fix(catalog): stream single imports and preserve response errors
This commit is contained in:
1 parent
f0dcbee162
commit
33b6d1520e
5 files changed
+351
-142
No files matched your search
@@ -60,6 +60,7 @@ import {
|
||||
type AutoCatalogPreview,
|
||||
previewAutoCatalog,
|
||||
} from "@/lib/furni/auto-catalog";
|
||||
import { readImportResponse } from "@/lib/furni/import-response";
|
||||
import type { FurniImportSource } from "@/lib/habbo-gamedata-hotel";
|
||||
import { readSseStream } from "@/lib/sse-client";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -690,7 +691,10 @@ export function StudioClient({
|
||||
try {
|
||||
const res = await adminFetch("/api/admin/import/furni", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "text/event-stream",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
repairExisting: true,
|
||||
id: item.id,
|
||||
@@ -706,8 +710,8 @@ export function StudioClient({
|
||||
translate && translateLangs.length > 0 ? translateLangs : undefined,
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (res.ok) {
|
||||
const { status, data } = await readImportResponse(res);
|
||||
if (status >= 200 && status < 300) {
|
||||
setItems((prev) =>
|
||||
prev.map((i) =>
|
||||
i.classname === item.classname
|
||||
@@ -727,15 +731,26 @@ export function StudioClient({
|
||||
`verified: ${data.offerIdsFixed} offer_id, ${data.furniDataFixedIds} furnidata id`,
|
||||
);
|
||||
}
|
||||
if (data.furniDataMissing > 0) {
|
||||
if (
|
||||
typeof data.furniDataMissing === "number" &&
|
||||
data.furniDataMissing > 0
|
||||
) {
|
||||
parts.push(`${data.furniDataMissing} furnidata missing`);
|
||||
}
|
||||
toast.success(parts.join(" · "));
|
||||
} else {
|
||||
toast.error(data.error || `Import failed for ${item.classname}`);
|
||||
toast.error(
|
||||
typeof data.error === "string"
|
||||
? data.error
|
||||
: `Import failed for ${item.classname}`,
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
toast.error("Network error");
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "Import connection failed. Check the furniture status before retrying.",
|
||||
);
|
||||
} finally {
|
||||
setImportingId(null);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user