From 240ee81712f28e8922d72b9d097970279be806d1 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Thu, 3 Dec 2026 03:02:14 +0800 Subject: [PATCH] feat(launcher): use dl.wto-project.net as primary release source with GitHub fallback Replace the single GitHub repository field in release-channels.jsonc with primary_source (https://dl.wto-project.net) and ordered fallback_sources (GitHub), and update withReleaseSources to walk the deduplicated primary, player mirror, and fallback list while keeping preferred-source downloads and Ed25519 signature verification intact. Verified with root and launcher typecheck and launcher production build. --- .../main/services/patch-pack/release-feed.ts | 41 +++++++++++++------ .../src/patch-pack/patch-pack-tuning.ts | 31 ++++++++++---- .../patcher/tuning/release-channels.jsonc | 13 ++++-- 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/apps/launcher/src/main/services/patch-pack/release-feed.ts b/apps/launcher/src/main/services/patch-pack/release-feed.ts index 775da8a..b5f1ff0 100644 --- a/apps/launcher/src/main/services/patch-pack/release-feed.ts +++ b/apps/launcher/src/main/services/patch-pack/release-feed.ts @@ -1,6 +1,6 @@ /** * The launcher and adaptation pack channels share an anonymous, GitHub-compatible release list. - * The project repository is tried first, with an optional player-configured fallback. + * The primary release source is tried first, followed by any player-configured mirror and default fallbacks. */ import { net } from 'electron'; import { @@ -98,18 +98,35 @@ export function sameReleaseSource(a: ReleaseSource, b: ReleaseSource): boolean { export async function withReleaseSources( read: (source: ReleaseSource) => Promise, preferred?: ReleaseSource, ): Promise { - const primary = releaseSource(new URL(`https://github.com/${patchPackTuning().repository}`)); - const repository = releaseRepositoryUrl((await getSettings()).updateMirrorUrl); - const mirror = repository ? releaseSource(repository) : null; - if (!mirror || sameReleaseSource(primary, mirror)) return read(primary); - const [first, second] = preferred && sameReleaseSource(preferred, mirror) ? [mirror, primary] : [primary, mirror]; - try { - return await read(first); - } catch (error) { - if (!(error instanceof FeedUnreachableError || error instanceof ReleasePageLimitError)) throw error; - console.info(`[release-feed] ${first.feed.hostname} was unavailable, trying ${second.feed.hostname}.`); - return read(second); + const tuning = patchPackTuning(); + const candidates: ReleaseSource[] = []; + const add = (url: URL | null): void => { + if (!url) return; + const source = releaseSource(url); + if (!candidates.some((existing) => sameReleaseSource(existing, source))) candidates.push(source); + }; + add(releaseRepositoryUrl(tuning.primarySource)); + add(releaseRepositoryUrl((await getSettings()).updateMirrorUrl)); + for (const fallback of tuning.fallbackSources) add(releaseRepositoryUrl(fallback)); + if (candidates.length === 0) throw new FeedUnreachableError('No valid release sources are configured.'); + + const ordered = preferred + ? [preferred, ...candidates.filter((source) => !sameReleaseSource(source, preferred))] + : candidates; + + let lastError: unknown; + for (let index = 0; index < ordered.length; index += 1) { + const current = ordered[index]!; + try { + return await read(current); + } catch (error) { + if (!(error instanceof FeedUnreachableError || error instanceof ReleasePageLimitError)) throw error; + lastError = error; + const next = ordered[index + 1]; + if (next) console.info(`[release-feed] ${current.feed.hostname} was unavailable, trying ${next.feed.hostname}.`); + } } + throw lastError; } function listingFor(source: ReleaseSource): Promise { diff --git a/packages/patcher/src/patch-pack/patch-pack-tuning.ts b/packages/patcher/src/patch-pack/patch-pack-tuning.ts index 528baf6..0c4ec3d 100644 --- a/packages/patcher/src/patch-pack/patch-pack-tuning.ts +++ b/packages/patcher/src/patch-pack/patch-pack-tuning.ts @@ -4,8 +4,10 @@ import { parseJsonc } from '@wto/jsonc'; import { PatchPackError } from './patch-pack-error.ts'; export interface PatchPackTuning { - /** `owner/repo` on GitHub. */ - readonly repository: string; + /** Default primary HTTPS release source URL. */ + readonly primarySource: string; + /** Default ordered fallback HTTPS release source URLs. */ + readonly fallbackSources: readonly string[]; readonly releasePageSize: number; readonly maxReleasePages: number; readonly maxPackBytes: number; @@ -22,14 +24,15 @@ export function patchPackTuning(): PatchPackTuning { const value = parseJsonc(readFileSync(TUNING_FILE, 'utf8')); if (typeof value !== 'object' || value === null || Array.isArray(value)) throw tuningError('the file is not an object'); const fields = value as Record; - const repository = fields['repository']; - if (typeof repository !== 'string' || !/^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(repository)) { - throw tuningError('"repository" must be "owner/repo"'); - } + const primarySource = releaseSourceUrl(fields['primary_source'], '"primary_source"'); + const rawFallbacks = fields['fallback_sources']; + if (!Array.isArray(rawFallbacks)) throw tuningError('"fallback_sources" must be an array of HTTPS URLs'); + const fallbackSources = rawFallbacks.map((entry, index) => releaseSourceUrl(entry, `"fallback_sources[${index}]"`)); const releasePageSize = positiveInteger(fields, 'release_page_size'); if (releasePageSize > 100) throw tuningError('"release_page_size" must be at most 100'); cached = { - repository, + primarySource, + fallbackSources, releasePageSize, maxReleasePages: positiveInteger(fields, 'max_release_pages'), maxPackBytes: positiveInteger(fields, 'max_pack_bytes'), @@ -39,6 +42,20 @@ export function patchPackTuning(): PatchPackTuning { return cached; } +function releaseSourceUrl(value: unknown, label: string): string { + if (typeof value !== 'string') throw tuningError(`${label} must be an HTTPS URL`); + let url: URL; + try { + url = new URL(value); + } catch { + throw tuningError(`${label} must be an HTTPS URL`); + } + if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) { + throw tuningError(`${label} must be a clean HTTPS URL without credentials, query, or hash`); + } + return value; +} + function positiveInteger(fields: Record, key: string): number { const value = fields[key]; if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) throw tuningError(`"${key}" must be a positive integer`); diff --git a/packages/patcher/tuning/release-channels.jsonc b/packages/patcher/tuning/release-channels.jsonc index fdb6444..69ae20a 100644 --- a/packages/patcher/tuning/release-channels.jsonc +++ b/packages/patcher/tuning/release-channels.jsonc @@ -1,7 +1,12 @@ -// GitHub release checks for the launcher and adaptation packs, including the pack size limits. +// Release update channels for the launcher and adaptation packs, including pack size limits. { - // Both channels share this repository. Launcher tags use `v` and pack tags use `patches-`. - "repository": "N0VAN0M4LY/WT-Offline", + // Default primary release source. Both channels share this endpoint: + // launcher tags use `v` and pack tags use `patches-`. + "primary_source": "https://dl.wto-project.net", + // Default ordered fallback sources tried when the primary source is unreachable. + "fallback_sources": [ + "https://github.com/N0VAN0M4LY/WT-Offline" + ], // Entries per request (GitHub allows up to 100) and pages per shared check. "release_page_size": 30, "max_release_pages": 5, @@ -9,6 +14,6 @@ // The whole patch set is about 0.2 MB today. "max_pack_bytes": 16777216, "max_unpacked_bytes": 67108864, - // A request to GitHub that takes longer is given up. + // A request to a release source that takes longer is given up. "request_timeout_ms": 20000 }