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.
This commit is contained in:
N0VAN0M4LY committed 2026-12-03 03:02:14 +08:00
1 parent 662e837ab2
commit 240ee81712
3 files changed
+62 -23

No files matched your search

@@ -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<T>(
read: (source: ReleaseSource) => Promise<T>, preferred?: ReleaseSource,
): Promise<T> {
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<ReleaseListing> {
@@ -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<string, unknown>;
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<string, unknown>, key: string): number {
const value = fields[key];
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) throw tuningError(`"${key}" must be a positive integer`);
@@ -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<version>` and pack tags use `patches-<version>`.
"repository": "N0VAN0M4LY/WT-Offline",
// Default primary release source. Both channels share this endpoint:
// launcher tags use `v<version>` and pack tags use `patches-<version>`.
"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
}