feat(catalog) : sync Lunaris updates from Discord
CI / Verify (push) Successful in 1m13s
CI / Build immutable images and deploy (push) Successful in 5m34s

This commit is contained in:
2026-09-03 17:51:02 +07:00 Unverified
parent 2018005758
commit 76395a0b42
17 changed files with 520 additions and 19 deletions
+37 -3
View File
@@ -21,15 +21,21 @@ import type {
CatalogTalent,
} from "@/lib/catalog/lunaris";
import { customTravelers, isUpstreamTraveler } from "@/lib/catalog/travelers";
import { withCatalogSyncLock } from "@/lib/catalog/sync-lock";
import {
compareLunarisVersions,
lunarisVersionSchema,
} from "@/lib/catalog/version";
import { getMediaStorage } from "@/lib/media/storage";
const VERSION_URL = "https://api.lunaris.moe/data/version.json";
const API_ROOT = "https://api.lunaris.moe/data";
const versionSchema = z.object({
version: z.string().regex(/^\d+(?:\.\d+)+$/u),
version: lunarisVersionSchema,
timestamp: z.number().int().optional(),
});
const currentVersionSchema = z.object({ version: lunarisVersionSchema });
const characterSchema = z.record(
z.string(),
z.object({
@@ -179,8 +185,7 @@ async function uploadAssets(
return missing;
}
export async function processCatalogSync(): Promise<void> {
const version = await getLatestLunarisVersion();
async function syncCatalogVersion(version: string): Promise<void> {
const [charactersRaw, weaponsRaw, artifactsRaw] = await Promise.all([
getJson(`${API_ROOT}/${version}/charlist.json`),
getJson(`${API_ROOT}/${version}/weaponlist.json`),
@@ -491,3 +496,32 @@ export async function processCatalogSync(): Promise<void> {
acl: "public-read",
});
}
export type CatalogSyncResult = "synced" | "unchanged";
export async function getCurrentCatalogVersion(): Promise<string | null> {
const storage = await getMediaStorage();
const current = storage.file("catalog/current.json");
if (!(await current.exists())) return null;
return currentVersionSchema.parse(await current.json()).version;
}
export async function processCatalogSync(
requestedVersion?: string,
): Promise<CatalogSyncResult> {
const version = lunarisVersionSchema.parse(
requestedVersion ?? (await getLatestLunarisVersion()),
);
return withCatalogSyncLock(async () => {
const currentVersion = await getCurrentCatalogVersion();
if (
currentVersion &&
compareLunarisVersions(version, currentVersion) <= 0
) {
return "unchanged";
}
await syncCatalogVersion(version);
return "synced";
});
}