fix(extension): check a MakerWorld collection against the library in one call

The collection panel sent one /import/status request per model, all at
once. When any failed it counted the model as new, so a collection
already imported could offer to import almost everything again.

Add POST /import/status/batch and use it, falling back to paced
per-model checks on older instances. A failed check now shows an error
instead of guessing.
This commit is contained in:
Tautvydas Derzinskas committed 2026-10-12 03:50:28 +02:00
1 parent 1408b09c59
commit 44c687b3ae
3 files changed
+60 -11

No files matched your search

+16
View File
@@ -16,6 +16,7 @@ import {
importPrintFromUrl,
inspectImportLink,
} from "../services/importService";
import { findLibraryPrints } from "../services/collectionSyncService";
import { resolveMakerworldCookie } from "../services/importResolvers";
import {
extractMakerworldBearerToken,
@@ -190,6 +191,21 @@ router.get(
}),
);
const statusBatchSchema = z.object({
provider: z.enum(["makerworld", "thingiverse", "printables"]),
external_ids: z.array(z.string().max(64)).max(10_000),
});
// One query for a whole collection page; per-model /import/status calls bog down on big ones.
router.post(
"/import/status/batch",
asyncHandler(async (req, res) => {
const body = parseBody(statusBatchSchema, req.body);
const prints = await findLibraryPrints(req.userId!, body.provider, body.external_ids);
res.json({ print_ids: Object.fromEntries(prints) });
}),
);
router.post(
"/import/zip/entries",
asyncHandler(async (req, res) => {
+5
View File
@@ -227,6 +227,11 @@ describe("filling a model's missing details from its source", () => {
.get(`/api/import/status?url=${encodeURIComponent(`https://makerworld.com/en/models/${designId}`)}`)
.set(auth());
expect(status.body.gaps).toEqual([]);
const batch = await request(app)
.post("/api/import/status/batch")
.set(auth())
.send({ provider: "makerworld", external_ids: [designId, "0"] });
expect(batch.body.print_ids).toEqual({ [designId]: print.id });
// Clearing a field the source does have opens a gap again.
await prisma.print.update({ where: { id: print.id }, data: { notes: null } });