From cd752916e3d88de447fb25146e5176a373862c0e Mon Sep 17 00:00:00 2001 From: Mitch Downey Date: Sun, 28 Apr 2024 22:40:55 -0500 Subject: [PATCH 1/2] Remove parseNSFWHeader --- src/controllers/mediaRef.ts | 5 ----- src/controllers/user.ts | 7 ++----- src/middleware/parseNSFWHeader.ts | 7 ------- src/routes/clips.ts | 3 +-- src/routes/episode.ts | 8 +++----- src/routes/liveItem.ts | 2 -- src/routes/mediaRef.ts | 10 ++++------ src/routes/playlist.ts | 4 +--- src/routes/podcast.ts | 15 ++++++--------- src/routes/secondaryQueue.ts | 5 ++--- src/routes/user.ts | 15 +++++---------- 11 files changed, 24 insertions(+), 57 deletions(-) delete mode 100644 src/middleware/parseNSFWHeader.ts diff --git a/src/controllers/mediaRef.ts b/src/controllers/mediaRef.ts index 64d79758..21315687 100644 --- a/src/controllers/mediaRef.ts +++ b/src/controllers/mediaRef.ts @@ -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(',')) || [] @@ -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)' : ''} ` @@ -153,7 +151,6 @@ const getMediaRefs = async (query, isFromManticoreSearch?, totalOverride?) => { if (includePodcast) { qb.innerJoinAndSelect('mediaRef.episode', 'episode', queryConditions, { - isExplicit: !!includeNSFW, podcastIds: podcastIds, episodeIds: episodeIds }) @@ -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 }) diff --git a/src/controllers/user.ts b/src/controllers/user.ts index bddcb7d7..05d47378 100644 --- a/src/controllers/user.ts +++ b/src/controllers/user.ts @@ -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 }), diff --git a/src/middleware/parseNSFWHeader.ts b/src/middleware/parseNSFWHeader.ts deleted file mode 100644 index 12c85cf6..00000000 --- a/src/middleware/parseNSFWHeader.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const parseNSFWHeader = async (ctx, next) => { - // const includeNSFW = ctx.headers.nsfwmode && ctx.headers.nsfwmode === 'on' - // NOTE: disabling NSFW filtering since it's not a polished feature - // ctx.state.includeNSFW = includeNSFW - ctx.state.includeNSFW = true - await next(ctx) -} diff --git a/src/routes/clips.ts b/src/routes/clips.ts index 050dc1be..476a37e5 100644 --- a/src/routes/clips.ts +++ b/src/routes/clips.ts @@ -4,7 +4,6 @@ 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` }) @@ -12,7 +11,7 @@ const router = new Router({ prefix: `${config.apiPrefix}${config.apiVersion}/cli 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) diff --git a/src/routes/episode.ts b/src/routes/episode.ts index e1c89e67..cccd5702 100644 --- a/src/routes/episode.ts +++ b/src/routes/episode.ts @@ -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' @@ -29,7 +28,6 @@ router.get( '/', (ctx, next) => parseQueryPageOptions(ctx, next, 'episodes'), validateEpisodeSearch, - parseNSFWHeader, async (ctx) => { try { const { query = {} } = ctx.state @@ -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) @@ -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 @@ -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 diff --git a/src/routes/liveItem.ts b/src/routes/liveItem.ts index 1d4413c3..adb25797 100644 --- a/src/routes/liveItem.ts +++ b/src/routes/liveItem.ts @@ -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, @@ -22,7 +21,6 @@ router.get( '/', (ctx, next) => parseQueryPageOptions(ctx, next, 'liveItems'), validateLiveItemSearch, - parseNSFWHeader, async (ctx) => { try { const { query = {} } = ctx.state diff --git a/src/routes/mediaRef.ts b/src/routes/mediaRef.ts index 3f3ad364..7d8b0ef1 100644 --- a/src/routes/mediaRef.ts +++ b/src/routes/mediaRef.ts @@ -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' @@ -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 @@ -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) diff --git a/src/routes/playlist.ts b/src/routes/playlist.ts index d7ee4ed2..f70e957e 100644 --- a/src/routes/playlist.ts +++ b/src/routes/playlist.ts @@ -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' @@ -35,7 +34,6 @@ router.get( '/', (ctx, next) => parseQueryPageOptions(ctx, next, 'playlists'), validatePlaylistSearch, - parseNSFWHeader, async (ctx) => { try { ctx = delimitQueryValues(ctx, delimitKeys) @@ -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) diff --git a/src/routes/podcast.ts b/src/routes/podcast.ts index 03007e51..d90e4b49 100644 --- a/src/routes/podcast.ts +++ b/src/routes/podcast.ts @@ -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 @@ -31,7 +30,6 @@ router.get( '/metadata', (ctx, next) => parseQueryPageOptions(ctx, next, 'podcasts'), validatePodcastSearch, - parseNSFWHeader, async (ctx) => { try { ctx = delimitQueryValues(ctx, delimitKeys) @@ -49,7 +47,6 @@ router.get( '/', (ctx, next) => parseQueryPageOptions(ctx, next, 'podcasts'), validatePodcastSearch, - parseNSFWHeader, async (ctx) => { try { const { query = {} } = ctx.state @@ -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 @@ -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) @@ -119,7 +116,7 @@ router.get('/podcastindex/:id', parseNSFWHeader, async (ctx) => { }) // Redirect to Podcast web page by -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) @@ -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) @@ -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) @@ -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) diff --git a/src/routes/secondaryQueue.ts b/src/routes/secondaryQueue.ts index 452f862e..afde3dbb 100644 --- a/src/routes/secondaryQueue.ts +++ b/src/routes/secondaryQueue.ts @@ -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) { @@ -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, diff --git a/src/routes/user.ts b/src/routes/user.ts index b2317114..3f27e6f4 100644 --- a/src/routes/user.ts +++ b/src/routes/user.ts @@ -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') @@ -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) @@ -162,7 +160,6 @@ router.get( '/', (ctx, next) => parseQueryPageOptions(ctx, next, 'users'), validateUserSearch, - parseNSFWHeader, async (ctx) => { try { ctx = delimitQueryValues(ctx, delimitKeys) @@ -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) @@ -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) @@ -229,7 +225,6 @@ router.get( router.get( '/:id/playlists', (ctx, next) => parseQueryPageOptions(ctx, next, 'playlists'), - parseNSFWHeader, async (ctx) => { try { const { query } = ctx.state From cf4cfba4e16bfb0574d060bacd451fdd1a3487af Mon Sep 17 00:00:00 2001 From: Mitch Downey Date: Sun, 28 Apr 2024 22:41:21 -0500 Subject: [PATCH 2/2] Bump to version 4.16.20 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1859c8b2..19de9580 100644 --- a/package.json +++ b/package.json @@ -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"