Skip to content

Commit

Permalink
Merge pull request #707 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.15.12
  • Loading branch information
mitchdowney authored Nov 28, 2023
2 parents 0b411cf + 629e87c commit 606ca05
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 27 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.15.11",
"version": "4.15.12",
"description": "Data API, database migration scripts, and backend services for all Podverse models.",
"contributors": [
"Mitch Downey"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const generateEpisodeSelects = (
}

if (podcastsOnly) {
qb.andWhere(`podcast.medium = 'podcast' OR podcast."hasVideo" IS true`)
qb.andWhere(`(podcast.medium = 'podcast' OR podcast."hasVideo" IS true)`)
}

if (liveItemStatus) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/mediaRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const getMediaRefs = async (query, isFromManticoreSearch?, totalOverride?) => {
}

if (podcastsOnly) {
qb.andWhere(`podcast.medium = 'podcast' OR podcast."hasVideo" IS true`)
qb.andWhere(`(podcast.medium = 'podcast' OR podcast."hasVideo" IS true)`)
}

const allowRandom = podcastIds.length > 0 || episodeIds.length > 0
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ const addOrRemovePlaylistItem = async (playlistId, mediaRefId, episodeId, logged
actionTaken = 'added'
const filteredMedium = getPlaylistMedium(mediaRef.episode.podcast.medium)
if (playlist.medium !== 'mixed' && playlist.medium !== filteredMedium) {
throw new createError.NotFound('Item can not be added to this type of playlist')
throw new createError.BadRequest('Item can not be added to this type of playlist')
}
playlist.mediaRefs.push(mediaRef)
playlist.itemsOrder.push(mediaRef.id)
Expand All @@ -314,7 +314,7 @@ const addOrRemovePlaylistItem = async (playlistId, mediaRefId, episodeId, logged
actionTaken = 'added'
const filteredMedium = getPlaylistMedium(episode.podcast.medium)
if (playlist.medium !== 'mixed' && playlist.medium !== filteredMedium) {
throw new createError.NotFound('Item can not be added to this type of playlist')
throw new createError.BadRequest('Item can not be added to this type of playlist')
}
playlist.episodes.push(episode)
playlist.itemsOrder.push(episode.id)
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/podcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const getPodcasts = async (query, countOverride?, isFromManticoreSearch?) => {
}

if (podcastsOnly) {
qb.andWhere(`podcast.medium = 'podcast' OR podcast."hasVideo" IS true`)
qb.andWhere(`(podcast.medium = 'podcast' OR podcast."hasVideo" IS true)`)
}

const allowRandom = !!podcastIds
Expand Down
75 changes: 73 additions & 2 deletions src/controllers/secondaryQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,73 @@ type SecondaryQueueEpisodesForPodcastIdResponseData = {
inheritedPodcast: Podcast
}

export const getSecondaryQueueEpisodesForPodcastId2 = async (
episodeId: string,
podcastId: string
): Promise<SecondaryQueueEpisodesForPodcastIdResponseData> => {
const repository = getRepository(Episode)
const currentEpisode = await repository.findOne(
{
isPublic: true,
id: episodeId
},
{ relations }
)

if (!currentEpisode || currentEpisode.liveItem) {
throw new createError.NotFound('Episode not found')
}

const inheritedPodcast = currentEpisode.podcast
if (!inheritedPodcast) {
throw new createError.NotFound('Podcast not found')
}

const { itunesEpisode, pubDate } = currentEpisode
const take = currentEpisode.podcast.medium === 'music' ? 50 : 10

const previousEpisodesAndWhere =
currentEpisode.podcast.medium === 'music'
? { itunesEpisode: LessThan(itunesEpisode) }
: { pubDate: LessThan(pubDate) }
const previousEpisodesOrder =
currentEpisode.podcast.medium === 'music' ? ['itunesEpisode', 'DESC'] : ['pubDate', 'DESC']
const previousEpisodes = await repository.find({
where: {
isPublic: true,
podcastId,
...previousEpisodesAndWhere
},
order: {
[previousEpisodesOrder[0]]: previousEpisodesOrder[1]
},
take,
relations: ['authors', 'podcast', 'podcast.authors']
})

const nextEpisodesAndWhere =
currentEpisode.podcast.medium === 'music'
? { itunesEpisode: MoreThan(itunesEpisode) }
: { pubDate: MoreThan(pubDate) }
const nextEpisodesOrder = currentEpisode.podcast.medium === 'music' ? ['itunesEpisode', 'ASC'] : ['pubDate', 'ASC']
const nextEpisodes = await repository.find({
where: {
isPublic: true,
podcastId,
...nextEpisodesAndWhere
},
order: {
[nextEpisodesOrder[0]]: nextEpisodesOrder[1]
},
take,
relations: ['authors', 'podcast', 'podcast.authors']
})

return { previousEpisodes, nextEpisodes, inheritedPodcast }
}

// THIS HAS SOME CRITICAL BUGS IN PODVERSE-RN 4.15.0
// I'M DEPRECATING IT AND REPLACING IT WITH THE "2" VERSION
export const getSecondaryQueueEpisodesForPodcastId = async (
episodeId: string,
podcastId: string
Expand Down Expand Up @@ -85,7 +152,8 @@ type SecondaryQueueEpisodesForPlaylistIdResponseData = {
export const getSecondaryQueueEpisodesForPlaylist = async (
playlistId: string,
episodeOrMediaRefId: string,
audioOnly: boolean
audioOnly: boolean,
withFix: boolean
): Promise<SecondaryQueueEpisodesForPlaylistIdResponseData> => {
const currentPlaylist = await getPlaylist(playlistId)

Expand Down Expand Up @@ -114,7 +182,10 @@ export const getSecondaryQueueEpisodesForPlaylist = async (
})

// limit to the nearest 50 ids
const previousEpisodesAndMediaRefs = filteredPlaylistItems.slice(currentItemIndex - 50, currentItemIndex)
let previousEpisodesAndMediaRefs = filteredPlaylistItems.slice(currentItemIndex - 50, currentItemIndex)
if (withFix) {
previousEpisodesAndMediaRefs = previousEpisodesAndMediaRefs.reverse()
}
const nextEpisodesAndMediaRefs = filteredPlaylistItems.slice(currentItemIndex + 1, currentItemIndex + 1 + 50)

return { previousEpisodesAndMediaRefs, nextEpisodesAndMediaRefs }
Expand Down
28 changes: 13 additions & 15 deletions src/routes/secondaryQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ import * as Router from 'koa-router'
import { config } from '~/config'
import {
getSecondaryQueueEpisodesForPodcastId,
getSecondaryQueueEpisodesForPlaylist
getSecondaryQueueEpisodesForPlaylist,
getSecondaryQueueEpisodesForPodcastId2
} from '~/controllers/secondaryQueue'
import { emitRouterError } from '~/lib/errors'
import { parseNSFWHeader } from '~/middleware/parseNSFWHeader'

const router = new Router({ prefix: `${config.apiPrefix}${config.apiVersion}/secondary-queue` })

/* TODO: REMOVE THIS AFTER NEXT BETA RELEASE */
// Get episodes that are adjacent within a podcast
router.get('/episode/:episodeId/podcast/:podcastId', parseNSFWHeader, async (ctx) => {
try {
const data = await getSecondaryQueueEpisodesForPodcastId(ctx.params.episodeId, ctx.params.podcastId)
ctx.body = data
} catch (error) {
emitRouterError(error, ctx)
}
})

// Get episodes that are adjacent within a podcast
router.get('/podcast/:podcastId/episode/:episodeId', parseNSFWHeader, async (ctx) => {
try {
const data = await getSecondaryQueueEpisodesForPodcastId(ctx.params.episodeId, ctx.params.podcastId)
ctx.body = data
const { withFix } = ctx.query
if (!!withFix) {
const data = await getSecondaryQueueEpisodesForPodcastId2(ctx.params.episodeId, ctx.params.podcastId)
ctx.body = data
} else {
// DEPRECATED AS OF v4.15.1 PODVERSE MOBILE
const data = await getSecondaryQueueEpisodesForPodcastId(ctx.params.episodeId, ctx.params.podcastId)
ctx.body = data
}
} catch (error) {
emitRouterError(error, ctx)
}
Expand All @@ -36,7 +33,8 @@ router.get('/playlist/:playlistId/episode-or-media-ref/:episodeOrMediaRef', pars
const data = await getSecondaryQueueEpisodesForPlaylist(
ctx.params.playlistId,
ctx.params.episodeOrMediaRef,
!!ctx.query.audioOnly
!!ctx.query.audioOnly,
!!ctx.query.withFix
)
ctx.body = data
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions src/seeds/qa/podcastIndexIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
export const podcastIndexIds = [
5718023, 387129, 3662287, 160817, 150842, 878147, 487548, 167137, 465231, 767934, 577105, 54545, 650774, 955598,
3758236, 203827, 879740, 393504, 575694, 921030, 41504, 5341434, 757675, 174725, 920666, 1333070, 227573, 5465405,
5498327, 5495489, 556715, 5485175, 202764, 830124, 66844, 4169501, 6524027
5498327, 5495489, 556715, 5485175, 202764, 830124, 66844, 4169501, 6524027, 6569395
]
export const podcastIndexIdsQuick = [5718023, 387129, 3662287, 160817]
export const podcastIndexIdsQuick = [5718023, 387129, 3662287, 160817, 6569395]

export const podcastIndexIdsWithLiveItems = [
4935828, 5495489, 162612, 5461087, 486332, 480983, 3727160, 5496786, 901876, 5498327, 4207213, 5710520, 5465405,
5485175, 574891, 920666, 540927, 4432692, 5718023, 41504, 3756449, 150842, 937170, 946122, 5373053, 624721, 5700613,
288180, 955598, 6524027
288180, 955598, 6524027, 6569395
]

export const podcastIndexIdsWithLiveItemsQuick = [4935828, 5495489, 162612, 5461087, 6524027]
export const podcastIndexIdsWithLiveItemsQuick = [4935828, 5495489, 162612, 5461087, 6524027, 6569395]

0 comments on commit 606ca05

Please sign in to comment.