Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

(breaking): Always list nsfw videos in playlists

Chocobozzza68ccaead667
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index f8a6071700..947f7ca778 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -15,7 +15,7 @@ import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/vid
import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model'
import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
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 { getFormattedObjects } from '../../helpers/utils'
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'
)
- const options = {
- displayNSFW: buildNSFWFilter(res, req.query.nsfw),
- accountId: user ? user.Account.id : undefined
- }
+ const options = { accountId: user?.Account?.id }
return res.json(getFormattedObjects(resultList.data, resultList.total, options))
}
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts
index 48f4ed5a9c..b832f9768c 100644
--- a/server/models/video/video-playlist-element.ts
+++ b/server/models/video/video-playlist-element.ts
@@ -309,7 +309,23 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide
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
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.isBlacklisted() || video.isBlocked()) return VideoPlaylistElementType.UNAVAILABLE
- if (video.nsfw === true && displayNSFW === false) return VideoPlaylistElementType.UNAVAILABLE
return VideoPlaylistElementType.REGULAR
}
- getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
+ getVideoElement (this: MVideoPlaylistElementFormattable, accountId?: number) {
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()
}
- 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 {
const base: PlaylistElementObject = {
id: this.url,
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index 6a18cf26a1..e8e6533827 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -3,6 +3,7 @@
import { expect } from 'chai'
import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared'
import { wait } from '@shared/core-utils'
+import { uuidToShort } from '@shared/extra-utils'
import {
HttpStatusCode,
VideoPlaylist,
@@ -23,7 +24,6 @@ import {
setDefaultVideoChannel,
waitJobs
} from '@shared/server-commands'
-import { uuidToShort } from '@shared/extra-utils'
async function checkPlaylistElementType (
servers: PeerTubeServer[],
@@ -752,19 +752,6 @@ describe('Test video playlists', function () {
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 () {