Skip to content

Commit

Permalink
Merge pull request #754 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.16.20
  • Loading branch information
mitchdowney authored Apr 29, 2024
2 parents 8c6b84e + cf4cfba commit db5680e
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 58 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.19",
"version": "4.16.20",
"description": "Data API, database migration scripts, and backend services for all Podverse models.",
"contributors": [
"Mitch Downey"
Expand Down
5 changes: 0 additions & 5 deletions src/controllers/mediaRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ const getMediaRefsFromSearchEngine = async (query) => {
}

const getMediaRefs = async (query, isFromManticoreSearch?, totalOverride?) => {
const includeNSFW = true
const { mediaRefId, searchTitle } = query
const mediaRefIds = (mediaRefId && mediaRefId.split(',')) || []
const podcastIds = (query.podcastId && query.podcastId.split(',')) || []
Expand All @@ -143,7 +142,6 @@ const getMediaRefs = async (query, isFromManticoreSearch?, totalOverride?) => {

const queryConditions = `
episode.isPublic = true
${includeNSFW ? '' : 'AND episode.isExplicit = :isExplicit'}
${podcastIds.length > 0 ? 'AND episode.podcastId IN (:...podcastIds)' : ''}
${episodeIds.length > 0 ? 'AND episode.id IN (:...episodeIds)' : ''}
`
Expand All @@ -153,7 +151,6 @@ const getMediaRefs = async (query, isFromManticoreSearch?, totalOverride?) => {

if (includePodcast) {
qb.innerJoinAndSelect('mediaRef.episode', 'episode', queryConditions, {
isExplicit: !!includeNSFW,
podcastIds: podcastIds,
episodeIds: episodeIds
})
Expand All @@ -164,13 +161,11 @@ const getMediaRefs = async (query, isFromManticoreSearch?, totalOverride?) => {
}
} else if (includeEpisode) {
qb.innerJoinAndSelect('mediaRef.episode', 'episode', queryConditions, {
isExplicit: !!includeNSFW,
podcastIds: podcastIds,
episodeIds: episodeIds
})
} else {
qb.innerJoin('mediaRef.episode', 'episode', queryConditions, {
isExplicit: !!includeNSFW,
podcastIds: podcastIds,
episodeIds: episodeIds
})
Expand Down
7 changes: 2 additions & 5 deletions src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,13 @@ const getUserSubscribedPublicUserIds = async (id) => {
return getUserSingleField(id, 'subscribedUserIds')
}

const getUserMediaRefs = async (query, ownerId, includeNSFW, includePrivate) => {
const getUserMediaRefs = async (query, ownerId, includePrivate) => {
const { skip, sort, take } = query
const repository = getRepository(MediaRef)
const episodeJoinAndSelect = `${includeNSFW ? 'true' : 'episode.isExplicit = :isExplicit'}`

let qb = await repository
.createQueryBuilder('mediaRef')
.innerJoinAndSelect('mediaRef.episode', 'episode', episodeJoinAndSelect, {
isExplicit: !!includeNSFW
})
.innerJoinAndSelect('mediaRef.episode', 'episode')
.innerJoinAndSelect('episode.podcast', 'podcast')
.where({
...(includePrivate ? {} : { isPublic: true }),
Expand Down
7 changes: 0 additions & 7 deletions src/middleware/parseNSFWHeader.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/routes/clips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { config } from '~/config'
import { emitRouterError } from '~/lib/errors'
import { convertToChaptersFile } from '~/lib/podcastIndex'
import { getPublicMediaRefsByEpisodeGuid } from '~/controllers/mediaRef'
import { parseNSFWHeader } from '~/middleware/parseNSFWHeader'
const json = require('koa-json')

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

router.use(bodyParser())

// Get public mediaRefs by episode guid
router.get('/', parseNSFWHeader, json(), async (ctx) => {
router.get('/', json(), async (ctx) => {
try {
const { episodeGuid, podcastId } = ctx.query
const mediaRefsResult = await getPublicMediaRefsByEpisodeGuid(episodeGuid, podcastId)
Expand Down
8 changes: 3 additions & 5 deletions src/routes/episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '~/controllers/episode'
import { parseQueryPageOptions } from '~/middleware/parseQueryPageOptions'
import { validateEpisodeSearch } from '~/middleware/queryValidation/search'
import { parseNSFWHeader } from '~/middleware/parseNSFWHeader'
import { getThreadcap } from '~/services/socialInteraction/threadcap'
import { request } from '~/lib/request'
// import { MediaRef } from '~/entities'
Expand All @@ -29,7 +28,6 @@ router.get(
'/',
(ctx, next) => parseQueryPageOptions(ctx, next, 'episodes'),
validateEpisodeSearch,
parseNSFWHeader,
async (ctx) => {
try {
const { query = {} } = ctx.state
Expand Down Expand Up @@ -57,7 +55,7 @@ router.get(
)

// Get
router.get('/:id', parseNSFWHeader, async (ctx) => {
router.get('/:id', async (ctx) => {
try {
const episode = await getEpisode(ctx.params.id)

Expand Down Expand Up @@ -226,7 +224,7 @@ router.get('/:id/proxy/twitter', async (ctx) => {
})

// Get Episode by GUID
router.post('/get-by-guid', parseNSFWHeader, async (ctx) => {
router.post('/get-by-guid', async (ctx) => {
try {
const body: any = ctx.request.body
const { episodeGuid, podcastId } = body
Expand All @@ -238,7 +236,7 @@ router.post('/get-by-guid', parseNSFWHeader, async (ctx) => {
})

// Get Episode by guid
router.post('/get-by-guid', parseNSFWHeader, async (ctx) => {
router.post('/get-by-guid', async (ctx) => {
try {
const body: any = ctx.request.body
const { episodeGuid, podcastId } = body
Expand Down
2 changes: 0 additions & 2 deletions src/routes/liveItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { emitRouterError } from '~/lib/errors'
import { getLiveItems } from '~/controllers/liveItem'
import { parseQueryPageOptions } from '~/middleware/parseQueryPageOptions'
import { validateLiveItemSearch } from '~/middleware/queryValidation/search'
import { parseNSFWHeader } from '~/middleware/parseNSFWHeader'
import { delimitQueryValues } from '~/lib/utility'
import {
getEpisodes,
Expand All @@ -22,7 +21,6 @@ router.get(
'/',
(ctx, next) => parseQueryPageOptions(ctx, next, 'liveItems'),
validateLiveItemSearch,
parseNSFWHeader,
async (ctx) => {
try {
const { query = {} } = ctx.state
Expand Down
10 changes: 4 additions & 6 deletions src/routes/mediaRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
updateMediaRef
} from '~/controllers/mediaRef'
import { jwtAuth } from '~/middleware/auth/jwtAuth'
import { parseNSFWHeader } from '~/middleware/parseNSFWHeader'
import { parseQueryPageOptions } from '~/middleware/parseQueryPageOptions'
import { validateMediaRefCreate } from '~/middleware/queryValidation/create'
import { validateMediaRefSearch } from '~/middleware/queryValidation/search'
Expand All @@ -32,19 +31,18 @@ router.get(
'/',
(ctx, next) => parseQueryPageOptions(ctx, next, 'mediaRefs'),
validateMediaRefSearch,
parseNSFWHeader,
async (ctx) => {
try {
const { includeNSFW, query } = ctx.state
const { query } = ctx.state
ctx = delimitQueryValues(ctx, delimitKeys)
let mediaRefs = [[], 0]

if (query.podcastId && query.searchTitle) {
mediaRefs = await getMediaRefs(query, includeNSFW)
mediaRefs = await getMediaRefs(query)
} else if (query.searchTitle) {
mediaRefs = await getMediaRefsFromSearchEngine(query)
} else {
mediaRefs = await getMediaRefs(query, includeNSFW)
mediaRefs = await getMediaRefs(query)
}

ctx.body = mediaRefs
Expand All @@ -55,7 +53,7 @@ router.get(
)

// Get
router.get('/:id', parseNSFWHeader, async (ctx) => {
router.get('/:id', async (ctx) => {
try {
const mediaRef = await getMediaRef(ctx.params.id)

Expand Down
4 changes: 1 addition & 3 deletions src/routes/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
updatePlaylist
} from '~/controllers/playlist'
import { jwtAuth } from '~/middleware/auth/jwtAuth'
import { parseNSFWHeader } from '~/middleware/parseNSFWHeader'
import { parseQueryPageOptions } from '~/middleware/parseQueryPageOptions'
import { validatePlaylistCreate } from '~/middleware/queryValidation/create'
import { validatePlaylistSearch } from '~/middleware/queryValidation/search'
Expand All @@ -35,7 +34,6 @@ router.get(
'/',
(ctx, next) => parseQueryPageOptions(ctx, next, 'playlists'),
validatePlaylistSearch,
parseNSFWHeader,
async (ctx) => {
try {
ctx = delimitQueryValues(ctx, delimitKeys)
Expand Down Expand Up @@ -71,7 +69,7 @@ router.get(
)

// Get
router.get('/:id', parseNSFWHeader, async (ctx) => {
router.get('/:id', async (ctx) => {
try {
const playlist = await getPlaylist(ctx.params.id)

Expand Down
15 changes: 6 additions & 9 deletions src/routes/podcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { emitRouterError } from '~/lib/errors'
import { delimitQueryValues } from '~/lib/utility'
import { hasValidMembership } from '~/middleware/hasValidMembership'
import { jwtAuth } from '~/middleware/auth/jwtAuth'
import { parseNSFWHeader } from '~/middleware/parseNSFWHeader'
import { parseQueryPageOptions } from '~/middleware/parseQueryPageOptions'
import { validatePodcastSearch } from '~/middleware/queryValidation/search'
const RateLimit = require('koa2-ratelimit').RateLimit
Expand All @@ -31,7 +30,6 @@ router.get(
'/metadata',
(ctx, next) => parseQueryPageOptions(ctx, next, 'podcasts'),
validatePodcastSearch,
parseNSFWHeader,
async (ctx) => {
try {
ctx = delimitQueryValues(ctx, delimitKeys)
Expand All @@ -49,7 +47,6 @@ router.get(
'/',
(ctx, next) => parseQueryPageOptions(ctx, next, 'podcasts'),
validatePodcastSearch,
parseNSFWHeader,
async (ctx) => {
try {
const { query = {} } = ctx.state
Expand Down Expand Up @@ -94,7 +91,7 @@ router.get(
)

// Get by Podcast Index ID
router.get('/podcastindex/data/:id', parseNSFWHeader, async (ctx) => {
router.get('/podcastindex/data/:id', async (ctx) => {
try {
const podcast = await getPodcastByPodcastIndexId(ctx.params.id)
ctx.body = podcast
Expand All @@ -104,7 +101,7 @@ router.get('/podcastindex/data/:id', parseNSFWHeader, async (ctx) => {
})

// Redirect to Podcast web page by Podcast Index ID
router.get('/podcastindex/:id', parseNSFWHeader, async (ctx) => {
router.get('/podcastindex/:id', async (ctx) => {
try {
const podcast = await getPodcastByPodcastIndexId(ctx.params.id)

Expand All @@ -119,7 +116,7 @@ router.get('/podcastindex/:id', parseNSFWHeader, async (ctx) => {
})

// Redirect to Podcast web page by <podcast:guid>
router.get('/by-podcast-guid/:podcastGuid', parseNSFWHeader, async (ctx) => {
router.get('/by-podcast-guid/:podcastGuid', async (ctx) => {
try {
const podcast = await getPodcastByPodcastGuid(ctx.params.podcastGuid)

Expand All @@ -134,7 +131,7 @@ router.get('/by-podcast-guid/:podcastGuid', parseNSFWHeader, async (ctx) => {
})

// Redirect to Podcast web page by feedUrl
router.get('/by-feed-url', parseNSFWHeader, async (ctx) => {
router.get('/by-feed-url', async (ctx) => {
try {
const feedUrl = ctx.query.feedUrl ? (ctx.query.feedUrl as string) : ''
const decodedFeedUrl = decodeURIComponent(feedUrl)
Expand All @@ -156,7 +153,7 @@ router.get('/by-feed-url', parseNSFWHeader, async (ctx) => {
})

// Get
router.get('/:id', parseNSFWHeader, async (ctx) => {
router.get('/:id', async (ctx) => {
try {
const podcast = await getPodcast(ctx.params.id)

Expand All @@ -167,7 +164,7 @@ router.get('/:id', parseNSFWHeader, async (ctx) => {
})

// Find Podcasts by FeedUrls
router.post('/find-by-feed-urls', parseNSFWHeader, async (ctx) => {
router.post('/find-by-feed-urls', async (ctx) => {
try {
const body: any = ctx.request.body
const results = await findPodcastsByFeedUrls(body.feedUrls)
Expand Down
5 changes: 2 additions & 3 deletions src/routes/secondaryQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import {
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` })

// Get episodes that are adjacent within a podcast
router.get('/podcast/:podcastId/episode/:episodeId', parseNSFWHeader, async (ctx) => {
router.get('/podcast/:podcastId/episode/:episodeId', async (ctx) => {
try {
const { withFix } = ctx.query
if (!!withFix) {
Expand All @@ -28,7 +27,7 @@ router.get('/podcast/:podcastId/episode/:episodeId', parseNSFWHeader, async (ctx
})

// Get episodes that are adjacent within a playlist
router.get('/playlist/:playlistId/episode-or-media-ref/:episodeOrMediaRef', parseNSFWHeader, async (ctx) => {
router.get('/playlist/:playlistId/episode-or-media-ref/:episodeOrMediaRef', async (ctx) => {
try {
const data = await getSecondaryQueueEpisodesForPlaylist(
ctx.params.playlistId,
Expand Down
15 changes: 5 additions & 10 deletions src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { delimitQueryValues } from '~/lib/utility'
import { jwtAuth } from '~/middleware/auth/jwtAuth'
import { hasValidMembership } from '~/middleware/hasValidMembership'
import { parseQueryPageOptions } from '~/middleware/parseQueryPageOptions'
import { parseNSFWHeader } from '~/middleware/parseNSFWHeader'
import { validateUserSearch } from '~/middleware/queryValidation/search'
import { validateUserUpdate } from '~/middleware/queryValidation/update'
const archiver = require('archiver')
Expand Down Expand Up @@ -107,13 +106,12 @@ router.get('/download', downloadUserLimiter, jwtAuth, async (ctx) => {
router.get(
'/mediaRefs',
jwtAuth,
parseNSFWHeader,
(ctx, next) => parseQueryPageOptions(ctx, next, 'mediaRefs'),
async (ctx) => {
try {
const { query } = ctx.state

const mediaRefs = await getUserMediaRefs(query, ctx.state.user.id, ctx.state.includeNSFW, true)
const includePrivate = true
const mediaRefs = await getUserMediaRefs(query, ctx.state.user.id, includePrivate)
ctx.body = mediaRefs
} catch (error) {
emitRouterError(error, ctx)
Expand Down Expand Up @@ -162,7 +160,6 @@ router.get(
'/',
(ctx, next) => parseQueryPageOptions(ctx, next, 'users'),
validateUserSearch,
parseNSFWHeader,
async (ctx) => {
try {
ctx = delimitQueryValues(ctx, delimitKeys)
Expand Down Expand Up @@ -198,7 +195,7 @@ router.get(
)

// Get Public User
router.get('/:id', parseNSFWHeader, async (ctx) => {
router.get('/:id', async (ctx) => {
try {
const user = await getPublicUser(ctx.params.id)

Expand All @@ -212,12 +209,11 @@ router.get('/:id', parseNSFWHeader, async (ctx) => {
router.get(
'/:id/mediaRefs',
(ctx, next) => parseQueryPageOptions(ctx, next, 'mediaRefs'),
parseNSFWHeader,
async (ctx) => {
try {
const { query } = ctx.state

const mediaRefs = await getUserMediaRefs(query, ctx.params.id, ctx.state.includeNSFW, false)
const includePrivate = false
const mediaRefs = await getUserMediaRefs(query, ctx.params.id, includePrivate)
ctx.body = mediaRefs
} catch (error) {
emitRouterError(error, ctx)
Expand All @@ -229,7 +225,6 @@ router.get(
router.get(
'/:id/playlists',
(ctx, next) => parseQueryPageOptions(ctx, next, 'playlists'),
parseNSFWHeader,
async (ctx) => {
try {
const { query } = ctx.state
Expand Down

0 comments on commit db5680e

Please sign in to comment.