mirror of
https://github.com/TautvydasDerzinskas/Thingport.git
synced 2026-10-21 22:22:24 -05:00
fix: count only MakerWorld profiles with an id before taking the raw files
The import now skips profile records without an id, as the profile jobs already did, so a model with none usable gets its raw files there too.
This commit is contained in:
1 parent
437d85be14
commit
8affbbb6c3
2 files changed
+21
-1
No files matched your search
@@ -380,7 +380,10 @@ export async function resolveMakerworldViaCloudApi(
|
||||
if (designResult.status === 401 || designResult.status === 403) throw new MakerworldAuthError();
|
||||
if (designResult.status !== 200 || !isRecord(designResult.data)) return null;
|
||||
const design = designResult.data;
|
||||
const instances = Array.isArray(design.instances) ? design.instances.filter(isRecord) : [];
|
||||
// The profiles selectMakerworldProfiles counts, so a job that found none gets the raw files here too.
|
||||
const instances = Array.isArray(design.instances)
|
||||
? design.instances.filter(isRecord).filter((inst) => inst.id != null)
|
||||
: [];
|
||||
if (!instances.length) return resolveMakerworldRawFiles(designId, design, bearerToken, paceMs);
|
||||
|
||||
const modelId = typeof design.modelId === "string" && design.modelId.trim() ? design.modelId.trim() : null;
|
||||
|
||||
@@ -70,6 +70,23 @@ describe("resolveMakerworldViaCloudApi", () => {
|
||||
expect(fetched.some((url) => url.includes("/iot-service/"))).toBe(false);
|
||||
});
|
||||
|
||||
it("takes the raw files when no profile has an id to download it by", async () => {
|
||||
global.fetch = vi.fn<(input: RequestInfo | URL) => Promise<Response>>(async (input) => {
|
||||
const url = String(input);
|
||||
if (url.endsWith("/design-service/design/778")) {
|
||||
return jsonResponse(200, { id: 778, modelId: "model-778", instances: [{ profileId: "p" }] });
|
||||
}
|
||||
if (url.includes("/design-service/design/778/model?")) {
|
||||
return jsonResponse(200, { url: "https://makerworld.bblmw.com/model/778/all.zip" });
|
||||
}
|
||||
throw new Error(`Unexpected fetch to ${url}`);
|
||||
}) as unknown as typeof fetch;
|
||||
|
||||
const result = await resolveMakerworldViaCloudApi("778", null, "test-token");
|
||||
|
||||
expect(result?.downloadUrl).toBe("https://makerworld.bblmw.com/model/778/all.zip");
|
||||
});
|
||||
|
||||
it("throws MakerworldDownloadLimitError on the daily download limit reply", async () => {
|
||||
global.fetch = vi.fn<(input: RequestInfo | URL) => Promise<Response>>(async (input) => {
|
||||
const url = String(input);
|
||||
|
||||
Reference in new issue
Block a user