From 3b22fe98f216579090ecfc6c1ab912eeac39d873 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 16 Apr 2025 11:53:19 +1200 Subject: [PATCH] Use placeholder for items with no art --- public/missing-art.png | Bin 0 -> 727 bytes routes/_index.js | 8 ++++++++ routes/load-collection.js | 29 +++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 public/missing-art.png diff --git a/public/missing-art.png b/public/missing-art.png new file mode 100644 index 0000000000000000000000000000000000000000..2084c66aa9421e858dea736f45c684e4c9ab6ded GIT binary patch literal 727 zcmeAS@N?(olHy`uVBq!ia0vp^mq3_<4M^J0oaY3jI14-?iy0XB4ude`@%$AjKtah8 z*NBqf{Irtt#G+J&^73-M%)IR42!pu!=+$>i45Fv=Va2T~Hj0q)cl%$6JW S$N2&iC4;A{pUXO@geCy { + handleCacheHeaders(event, {maxAge: 86400}) + defaultContentType(event, "image/png") + return fs.promises.readFile("public/missing-art.png") + } +})) diff --git a/routes/load-collection.js b/routes/load-collection.js index 941cbc7..8d17e57 100644 --- a/routes/load-collection.js +++ b/routes/load-collection.js @@ -54,14 +54,26 @@ async function loadCollection(inputUsername) { db.transaction(() => { for (const item of items.items) { if (!item.tralbum_type.match(/[at]/)) continue // p=product and s=subscription not supported - preparedItem.run({ - account, - ...item, - price: item.price || 0, - purchased: new Date(item.purchased).getTime(), - added: new Date(item.added).getTime(), - updated: new Date(item.updated).getTime() - }) + try { + preparedItem.run({ + account, + ...item, + price: item.price || 0, + item_art_url: item.item_art_url || "/missing-art.png", + purchased: new Date(item.purchased).getTime(), + added: new Date(item.added).getTime(), + updated: new Date(item.updated).getTime() + }) + } catch (cause) { + throw new class extends Error { + constructor() { + super("Unsupported album/track data", {cause}) + this.name = "Collection Import Error" + this.account = account + this.item = item + } + } + } } })() const storedItemCount = db.prepare("SELECT count(*) AS count FROM item WHERE account = ?").pluck().get(account) @@ -101,6 +113,7 @@ router.post("/api/load-collection", defineEventHandler(async event => { setCookie(event, "accounts", (getCookie(event, "accounts") || "").split("|").concat(account).join("|")) return pugSync.render(event, "collection-loaded.pug", result) } catch (error) { + console.error(error) return pugSync.render(event, "collection-loaded.pug", {error}) } }))