(breaking): Always list nsfw videos in playlists

Keep the same behaviour as unlisted videos
The frontend is in charge to blur the video element if the nsfw setting
is "hide" or "blur"
This commit is contained in:
Chocobozzz 2023-01-19 15:04:10 +01:00
parent 789ba34931
commit a68ccaead6
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 22 additions and 39 deletions

View File

@ -15,7 +15,7 @@ import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/vid
import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model' import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model'
import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model' import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
import { resetSequelizeInstance } from '../../helpers/database-utils' import { resetSequelizeInstance } from '../../helpers/database-utils'
import { buildNSFWFilter, createReqFiles } from '../../helpers/express-utils' import { createReqFiles } from '../../helpers/express-utils'
import { logger } from '../../helpers/logger' import { logger } from '../../helpers/logger'
import { getFormattedObjects } from '../../helpers/utils' import { getFormattedObjects } from '../../helpers/utils'
import { CONFIG } from '../../initializers/config' import { CONFIG } from '../../initializers/config'
@ -474,10 +474,7 @@ async function getVideoPlaylistVideos (req: express.Request, res: express.Respon
'filter:api.video-playlist.videos.list.result' 'filter:api.video-playlist.videos.list.result'
) )
const options = { const options = { accountId: user?.Account?.id }
displayNSFW: buildNSFWFilter(res, req.query.nsfw),
accountId: user ? user.Account.id : undefined
}
return res.json(getFormattedObjects(resultList.data, resultList.total, options)) return res.json(getFormattedObjects(resultList.data, resultList.total, options))
} }

View File

@ -309,7 +309,23 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide
return VideoPlaylistElementModel.increment({ position: by }, query) return VideoPlaylistElementModel.increment({ position: by }, query)
} }
getType (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) { toFormattedJSON (
this: MVideoPlaylistElementFormattable,
options: { accountId?: number } = {}
): VideoPlaylistElement {
return {
id: this.id,
position: this.position,
startTimestamp: this.startTimestamp,
stopTimestamp: this.stopTimestamp,
type: this.getType(options.accountId),
video: this.getVideoElement(options.accountId)
}
}
getType (this: MVideoPlaylistElementFormattable, accountId?: number) {
const video = this.Video const video = this.Video
if (!video) return VideoPlaylistElementType.DELETED if (!video) return VideoPlaylistElementType.DELETED
@ -323,34 +339,17 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide
if (video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL) return VideoPlaylistElementType.PRIVATE if (video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL) return VideoPlaylistElementType.PRIVATE
if (video.isBlacklisted() || video.isBlocked()) return VideoPlaylistElementType.UNAVAILABLE if (video.isBlacklisted() || video.isBlocked()) return VideoPlaylistElementType.UNAVAILABLE
if (video.nsfw === true && displayNSFW === false) return VideoPlaylistElementType.UNAVAILABLE
return VideoPlaylistElementType.REGULAR return VideoPlaylistElementType.REGULAR
} }
getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) { getVideoElement (this: MVideoPlaylistElementFormattable, accountId?: number) {
if (!this.Video) return null if (!this.Video) return null
if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null if (this.getType(accountId) !== VideoPlaylistElementType.REGULAR) return null
return this.Video.toFormattedJSON() return this.Video.toFormattedJSON()
} }
toFormattedJSON (
this: MVideoPlaylistElementFormattable,
options: { displayNSFW?: boolean, accountId?: number } = {}
): VideoPlaylistElement {
return {
id: this.id,
position: this.position,
startTimestamp: this.startTimestamp,
stopTimestamp: this.stopTimestamp,
type: this.getType(options.displayNSFW, options.accountId),
video: this.getVideoElement(options.displayNSFW, options.accountId)
}
}
toActivityPubObject (this: MVideoPlaylistElementAP): PlaylistElementObject { toActivityPubObject (this: MVideoPlaylistElementAP): PlaylistElementObject {
const base: PlaylistElementObject = { const base: PlaylistElementObject = {
id: this.url, id: this.url,

View File

@ -3,6 +3,7 @@
import { expect } from 'chai' import { expect } from 'chai'
import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared' import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared'
import { wait } from '@shared/core-utils' import { wait } from '@shared/core-utils'
import { uuidToShort } from '@shared/extra-utils'
import { import {
HttpStatusCode, HttpStatusCode,
VideoPlaylist, VideoPlaylist,
@ -23,7 +24,6 @@ import {
setDefaultVideoChannel, setDefaultVideoChannel,
waitJobs waitJobs
} from '@shared/server-commands' } from '@shared/server-commands'
import { uuidToShort } from '@shared/extra-utils'
async function checkPlaylistElementType ( async function checkPlaylistElementType (
servers: PeerTubeServer[], servers: PeerTubeServer[],
@ -752,19 +752,6 @@ describe('Test video playlists', function () {
await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
} }
}) })
it('Should hide the video if it is NSFW', async function () {
const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } })
expect(body.total).to.equal(3)
const elements = body.data
const element = elements.find(e => e.position === 3)
expect(element).to.exist
expect(element.video).to.be.null
expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE)
})
}) })
describe('Managing playlist elements', function () { describe('Managing playlist elements', function () {