mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Fix 'file:' fetching (bundled apps)
This commit is contained in:
parent
13f0969976
commit
6f78193660
1 changed files with 33 additions and 2 deletions
|
@ -1,9 +1,40 @@
|
|||
let data;
|
||||
|
||||
// `fetch` with `file:` support
|
||||
// Recent browsers seem to support `file` protocol under some conditions.
|
||||
// Based on https://github.com/github/fetch/pull/92#issuecomment-174730593
|
||||
async function fetchLocal(url, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest;
|
||||
|
||||
xhr.onload = () => {
|
||||
// `file` protocol has invalid OK status
|
||||
let status = xhr.status;
|
||||
if (xhr.responseURL.startsWith('file:') && status === 0) {
|
||||
status = 200;
|
||||
}
|
||||
|
||||
resolve(new Response(xhr.responseText, {status: status}));
|
||||
}
|
||||
|
||||
xhr.onerror = () => {
|
||||
reject(new TypeError('Local request failed'));
|
||||
}
|
||||
|
||||
xhr.open('GET', url);
|
||||
|
||||
if (options && options.cache) {
|
||||
xhr.setRequestHeader('Cache-Control', options.cache);
|
||||
}
|
||||
|
||||
xhr.send(null);
|
||||
});
|
||||
}
|
||||
|
||||
async function getConfig() {
|
||||
if (data) return Promise.resolve(data);
|
||||
try {
|
||||
const response = await fetch('config.json', {
|
||||
const response = await fetchLocal('config.json', {
|
||||
cache: 'no-cache'
|
||||
});
|
||||
|
||||
|
@ -22,7 +53,7 @@ async function getConfig() {
|
|||
|
||||
async function getDefaultConfig() {
|
||||
try {
|
||||
const response = await fetch('config.template.json', {
|
||||
const response = await fetchLocal('config.template.json', {
|
||||
cache: 'no-cache'
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue