Skip to content

Commit

Permalink
Merge pull request #731 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.16.4
  • Loading branch information
mitchdowney committed Apr 6, 2024
2 parents bf97c77 + 0723cd1 commit 5b38a4e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
37 changes: 34 additions & 3 deletions src/controllers/episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,16 +763,26 @@ 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.
const existingChapter = existingChapters.find((x) => x.chapterHash === chapterHash)
if (existingChapter && existingChapter.id) {
await updateMediaRef(
{
endTime: newChapter.endTime || null,
endTime: roundedEndTime,
id: existingChapter.id,
imageUrl: newChapter.img || null,
isOfficialChapter: true,
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down

0 comments on commit 5b38a4e

Please sign in to comment.