fix: normalize bilingual style names to strings so /portal dashboard renders
This commit is contained in:
1 parent
566e17d1f4
commit
309372e1fe
1 file changed
+21
-3
+21
-3
@@ -86,6 +86,24 @@ function queueWrite(task: () => Promise<void> | void): Promise<void> {
|
||||
/**
|
||||
* Load all records from disk safely with automatic backup recovery
|
||||
*/
|
||||
/**
|
||||
* Style names became bilingual objects ({ en, zh }); older/newer records may store
|
||||
* either a plain string or that object. Always expose a plain string to the portal UI.
|
||||
*/
|
||||
function toPlainStyleName(name: unknown): string {
|
||||
if (typeof name === "string") return name;
|
||||
if (name && typeof name === "object") {
|
||||
const n = name as { en?: string; zh?: string };
|
||||
if (n.en && n.zh) return `${n.en} · ${n.zh}`;
|
||||
return n.en || n.zh || "Unknown Disguise";
|
||||
}
|
||||
return "Unknown Disguise";
|
||||
}
|
||||
|
||||
function normalizeRecordStyleName(r: GenerationRecord): GenerationRecord {
|
||||
return { ...r, styleName: toPlainStyleName(r.styleName) };
|
||||
}
|
||||
|
||||
export function getAllRecords(): GenerationRecord[] {
|
||||
ensureDirectories();
|
||||
try {
|
||||
@@ -98,7 +116,7 @@ export function getAllRecords(): GenerationRecord[] {
|
||||
console.warn("[Storage] records.json is not an array, attempting backup recovery...");
|
||||
return recoverFromBackup();
|
||||
}
|
||||
return parsed;
|
||||
return parsed.map(normalizeRecordStyleName);
|
||||
} catch (err) {
|
||||
console.error("[Storage] JSON parse error in records.json, attempting backup recovery:", err);
|
||||
return recoverFromBackup();
|
||||
@@ -117,7 +135,7 @@ function recoverFromBackup(): GenerationRecord[] {
|
||||
console.warn("[Storage] Successfully recovered records from records.json.bak!");
|
||||
// Re-write valid records back to records.json
|
||||
fs.writeFileSync(RECORDS_FILE, backupRaw, "utf8");
|
||||
return parsed;
|
||||
return parsed.map(normalizeRecordStyleName);
|
||||
}
|
||||
}
|
||||
} catch (backupErr) {
|
||||
@@ -302,7 +320,7 @@ export async function logGenerationEvent(data: {
|
||||
timestamp: now.toISOString(),
|
||||
dateStr,
|
||||
styleId: data.styleId,
|
||||
styleName: data.styleName,
|
||||
styleName: toPlainStyleName(data.styleName),
|
||||
provider: data.provider,
|
||||
model: data.model,
|
||||
durationMs: data.durationMs,
|
||||
|
||||
Reference in new issue
Block a user