diff --git a/public/missing-art.png b/public/missing-art.png new file mode 100644 index 0000000..2084c66 Binary files /dev/null and b/public/missing-art.png differ diff --git a/routes/_index.js b/routes/_index.js index b16468f..c68dd2f 100644 --- a/routes/_index.js +++ b/routes/_index.js @@ -69,3 +69,11 @@ router.get("/favicon.png", defineEventHandler({ return fs.promises.readFile("public/favicon.png") } })) + +router.get("/missing-art.png", defineEventHandler({ + handler: async event => { + 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}) } }))