Skip to content

Commit b5ef069

Browse files
authored
fix getrandomproject and latest
1 parent 3a0a5f5 commit b5ef069

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

static/extensions/SammerLOL/pangapi.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,14 @@
377377
return `${apiURL}projects/getproject?projectID=${Cast.toString(args.id)}&requestType=thumbnail`;
378378
}
379379

380+
// TODO: either add parameter to get multiple or have a block to get multiple (either say multiple or 20)
380381
async rnd() {
381382
try {
382383
const response = await fetch(`${apiURL}projects/getrandomproject`);
383384
if (!response.ok) throw new Error("Failed to fetch random project");
384385
let data = await response.json();
385386

386-
return data.id;
387+
return data[0].id;
387388
} catch {
388389
return "";
389390
}
@@ -393,17 +394,18 @@
393394
const id = this.generateIdWithArgs("latestProject", {});
394395
let data = this.getCached(id);
395396

397+
console.log(data);
398+
396399
try {
397400
if (data === null) {
398401
const response = await fetch(`${apiURL}projects/getprojects`);
399402
if (!response.ok) throw new Error("Failed to fetch latest project");
400403
data = await response.json();
404+
// Check if there are projects in the array
405+
if (data && data.length) data = JSON.stringify(data[0]);
406+
else return "{}";
401407
}
402-
403-
// Check if there are projects in the array
404-
if (data && data.length) data = JSON.stringify(data[0]);
405-
else return "{}";
406-
408+
407409
this.setCached(id, data, true);
408410
return data;
409411
} catch {

0 commit comments

Comments
 (0)