fix: SQL maker creates wrong categories and badge import fails when ExternalTexts.json missing
- writeSqlMigration now classifies furni via classifyFurni and generates correct category sub-pages (imp_<catKey>) instead of hardcoded imp_other - writeSqlMigration generates idempotent INSERT...SELECT WHERE NOT EXISTS for parent and category catalog_pages, with correct numeric page_id - writeBadgeToExternalTexts creates ExternalTexts.json (and parent dirs) when missing instead of failing with ENOENT
This commit is contained in:
1 parent
1851653afb
commit
4d4cbd2211
3 files changed
+60
-15
No files matched your search
@@ -17,24 +17,42 @@ export async function writeBadgeToExternalTexts(
|
||||
name: string,
|
||||
description: string,
|
||||
): Promise<ImportBadgeResult> {
|
||||
const nameKey = `badge_name_${code}`;
|
||||
const descKey = `badge_desc_${code}`;
|
||||
|
||||
let texts: Record<string, string>;
|
||||
try {
|
||||
const raw = await fs.readFile(EXTERNAL_TEXTS_PATH, "utf-8");
|
||||
const texts = JSON.parse(raw) as Record<string, string>;
|
||||
|
||||
const nameKey = `badge_name_${code}`;
|
||||
const descKey = `badge_desc_${code}`;
|
||||
|
||||
if (texts[nameKey] !== undefined) {
|
||||
texts = JSON.parse(raw) as Record<string, string>;
|
||||
} catch (err) {
|
||||
// File not present yet (fresh deployment) — start with an empty object.
|
||||
if ((err as NodeJS.ErrnoException).code !== "ENOENT") {
|
||||
console.warn(
|
||||
"[import-badges] Failed to update ExternalTexts.json:",
|
||||
(err as Error).message,
|
||||
);
|
||||
return {
|
||||
ok: false,
|
||||
error: "Badge already exists in ExternalTexts.json",
|
||||
status: 409,
|
||||
error: "Failed to update ExternalTexts.json",
|
||||
status: 500,
|
||||
};
|
||||
}
|
||||
texts = {};
|
||||
}
|
||||
|
||||
texts[nameKey] = name;
|
||||
texts[descKey] = description || "";
|
||||
if (texts[nameKey] !== undefined) {
|
||||
return {
|
||||
ok: false,
|
||||
error: "Badge already exists in ExternalTexts.json",
|
||||
status: 409,
|
||||
};
|
||||
}
|
||||
|
||||
texts[nameKey] = name;
|
||||
texts[descKey] = description || "";
|
||||
|
||||
try {
|
||||
await fs.mkdir(path.dirname(EXTERNAL_TEXTS_PATH), { recursive: true });
|
||||
await fs.writeFile(
|
||||
EXTERNAL_TEXTS_PATH,
|
||||
JSON.stringify(texts, null, 4),
|
||||
|
||||
Reference in new issue
Block a user