feat :idk
This commit is contained in:
+40
-3
@@ -15,6 +15,8 @@ import {
|
||||
avatarIconName,
|
||||
characterDetailSchema,
|
||||
constellationSnapshot,
|
||||
nameCardImageName,
|
||||
splashImageName,
|
||||
talentSnapshot,
|
||||
} from "@/lib/catalog/lunaris";
|
||||
import type { CatalogConstellation, CatalogTalent } from "@/lib/catalog/lunaris";
|
||||
@@ -56,7 +58,11 @@ interface SyncedCharacter {
|
||||
weaponType: string | null;
|
||||
imageKey: string;
|
||||
elementIconKey: string | null;
|
||||
coopImageKey: string | null;
|
||||
nameCardImageKey: string | null;
|
||||
sourceImage: string | null;
|
||||
coopSourceImage: string | null;
|
||||
nameCardSourceImage: string | null;
|
||||
localImage: string | null;
|
||||
constellations: CatalogConstellation[];
|
||||
talents: CatalogTalent[];
|
||||
@@ -154,12 +160,18 @@ export async function processCatalogSyncJob(jobId: string): Promise<void> {
|
||||
const detailRaw = await getOptionalJson(`${API_ROOT}/${version}/en/char/${encodeURIComponent(key)}.json`);
|
||||
const detail = detailRaw ? characterDetailSchema.parse(detailRaw) : null;
|
||||
const avatarIcon = webpName(avatarIconName(value.CardImg));
|
||||
const splashImage = splashImageName(value.CardImg);
|
||||
const nameCardImage = nameCardImageName(value.CardImg);
|
||||
const element = detail?.info?.element ?? value.element ?? null;
|
||||
return {
|
||||
version, key, name: value.enName, element, rarity: rarity(value.qualityType), weaponType: detail?.info?.weapon ?? value.weaponType ?? null,
|
||||
imageKey: `catalog/${version}/characters/${avatarIcon}`,
|
||||
elementIconKey: element ? `catalog/${version}/elements/${element.toLowerCase()}.png` : null,
|
||||
coopImageKey: `catalog/${version}/characters/splash/${splashImage}`,
|
||||
nameCardImageKey: `catalog/${version}/characters/namecard/${nameCardImage}`,
|
||||
sourceImage: `${API_ROOT}/assets/avataricon/${encodeURIComponent(avatarIcon)}`,
|
||||
coopSourceImage: `${API_ROOT}/assets/gachaimg/${encodeURIComponent(splashImage)}`,
|
||||
nameCardSourceImage: `${API_ROOT}/assets/namecardpic/${encodeURIComponent(nameCardImage)}`,
|
||||
localImage: null,
|
||||
constellations: detail ? constellationSnapshot(detail, (icon) => `catalog/${version}/constellations/${webpName(icon)}`) : [],
|
||||
talents: detail ? talentSnapshot(detail, (icon) => `catalog/${version}/talents/${webpName(icon)}`) : [],
|
||||
@@ -177,7 +189,11 @@ export async function processCatalogSyncJob(jobId: string): Promise<void> {
|
||||
weaponType: "WEAPON_SWORD_ONE_HAND",
|
||||
imageKey: `catalog/${version}/characters/${traveler.asset}`,
|
||||
elementIconKey: `catalog/${version}/elements/${traveler.element.toLowerCase()}.png`,
|
||||
coopImageKey: null,
|
||||
nameCardImageKey: null,
|
||||
sourceImage: null,
|
||||
coopSourceImage: null,
|
||||
nameCardSourceImage: null,
|
||||
localImage: traveler.asset,
|
||||
constellations: constellationSnapshot(detail, (icon) => `catalog/${version}/constellations/${webpName(icon)}`),
|
||||
talents: talentSnapshot(detail, (icon) => `catalog/${version}/talents/${webpName(icon)}`),
|
||||
@@ -200,6 +216,20 @@ export async function processCatalogSyncJob(jobId: string): Promise<void> {
|
||||
body: await readFile(join(process.cwd(), "lib/catalog/assets", character.localImage)),
|
||||
target: character.imageKey,
|
||||
} : { source: character.sourceImage!, target: character.imageKey });
|
||||
if (character.coopImageKey && character.coopSourceImage) {
|
||||
uniqueAssets.set(character.coopImageKey, {
|
||||
source: character.coopSourceImage,
|
||||
target: character.coopImageKey,
|
||||
type: "image/png",
|
||||
});
|
||||
}
|
||||
if (character.nameCardImageKey && character.nameCardSourceImage) {
|
||||
uniqueAssets.set(character.nameCardImageKey, {
|
||||
source: character.nameCardSourceImage,
|
||||
target: character.nameCardImageKey,
|
||||
type: "image/png",
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const item of [...weapons, ...artifacts]) uniqueAssets.set(item.imageKey, { source: item.sourceImage, target: item.imageKey });
|
||||
for (const character of characters) {
|
||||
@@ -225,13 +255,20 @@ export async function processCatalogSyncJob(jobId: string): Promise<void> {
|
||||
}
|
||||
const missingAssets = await uploadAssets(jobId, [...uniqueAssets.values()]);
|
||||
characters = characters.filter((item) => !missingAssets.has(item.imageKey));
|
||||
characters = characters.map((item) => ({ ...item, elementIconKey: item.elementIconKey && !missingAssets.has(item.elementIconKey) ? item.elementIconKey : null, constellations: item.constellations.map((constellation) => ({ ...constellation, iconKey: constellation.iconKey && !missingAssets.has(constellation.iconKey) ? constellation.iconKey : null })), talents: item.talents.map((talent) => ({ ...talent, iconKey: talent.iconKey && !missingAssets.has(talent.iconKey) ? talent.iconKey : null })) }));
|
||||
characters = characters.map((item) => ({
|
||||
...item,
|
||||
elementIconKey: item.elementIconKey && !missingAssets.has(item.elementIconKey) ? item.elementIconKey : null,
|
||||
coopImageKey: item.coopImageKey && !missingAssets.has(item.coopImageKey) ? item.coopImageKey : null,
|
||||
nameCardImageKey: item.nameCardImageKey && !missingAssets.has(item.nameCardImageKey) ? item.nameCardImageKey : null,
|
||||
constellations: item.constellations.map((constellation) => ({ ...constellation, iconKey: constellation.iconKey && !missingAssets.has(constellation.iconKey) ? constellation.iconKey : null })),
|
||||
talents: item.talents.map((talent) => ({ ...talent, iconKey: talent.iconKey && !missingAssets.has(talent.iconKey) ? talent.iconKey : null })),
|
||||
}));
|
||||
weapons = weapons.filter((item) => !missingAssets.has(item.imageKey));
|
||||
artifacts = artifacts.filter((item) => !missingAssets.has(item.imageKey));
|
||||
|
||||
const storage = await getMediaStorage();
|
||||
await Promise.all([
|
||||
storage.write(`catalog/${version}/characters.json`, JSON.stringify(characters.map((item) => ({ version: item.version, key: item.key, name: item.name, element: item.element, rarity: item.rarity, weaponType: item.weaponType, imageKey: item.imageKey, elementIconKey: item.elementIconKey, constellations: item.constellations, talents: item.talents }))), { type: "application/json", acl: "public-read" }),
|
||||
storage.write(`catalog/${version}/characters.json`, JSON.stringify(characters.map((item) => ({ version: item.version, key: item.key, name: item.name, element: item.element, rarity: item.rarity, weaponType: item.weaponType, imageKey: item.imageKey, elementIconKey: item.elementIconKey, coopImageKey: item.coopImageKey, nameCardImageKey: item.nameCardImageKey, constellations: item.constellations, talents: item.talents }))), { type: "application/json", acl: "public-read" }),
|
||||
storage.write(`catalog/${version}/weapons.json`, JSON.stringify(weapons.map((item) => ({ version: item.version, key: item.key, name: item.name, rarity: item.rarity, weaponType: item.weaponType, imageKey: item.imageKey }))), { type: "application/json", acl: "public-read" }),
|
||||
storage.write(`catalog/${version}/artifacts.json`, JSON.stringify(artifacts.map((item) => ({ version: item.version, key: item.key, name: item.name, rarity: item.rarity, imageKey: item.imageKey }))), { type: "application/json", acl: "public-read" }),
|
||||
]);
|
||||
@@ -241,7 +278,7 @@ export async function processCatalogSyncJob(jobId: string): Promise<void> {
|
||||
await tx.delete(catalogCharacters).where(eq(catalogCharacters.version, version));
|
||||
await tx.delete(catalogWeapons).where(eq(catalogWeapons.version, version));
|
||||
await tx.delete(catalogArtifacts).where(eq(catalogArtifacts.version, version));
|
||||
if (characters.length) await tx.insert(catalogCharacters).values(characters.map((item) => ({ version: item.version, key: item.key, name: item.name, element: item.element, rarity: item.rarity, weaponType: item.weaponType, imageKey: item.imageKey, elementIconKey: item.elementIconKey, constellations: item.constellations, talents: item.talents })));
|
||||
if (characters.length) await tx.insert(catalogCharacters).values(characters.map((item) => ({ version: item.version, key: item.key, name: item.name, element: item.element, rarity: item.rarity, weaponType: item.weaponType, imageKey: item.imageKey, elementIconKey: item.elementIconKey, coopImageKey: item.coopImageKey, nameCardImageKey: item.nameCardImageKey, constellations: item.constellations, talents: item.talents })));
|
||||
if (weapons.length) await tx.insert(catalogWeapons).values(weapons.map((item) => ({ version: item.version, key: item.key, name: item.name, rarity: item.rarity, weaponType: item.weaponType, imageKey: item.imageKey })));
|
||||
if (artifacts.length) await tx.insert(catalogArtifacts).values(artifacts.map((item) => ({ version: item.version, key: item.key, name: item.name, rarity: item.rarity, imageKey: item.imageKey })));
|
||||
await tx.update(catalogVersions).set({ active: false });
|
||||
|
||||
Reference in New Issue
Block a user