${text.title}
${escape(text.description)}
${escape(text.continue)}${escape(text.footnote)}
import { addonsJs, bootGuardJs, i18nJs, localeEn, localeZh, localeEnJs, localeZhJs, localeScripts, localeData, tasksJs, calendarJs, notificationsJs, i18nRenderersJs, systemNavigationJs, browserAppJs, dataActionsJs, terminalAppJs, dbAdminJs, indexHtml, manifest, serviceWorker, icon } from "./assets.js"; import { cloudApi } from "./cloud-state.js"; import { dbAdminApi } from "./db-admin.js"; const BING_ARCHIVE = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"; async function bingMetadata() { const response = await fetch(BING_ARCHIVE, { headers: { accept: "application/json" } }); if (!response.ok) throw new Error(`Bing metadata request failed: ${response.status}`); const image = (await response.json()).images?.[0]; if (!image?.url) throw new Error("Bing did not return today's image"); return { title: image.copyright || "Bing Daily Image", url: new URL(image.url, "https://www.bing.com").toString() }; } function headers(type, cache = "public, max-age=3600") { return { "content-type": type, "cache-control": cache }; } function userId(request) { return request.headers.get("oai-authenticated-user-id"); } async function holidayFeed(url) { const country = url.searchParams.get('country') || ''; const year = Number(url.searchParams.get('year')); if (!/^[A-Z]{2}$/.test(country) || !Number.isInteger(year) || year < 2024 || year > 2030) return Response.json({ error: 'Unsupported holiday country or year' }, { status: 400 }); try { const response = await fetch(`https://openworkdays.com/api/v1/${country.toLowerCase()}/${year}.json`); if (!response.ok) throw new Error(`Holiday source returned ${response.status}`); const data = await response.json(); if (data.code !== country || data.year !== year || !Array.isArray(data.holidays)) throw new Error('Unexpected holiday data'); const validDate = value => typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value) && value.startsWith(`${year}-`); const holidays = data.holidays.filter(item => validDate(item.date) && typeof item.name === 'string').map(item => ({ date: item.date, name: item.name.slice(0, 160), observed: item.observed === true, estimated: item.estimated === true })); const workingDays = (data.working_weekend_days || []).filter(validDate); return Response.json({ country, year, holidays, workingDays, source: 'OpenWorkdays' }, { headers: { 'cache-control': 'public, max-age=43200' } }); } catch { return Response.json({ error: 'Holiday source unavailable' }, { status: 502, headers: { 'cache-control': 'no-store' } }); } } async function holidayCountries() { try { const response = await fetch('https://openworkdays.com/api/v1/countries.json'); if (!response.ok) throw new Error(`Holiday source returned ${response.status}`); const data = await response.json(); const countries = (data.countries || []).filter(item => /^[A-Z]{2}$/.test(item.code) && typeof item.name === 'string').map(item => ({ code: item.code, name: item.name.slice(0, 100) })); if (!countries.length) throw new Error('No countries available'); return Response.json({ countries }, { headers: { 'cache-control': 'public, max-age=86400' } }); } catch { return Response.json({ error: 'Holiday country list unavailable' }, { status: 502, headers: { 'cache-control': 'no-store' } }); } } function loginPage(request) { const preferred = (request.headers.get("accept-language") || "en").split(",").map(part => part.split(";")[0].trim().toLowerCase()); const code = preferred.map(value => { if (value.startsWith("zh-hk")) return "zh-HK"; if (value.startsWith("zh-mo")) return "zh-MO"; if (value.startsWith("zh-tw") || value.startsWith("zh-hant")) return "zh-TW"; if (value.startsWith("zh")) return "zh-CN"; return ["ar", "fr", "ru", "es", "ja", "en"].find(item => value === item || value.startsWith(item + "-")); }).find(Boolean) || "en"; const language = code === "zh-CN" ? localeZh : code === "en" ? localeEn : localeData[code]; const text = language.login; const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", "\"": """, "'": "'" }[char])); return `
${escape(text.description)}
${escape(text.continue)}${escape(text.footnote)}