Fix webOS 1.2 and lint

This commit is contained in:
Dmitry Lyzo 2020-09-27 17:48:29 +03:00
parent 6f78193660
commit 56d7179838

View file

@ -1,25 +1,33 @@
let data; let data;
const urlResolver = document.createElement('a');
// `fetch` with `file:` support // `fetch` with `file:` support
// Recent browsers seem to support `file` protocol under some conditions. // Recent browsers seem to support `file` protocol under some conditions.
// Based on https://github.com/github/fetch/pull/92#issuecomment-174730593 // Based on https://github.com/github/fetch/pull/92#issuecomment-174730593
// https://github.com/github/fetch/pull/92#issuecomment-512187452
async function fetchLocal(url, options) { async function fetchLocal(url, options) {
urlResolver.href = url;
const requestURL = urlResolver.href;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest; const xhr = new XMLHttpRequest;
xhr.onload = () => { xhr.onload = () => {
// `file` protocol has invalid OK status // `file` protocol has invalid OK status
let status = xhr.status; let status = xhr.status;
if (xhr.responseURL.startsWith('file:') && status === 0) { if (requestURL.startsWith('file:') && status === 0) {
status = 200; status = 200;
} }
/* eslint-disable-next-line compat/compat */
resolve(new Response(xhr.responseText, {status: status})); resolve(new Response(xhr.responseText, {status: status}));
} };
xhr.onerror = () => { xhr.onerror = () => {
reject(new TypeError('Local request failed')); reject(new TypeError('Local request failed'));
} };
xhr.open('GET', url); xhr.open('GET', url);