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:
1 parent
662e837ab2
commit
240ee81712
3 files changed
+62
-23
No files matched your search
@@ -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`);
|
||||
|
||||
Reference in new issue
Block a user