From d2b79f3314c14ff30d2439aa4d9badaa50992bdb Mon Sep 17 00:00:00 2001 From: Mitch Downey Date: Sat, 6 Apr 2024 15:14:34 -0500 Subject: [PATCH 1/2] Fix chapterHash and auto-delete hidden chapters at end of chapter parsing job --- src/controllers/episode.ts | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/controllers/episode.ts b/src/controllers/episode.ts index e8c36351..583d4a16 100644 --- a/src/controllers/episode.ts +++ b/src/controllers/episode.ts @@ -763,8 +763,18 @@ const retrieveLatestChapters = async (id, includeNonToc = true) => { try { const newChapter = newChapters[i] const roundedStartTime = Math.floor(newChapter.startTime) + const roundedEndTime = + newChapter.endTime !== null && newChapter.endTime >= 1 ? Math.floor(newChapter.endTime) : null const isChapterToc = newChapter.toc === false ? false : newChapter.toc - const chapterHash = uuidv5(JSON.stringify(newChapter), uuidNIL) + + const chapterInfoToHash = { + startTime: roundedStartTime, + endTime: roundedEndTime || null, + isChapterToc, + episodeId: id + } + + const chapterHash = uuidv5(JSON.stringify(chapterInfoToHash), uuidNIL) // If a chapter with that chapterHash already exists, then update it. // If it does not exist, then create a new mediaRef with isOfficialChapter = true. @@ -772,7 +782,7 @@ const retrieveLatestChapters = async (id, includeNonToc = true) => { if (existingChapter && existingChapter.id) { await updateMediaRef( { - endTime: newChapter.endTime || null, + endTime: roundedEndTime, id: existingChapter.id, imageUrl: newChapter.img || null, isOfficialChapter: true, @@ -788,7 +798,7 @@ const retrieveLatestChapters = async (id, includeNonToc = true) => { ) } else { await createMediaRef({ - endTime: newChapter.endTime || null, + endTime: roundedEndTime, imageUrl: newChapter.img || null, isOfficialChapter: true, isPublic: true, @@ -806,6 +816,27 @@ const retrieveLatestChapters = async (id, includeNonToc = true) => { } } } + + const qb = mediaRefRepository + .createQueryBuilder('mediaRef') + .select('mediaRef.id', 'id') + .addSelect('mediaRef.isOfficialChapter', 'isOfficialChapter') + .addSelect('mediaRef.chapterHash', 'chapterHash') + .addSelect('mediaRef.isPublic', 'isPublic') + .where({ + isOfficialChapter: true, + episode: episode.id, + isPublic: false + }) + + const hiddenChaptersToDelete = await qb.getRawMany() + for (const chapterToDelete of hiddenChaptersToDelete) { + try { + await mediaRefRepository.remove(chapterToDelete) + } catch (error) { + console.log('error removing isPublic false chapter:', error) + } + } } catch (error) { console.log('retrieveLatestChapters request', error) } From 0723cd1573576c35db2f93a5dc67165743b22bed Mon Sep 17 00:00:00 2001 From: Mitch Downey Date: Sat, 6 Apr 2024 15:21:50 -0500 Subject: [PATCH 2/2] Bump to version 4.16.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b073a2b4..f9d8de29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "podverse-api", - "version": "4.16.3", + "version": "4.16.4", "description": "Data API, database migration scripts, and backend services for all Podverse models.", "contributors": [ "Mitch Downey"