revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s

revert style: clean up code with prettier and eslint
This commit is contained in:
remco committed 2026-07-12 21:02:03 +02:00
1 parent 27de078f54
commit e85e4d74ea
378 files changed
+20710 -22428

No files matched your search

+18 -15
View File
@@ -1,25 +1,28 @@
import { promises as fs } from "node:fs";
import path from "node:path";
import { withAdmin } from "@/lib/api-handler";
import { apiError, apiOk } from "@/lib/api-response";
import { PERMS } from "@/lib/permissions";
import { promises as fs } from 'node:fs'
import path from 'node:path'
import { withAdmin } from '@/lib/api-handler'
import { apiError, apiOk } from '@/lib/api-response'
import { PERMS } from '@/lib/permissions'
const EXTERNAL_TEXTS_PATH = path.join(process.cwd(), "public/nitro-assets/gamedata/ExternalTexts.json");
const EXTERNAL_TEXTS_PATH = path.join(
process.cwd(),
'public/nitro-assets/gamedata/ExternalTexts.json',
)
/** GET - Read badge name/desc from ExternalTexts.json */
export const GET = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request) => {
const code = request.nextUrl.searchParams.get("code")?.toUpperCase();
if (!code) return apiError("Missing code", 400);
const code = request.nextUrl.searchParams.get('code')?.toUpperCase()
if (!code) return apiError('Missing code', 400)
try {
const raw = await fs.readFile(EXTERNAL_TEXTS_PATH, "utf-8");
const texts: Record<string, string> = JSON.parse(raw);
const raw = await fs.readFile(EXTERNAL_TEXTS_PATH, 'utf-8')
const texts: Record<string, string> = JSON.parse(raw)
const name = texts[`badge_name_${code}`] ?? texts[`${code}_badge_name`] ?? "";
const desc = texts[`badge_desc_${code}`] ?? texts[`${code}_badge_desc`] ?? "";
const name = texts[`badge_name_${code}`] ?? texts[`${code}_badge_name`] ?? ''
const desc = texts[`badge_desc_${code}`] ?? texts[`${code}_badge_desc`] ?? ''
return apiOk({ name, desc });
return apiOk({ name, desc })
} catch {
return apiError("Failed to read ExternalTexts.json", 500);
return apiError('Failed to read ExternalTexts.json', 500)
}
});
})
+40 -37
View File
@@ -1,29 +1,32 @@
import { promises as fs } from "node:fs";
import path from "node:path";
import { withAdmin } from "@/lib/api-handler";
import { apiError, apiOk } from "@/lib/api-response";
import { PERMS } from "@/lib/permissions";
import { logAudit } from "@/lib/services/audit";
import { searchBadges } from "@/lib/services/habboassets";
import { promises as fs } from 'node:fs'
import path from 'node:path'
import { withAdmin } from '@/lib/api-handler'
import { apiError, apiOk } from '@/lib/api-response'
import { PERMS } from '@/lib/permissions'
import { logAudit } from '@/lib/services/audit'
import { searchBadges } from '@/lib/services/habboassets'
const EXTERNAL_TEXTS_PATH = path.join(process.cwd(), "public/nitro-assets/gamedata/ExternalTexts.json");
const EXTERNAL_TEXTS_PATH = path.join(
process.cwd(),
'public/nitro-assets/gamedata/ExternalTexts.json',
)
// ── Search badges via official Habbo external texts ────────────────
export const GET = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request) => {
const search = request.nextUrl.searchParams.get("search") || "";
const offset = parseInt(request.nextUrl.searchParams.get("offset") || "0", 10);
const allHotels = request.nextUrl.searchParams.get("allHotels") === "1";
const search = request.nextUrl.searchParams.get('search') || ''
const offset = parseInt(request.nextUrl.searchParams.get('offset') || '0', 10)
const allHotels = request.nextUrl.searchParams.get('allHotels') === '1'
const badges = await searchBadges(search, 100, offset, allHotels ? null : undefined);
const badges = await searchBadges(search, 100, offset, allHotels ? null : undefined)
// Check which badges already exist in ExternalTexts.json
const existingCodes = new Set<string>();
const existingCodes = new Set<string>()
try {
const raw = await fs.readFile(EXTERNAL_TEXTS_PATH, "utf-8");
const texts = JSON.parse(raw);
const raw = await fs.readFile(EXTERNAL_TEXTS_PATH, 'utf-8')
const texts = JSON.parse(raw)
for (const badge of badges) {
if (texts[`badge_name_${badge.code}`] !== undefined) {
existingCodes.add(badge.code);
existingCodes.add(badge.code)
}
}
} catch {
@@ -33,44 +36,44 @@ export const GET = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request
const enriched = badges.map((badge) => ({
...badge,
alreadyImported: existingCodes.has(badge.code),
}));
}))
return apiOk({ badges: enriched });
});
return apiOk({ badges: enriched })
})
// ── Import a single badge ───────────────────────────────────────────
export const POST = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request, ctx) => {
const body = await request.json();
const { code, name, description } = body;
const body = await request.json()
const { code, name, description } = body
if (!code || !name) return apiError("Missing code or name", 400);
if (!code || !name) return apiError('Missing code or name', 400)
try {
const raw = await fs.readFile(EXTERNAL_TEXTS_PATH, "utf-8");
const texts = JSON.parse(raw);
const raw = await fs.readFile(EXTERNAL_TEXTS_PATH, 'utf-8')
const texts = JSON.parse(raw)
const nameKey = `badge_name_${code}`;
const descKey = `badge_desc_${code}`;
const nameKey = `badge_name_${code}`
const descKey = `badge_desc_${code}`
if (texts[nameKey] !== undefined) {
return apiError("Badge already exists in ExternalTexts.json", 409);
return apiError('Badge already exists in ExternalTexts.json', 409)
}
texts[nameKey] = name;
texts[descKey] = description || "";
texts[nameKey] = name
texts[descKey] = description || ''
await fs.writeFile(EXTERNAL_TEXTS_PATH, JSON.stringify(texts, null, 4), "utf-8");
await fs.writeFile(EXTERNAL_TEXTS_PATH, JSON.stringify(texts, null, 4), 'utf-8')
} catch (err) {
console.warn("[import-badges] Failed to update ExternalTexts.json:", (err as Error).message);
return apiError("Failed to update ExternalTexts.json", 500);
console.warn('[import-badges] Failed to update ExternalTexts.json:', (err as Error).message)
return apiError('Failed to update ExternalTexts.json', 500)
}
logAudit({
userId: ctx.session.user.id,
action: "badge_import",
target: "ExternalTexts",
action: 'badge_import',
target: 'ExternalTexts',
after: { code, name, description },
});
})
return apiOk();
});
return apiOk()
})