Remove obsolete rule formats, batch SQLite work, preserve artwork source URLs, and coordinate refresh workers with maintenance. Add regression coverage and document backup format changes.
125 lines
6.2 KiB
JavaScript
125 lines
6.2 KiB
JavaScript
(function () {
|
|
const basePath = () => {
|
|
const path = window.location.pathname || "";
|
|
const marker = "/web/";
|
|
const index = path.indexOf(marker);
|
|
return index > 0 ? path.slice(0, index).replace(/\/$/, "") : "";
|
|
};
|
|
|
|
function token() {
|
|
try {
|
|
return window.ApiClient && window.ApiClient.accessToken ? window.ApiClient.accessToken() : "";
|
|
} catch (_) {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function authHeaders(contentType) {
|
|
const qs = new URLSearchParams(location.search);
|
|
const t = token() || qs.get("token") || qs.get("api_key") || "";
|
|
const h = {};
|
|
if (contentType) h["Content-Type"] = contentType;
|
|
if (t) {
|
|
h.Authorization = `MediaBrowser Token="${t}"`;
|
|
h["X-Emby-Token"] = t;
|
|
h["X-MediaBrowser-Token"] = t;
|
|
}
|
|
return h;
|
|
}
|
|
|
|
function debugUrl(itemId, userId) {
|
|
const query = new URLSearchParams();
|
|
const t = token() || new URLSearchParams(location.search).get("token") || new URLSearchParams(location.search).get("api_key") || "";
|
|
if (t) query.set("token", t);
|
|
if (userId) query.set("userId", userId);
|
|
const suffix = query.toString();
|
|
return `${basePath()}/Multilang/DebugUi/${encodeURIComponent(String(itemId || "").trim())}${suffix ? `?${suffix}` : ""}`;
|
|
}
|
|
|
|
async function request(path, options) {
|
|
const response = await fetch(`${basePath()}${path}`, {
|
|
cache: "no-store",
|
|
headers: authHeaders("application/json"),
|
|
...options
|
|
});
|
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
const text = await response.text();
|
|
return text ? JSON.parse(text) : null;
|
|
}
|
|
|
|
function splitList(value) {
|
|
return String(value || "")
|
|
.split(",")
|
|
.map((v) => v.trim())
|
|
.filter(Boolean);
|
|
}
|
|
|
|
function setStatus(el, text, error) {
|
|
if (!el) return;
|
|
el.textContent = text || "";
|
|
el.style.color = error ? "#ff9b9b" : "";
|
|
}
|
|
|
|
function prop(obj, pascal, camel, fallback) {
|
|
if (!obj) return fallback;
|
|
if (obj[pascal] !== undefined) return obj[pascal];
|
|
if (obj[camel] !== undefined) return obj[camel];
|
|
return fallback;
|
|
}
|
|
|
|
function formatBytes(bytes) {
|
|
bytes = Number(bytes || 0);
|
|
if (bytes < 1024) return bytes + " B";
|
|
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KiB";
|
|
if (bytes < 1024 * 1024 * 1024) return (bytes / 1024 / 1024).toFixed(1) + " MiB";
|
|
return (bytes / 1024 / 1024 / 1024).toFixed(1) + " GiB";
|
|
}
|
|
|
|
function showModal(id) {
|
|
document.getElementById(id).hidden = false;
|
|
}
|
|
|
|
function hideModals(selector) {
|
|
[...document.querySelectorAll(selector || ".ml-modal")].forEach((modal) => { modal.hidden = true; });
|
|
}
|
|
|
|
function downloadBlob(blob, name) {
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = name;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
a.remove();
|
|
URL.revokeObjectURL(url);
|
|
}
|
|
|
|
function replaceChildren(parent, ...children) {
|
|
parent.textContent = "";
|
|
parent.append(...children);
|
|
}
|
|
|
|
const staticData = {
|
|
iso6391: ["aa","ab","ae","af","ak","am","an","ar","as","av","ay","az","ba","be","bg","bh","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de","dv","dz","ee","el","en","eo","es","et","eu","fa","ff","fi","fj","fo","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","io","is","it","iu","ja","jv","ka","kg","ki","kj","kk","kl","km","kn","ko","kr","ks","ku","kv","kw","ky","la","lb","lg","li","ln","lo","lt","lu","lv","mg","mh","mi","mk","ml","mn","mr","ms","mt","my","na","nb","nd","ne","ng","nl","nn","no","nr","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt","qu","rm","rn","ro","ru","rw","sa","sc","sd","se","sg","si","sk","sl","sm","sn","so","sq","sr","ss","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh","zu"],
|
|
iso3166: ["AF","AL","DZ","AS","AD","AO","AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY","BE","BZ","BJ","BM","BT","BO","BQ","BA","BW","BV","BR","IO","BN","BG","BF","BI","CV","KH","CM","CA","KY","CF","TD","CL","CN","CX","CC","CO","KM","CD","CG","CK","CR","CI","HR","CU","CW","CY","CZ","DK","DJ","DM","DO","EC","EG","SV","GQ","ER","EE","SZ","ET","FK","FO","FJ","FI","FR","GF","PF","TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GG","GN","GW","GY","HT","HM","VA","HN","HK","HU","IS","IN","ID","IR","IQ","IE","IM","IL","IT","JM","JP","JE","JO","KZ","KE","KI","KP","KR","KW","KG","LA","LV","LB","LS","LR","LY","LI","LT","LU","MO","MG","MW","MY","MV","ML","MT","MH","MQ","MR","MU","YT","MX","FM","MD","MC","MN","ME","MS","MA","MZ","MM","NA","NR","NP","NL","NC","NZ","NI","NE","NG","NU","NF","MK","MP","NO","OM","PK","PW","PS","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO","RU","RW","BL","SH","KN","LC","MF","PM","VC","WS","SM","ST","SA","SN","RS","SC","SL","SG","SX","SK","SI","SB","SO","ZA","GS","SS","ES","LK","SD","SR","SJ","SE","CH","SY","TW","TJ","TZ","TH","TL","TG","TK","TO","TT","TN","TR","TM","TC","TV","UG","UA","AE","GB","US","UM","UY","UZ","VU","VE","VN","VG","VI","WF","EH","YE","ZM","ZW"],
|
|
langRegionCombos: ["en-US","en-GB","en-AU","en-CA","en-NZ","en-IN","en-ZA","en-IE","es-ES","es-MX","es-AR","es-CO","es-CL","es-PE","es-US","fr-FR","fr-CA","fr-BE","fr-CH","pt-PT","pt-BR","de-DE","de-CH","de-AT","it-IT","it-CH","nl-NL","nl-BE","sv-SE","sv-FI","no-NO","nb-NO","nn-NO","da-DK","fi-FI","ru-RU","pl-PL","cs-CZ","sk-SK","hu-HU","el-GR","tr-TR","he-IL","ar-SA","ar-EG","ar-AE","ja-JP","ko-KR","zh-CN","zh-TW","zh-HK","th-TH","hi-IN","ta-IN","te-IN","ml-IN","mr-IN","bn-IN","pa-IN","gu-IN","ur-PK","id-ID","ms-MY","vi-VN","uk-UA","ro-RO","bg-BG","sr-RS","hr-HR","sl-SI","et-EE","lv-LV","lt-LT","is-IS","ga-IE","mt-MT","sq-AL","fa-IR","af-ZA","sw-KE","sw-TZ","zu-ZA","xh-ZA","st-ZA"]
|
|
};
|
|
|
|
window.Multilang = {
|
|
get: (path) => request(path),
|
|
post: (path, body) => request(path, { method: "POST", body: JSON.stringify(body) }),
|
|
basePath,
|
|
debugUrl,
|
|
authHeaders,
|
|
splitList,
|
|
setStatus,
|
|
prop,
|
|
formatBytes,
|
|
showModal,
|
|
hideModals,
|
|
downloadBlob,
|
|
replaceChildren,
|
|
staticData
|
|
};
|
|
})();
|