feat: RCON API transport, full furnidata translation with LibreTranslate fallback, remove organize feature, bump per-page limit to 500
- Add EMULATOR_MODE=api option with HTTP transport mirroring RCON payload - buildLocalizedFurniDataFiles now falls back to LibreTranslate for customs (incl. pl/ru/ar/ja) - Remove Organiseer import button from studio and Reorganize Catalog from import page - Delete organize API route and PUT handler; remove organizeCatalogAll from catalog-repair.ts - Increase imported-furni list perPage from 50 to 500
This commit is contained in:
1 parent
5668493485
commit
85b5792d40
8 files changed
+144
-766
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1,42 +0,0 @@
|
|||||||
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 { organizeCatalogAll } from "@/lib/services/catalog-repair";
|
|
||||||
import { rcon } from "@/lib/services/rcon";
|
|
||||||
|
|
||||||
// ── Fully automatic catalog organization of the whole database ──────
|
|
||||||
export const POST = withAdmin(
|
|
||||||
{ permission: PERMS.ASSETS_IMPORT },
|
|
||||||
async (_request, ctx) => {
|
|
||||||
try {
|
|
||||||
const result = await organizeCatalogAll();
|
|
||||||
|
|
||||||
// Refresh game server caches so the reorganized catalog shows up.
|
|
||||||
try {
|
|
||||||
await rcon.updateCatalog();
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(
|
|
||||||
"[organize-furni] RCON catalog refresh failed:",
|
|
||||||
(err as Error).message,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
logAudit({
|
|
||||||
userId: ctx.session.user.id,
|
|
||||||
action: "furni_organize",
|
|
||||||
target: "CatalogItems",
|
|
||||||
targetId: 0,
|
|
||||||
after: {
|
|
||||||
pagesCreated: result.pagesCreated,
|
|
||||||
catalogAdded: result.catalogAdded,
|
|
||||||
catalogRehomed: result.catalogRehomed,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return apiOk({ ...result });
|
|
||||||
} catch (err) {
|
|
||||||
return apiError((err as Error).message, 500);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -514,37 +514,6 @@ export function StudioClient({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [organizing, setOrganizing] = useState(false);
|
|
||||||
|
|
||||||
async function organizeAll() {
|
|
||||||
if (organizing) return;
|
|
||||||
setOrganizing(true);
|
|
||||||
try {
|
|
||||||
const res = await adminFetch("/api/admin/import/furni/organize", {
|
|
||||||
method: "POST",
|
|
||||||
});
|
|
||||||
const data = await res.json();
|
|
||||||
if (res.ok) {
|
|
||||||
const parts = [
|
|
||||||
`Catalogus georganiseerd`,
|
|
||||||
data.pagesCreated > 0
|
|
||||||
? `${data.pagesCreated} pagina's aangemaakt`
|
|
||||||
: null,
|
|
||||||
data.catalogAdded > 0 ? `${data.catalogAdded} nieuw` : null,
|
|
||||||
data.catalogRehomed > 0 ? `${data.catalogRehomed} bijgewerkt` : null,
|
|
||||||
].filter(Boolean);
|
|
||||||
toast.success(parts.join(" · "));
|
|
||||||
fetchStats();
|
|
||||||
} else {
|
|
||||||
toast.error(data.error || "Organiseren mislukt");
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
toast.error("Netwerkfout");
|
|
||||||
} finally {
|
|
||||||
setOrganizing(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteItem() {
|
async function deleteItem() {
|
||||||
if (!deleting) return;
|
if (!deleting) return;
|
||||||
try {
|
try {
|
||||||
@@ -875,22 +844,6 @@ export function StudioClient({
|
|||||||
|
|
||||||
<div className="flex-1" />
|
<div className="flex-1" />
|
||||||
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
className="gap-1.5"
|
|
||||||
disabled={organizing || !!batchProgress}
|
|
||||||
onClick={organizeAll}
|
|
||||||
title="Alle meubels uit de Import-sectie automatisch ordenen in catalogus-pagina's (pagina's worden aangemaakt indien nodig)"
|
|
||||||
>
|
|
||||||
{organizing ? (
|
|
||||||
<Loader2 size={14} className="animate-spin" />
|
|
||||||
) : (
|
|
||||||
<WandSparkles size={14} />
|
|
||||||
)}
|
|
||||||
Organiseer import
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
{selectedNonImported > 0 && (
|
{selectedNonImported > 0 && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
+11
@@ -45,6 +45,17 @@ const schema = z
|
|||||||
RCON_PORT: z.coerce.number().int().positive().default(3001),
|
RCON_PORT: z.coerce.number().int().positive().default(3001),
|
||||||
RCON_TIMEOUT_MS: z.coerce.number().int().positive().default(10_000),
|
RCON_TIMEOUT_MS: z.coerce.number().int().positive().default(10_000),
|
||||||
RCON_MAX_RETRIES: z.coerce.number().int().positive().default(3),
|
RCON_MAX_RETRIES: z.coerce.number().int().positive().default(3),
|
||||||
|
// Emulator transport selection. "rcon" uses the raw-JSON TCP protocol
|
||||||
|
// above; "api" uses an HTTP endpoint that accepts the same
|
||||||
|
// `{"key":...,"data":...}` payload (for emulators without RCON).
|
||||||
|
EMULATOR_MODE: z.enum(["rcon", "api"]).default("rcon"),
|
||||||
|
// HTTP endpoint used when EMULATOR_MODE=api. Required in that mode.
|
||||||
|
EMULATOR_API_URL: z.string().url().optional(),
|
||||||
|
// Optional bearer/key auth for the API transport. When set, it is sent
|
||||||
|
// as `${EMULATOR_API_KEY_HEADER}: ${EMULATOR_API_KEY}` (default header
|
||||||
|
// "Authorization").
|
||||||
|
EMULATOR_API_KEY: z.string().optional(),
|
||||||
|
EMULATOR_API_KEY_HEADER: z.string().default("Authorization"),
|
||||||
// NextAuth v5 reads AUTH_SECRET itself; declared here for documentation/typing.
|
// NextAuth v5 reads AUTH_SECRET itself; declared here for documentation/typing.
|
||||||
AUTH_SECRET: z.string().min(1).optional(),
|
AUTH_SECRET: z.string().min(1).optional(),
|
||||||
// Laravel APP_KEY (base64:...) — needed to read existing 2FA secrets.
|
// Laravel APP_KEY (base64:...) — needed to read existing 2FA secrets.
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -324,22 +324,50 @@ export async function buildLocalizedFurniDataFiles(): Promise<
|
|||||||
for (const section of ["roomitemtypes", "wallitemtypes"] as const) {
|
for (const section of ["roomitemtypes", "wallitemtypes"] as const) {
|
||||||
const arr = cloned[section]?.furnitype;
|
const arr = cloned[section]?.furnitype;
|
||||||
if (!Array.isArray(arr)) continue;
|
if (!Array.isArray(arr)) continue;
|
||||||
|
// A language mapped to hotel "com" only carries English names,
|
||||||
|
// so it must NOT be treated as a real translation — fall through
|
||||||
|
// to LibreTranslate for those (pl/ru/ar/ja).
|
||||||
|
const officialIsReal = lang === "en" || hotel !== "com";
|
||||||
for (const entry of arr) {
|
for (const entry of arr) {
|
||||||
const cn =
|
const cn =
|
||||||
typeof entry.classname === "string" ? entry.classname : "";
|
typeof entry.classname === "string" ? entry.classname : "";
|
||||||
if (!cn) continue;
|
if (!cn) continue;
|
||||||
const t = lookupTranslation(map, cn);
|
const t = lookupTranslation(map, cn);
|
||||||
if (!t) continue;
|
|
||||||
// Only override when the translation carries content — empty
|
|
||||||
// strings in official data would otherwise blank existing names.
|
|
||||||
let didTranslate = false;
|
let didTranslate = false;
|
||||||
if (t.name) {
|
// Prefer the official Habbo translation when it carries content;
|
||||||
|
// otherwise fall back to LibreTranslate (customs, or languages
|
||||||
|
// whose hotel only provides English) so every entry gets a
|
||||||
|
// localized name/description rather than staying English.
|
||||||
|
if (officialIsReal && t?.name) {
|
||||||
entry.name = t.name;
|
entry.name = t.name;
|
||||||
didTranslate = true;
|
didTranslate = true;
|
||||||
|
} else if (
|
||||||
|
lang !== "en" &&
|
||||||
|
typeof entry.name === "string" &&
|
||||||
|
entry.name.trim()
|
||||||
|
) {
|
||||||
|
const translated = await translateWithLibre(entry.name, lang);
|
||||||
|
if (translated && translated !== entry.name) {
|
||||||
|
entry.name = translated;
|
||||||
|
didTranslate = true;
|
||||||
}
|
}
|
||||||
if (t.description) {
|
}
|
||||||
|
if (officialIsReal && t?.description) {
|
||||||
entry.description = t.description;
|
entry.description = t.description;
|
||||||
didTranslate = true;
|
didTranslate = true;
|
||||||
|
} else if (
|
||||||
|
lang !== "en" &&
|
||||||
|
typeof entry.description === "string" &&
|
||||||
|
entry.description.trim()
|
||||||
|
) {
|
||||||
|
const translated = await translateWithLibre(
|
||||||
|
entry.description,
|
||||||
|
lang,
|
||||||
|
);
|
||||||
|
if (translated && translated !== entry.description) {
|
||||||
|
entry.description = translated;
|
||||||
|
didTranslate = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (didTranslate) {
|
if (didTranslate) {
|
||||||
if (section === "roomitemtypes") translatedRoom++;
|
if (section === "roomitemtypes") translatedRoom++;
|
||||||
@@ -361,6 +389,10 @@ export async function buildLocalizedFurniDataFiles(): Promise<
|
|||||||
await fs.rename(tmp, target);
|
await fs.rename(tmp, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Persist the LibreTranslate cache once per language so the next
|
||||||
|
// full build reuses translations instead of re-calling the API.
|
||||||
|
if (lang !== "en") await saveLibreCache();
|
||||||
|
|
||||||
results.push({
|
results.push({
|
||||||
lang,
|
lang,
|
||||||
hotel,
|
hotel,
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user