From 90bc2f3724fe00f4acacf261ca69100f15538c70 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 28 Jan 2022 04:05:29 +0100 Subject: [PATCH] Changed release media association existence check, added log for details. --- .eslintrc | 3 ++- assets/components/entities/entity.vue | 4 ++-- src/media.js | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 846a916c..3d7c5f9f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -17,10 +17,11 @@ "vue/html-indent": ["error", "tab"], "vue/multiline-html-element-content-newline": 0, "vue/singleline-html-element-content-newline": 0, + "vue/multi-word-component-names": 0, "no-param-reassign": ["error", { "props": true, "ignorePropertyModificationsFor": ["state", "acc"] - }], + }] }, "globals": { "CONFIG": true diff --git a/assets/components/entities/entity.vue b/assets/components/entities/entity.vue index a52da49c..705e70cc 100644 --- a/assets/components/entities/entity.vue +++ b/assets/components/entities/entity.vue @@ -153,8 +153,8 @@ async function fetchEntity(scroll = true) { this.pageTitle = entity.name; - const campaign = entity.campaigns.find(campaignX => !campaignX.banner) - || entity.parent?.campaigns.find(campaignX => !campaignX.banner); + const campaign = entity.campaigns.find((campaignX) => !campaignX.banner) + || entity.parent?.campaigns.find((campaignX) => !campaignX.banner); const affiliateParams = new URLSearchParams({ ...(entity.url && Object.fromEntries(new URL(entity.url).searchParams)), // preserve any query in entity URL, e.g. ?siteId=5 diff --git a/src/media.js b/src/media.js index f1399522..a2ec606f 100644 --- a/src/media.js +++ b/src/media.js @@ -826,11 +826,12 @@ async function associateReleaseMedia(releases, type = 'release') { .reduce((acc, [releaseId, releaseBaseMedias]) => { releaseBaseMedias.forEach((baseMedia) => { const media = storedMediasById[baseMedia.id]; + const mediaId = media?.use || media?.entry?.id; - if (media) { + if (mediaId) { acc.push({ [`${type}_id`]: releaseId, - media_id: media.use || media.entry.id, + media_id: mediaId, }); } }); @@ -839,11 +840,19 @@ async function associateReleaseMedia(releases, type = 'release') { }, []) .filter(Boolean); - if (associations.length > 0) { - await bulkInsert(`${type}s_${role}`, associations, false); + try { + if (associations.length > 0) { + await bulkInsert(`${type}s_${role}`, associations, false); + } + } catch (error) { + console.log(associations); + throw error; } } catch (error) { - logger.error(util.inspect(error.entries, null, null, { color: true })); + if (error.entries) { + logger.error(util.inspect(error.entries, null, null, { color: true })); + } + logger.error(`Failed to store ${type} ${role}: ${error.message}`); } }, Promise.resolve());