aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-01-19 15:04:10 +0100
committerChocobozzz <me@florianbigard.com>2023-01-19 15:04:10 +0100
commita68ccaead667f1b976e0fb10c8b1087af25547f2 (patch)
treeb23ef1915c1b8bdb6b88c10d0dee5749fa874133
parent789ba349318e7ff012590491e76087a1204cccd4 (diff)
downloadPeerTube-a68ccaead667f1b976e0fb10c8b1087af25547f2.tar.gz
PeerTube-a68ccaead667f1b976e0fb10c8b1087af25547f2.tar.zst
PeerTube-a68ccaead667f1b976e0fb10c8b1087af25547f2.zip
(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"
-rw-r--r--server/controllers/api/video-playlist.ts7
-rw-r--r--server/models/video/video-playlist-element.ts39
-rw-r--r--server/tests/api/videos/video-playlists.ts15
3 files changed, 22 insertions, 39 deletions
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index f8a607170..947f7ca77 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
15import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model' 15import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model'
16import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model' 16import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
17import { resetSequelizeInstance } from '../../helpers/database-utils' 17import { resetSequelizeInstance } from '../../helpers/database-utils'
18import { buildNSFWFilter, createReqFiles } from '../../helpers/express-utils' 18import { createReqFiles } from '../../helpers/express-utils'
19import { logger } from '../../helpers/logger' 19import { logger } from '../../helpers/logger'
20import { getFormattedObjects } from '../../helpers/utils' 20import { getFormattedObjects } from '../../helpers/utils'
21import { CONFIG } from '../../initializers/config' 21import { CONFIG } from '../../initializers/config'
@@ -474,10 +474,7 @@ async function getVideoPlaylistVideos (req: express.Request, res: express.Respon
474 'filter:api.video-playlist.videos.list.result' 474 'filter:api.video-playlist.videos.list.result'
475 ) 475 )
476 476
477 const options = { 477 const options = { accountId: user?.Account?.id }
478 displayNSFW: buildNSFWFilter(res, req.query.nsfw),
479 accountId: user ? user.Account.id : undefined
480 }
481 return res.json(getFormattedObjects(resultList.data, resultList.total, options)) 478 return res.json(getFormattedObjects(resultList.data, resultList.total, options))
482} 479}
483 480
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts
index 48f4ed5a9..b832f9768 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
309 return VideoPlaylistElementModel.increment({ position: by }, query) 309 return VideoPlaylistElementModel.increment({ position: by }, query)
310 } 310 }
311 311
312 getType (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) { 312 toFormattedJSON (
313 this: MVideoPlaylistElementFormattable,
314 options: { accountId?: number } = {}
315 ): VideoPlaylistElement {
316 return {
317 id: this.id,
318 position: this.position,
319 startTimestamp: this.startTimestamp,
320 stopTimestamp: this.stopTimestamp,
321
322 type: this.getType(options.accountId),
323
324 video: this.getVideoElement(options.accountId)
325 }
326 }
327
328 getType (this: MVideoPlaylistElementFormattable, accountId?: number) {
313 const video = this.Video 329 const video = this.Video
314 330
315 if (!video) return VideoPlaylistElementType.DELETED 331 if (!video) return VideoPlaylistElementType.DELETED
@@ -323,34 +339,17 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide
323 if (video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL) return VideoPlaylistElementType.PRIVATE 339 if (video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL) return VideoPlaylistElementType.PRIVATE
324 340
325 if (video.isBlacklisted() || video.isBlocked()) return VideoPlaylistElementType.UNAVAILABLE 341 if (video.isBlacklisted() || video.isBlocked()) return VideoPlaylistElementType.UNAVAILABLE
326 if (video.nsfw === true && displayNSFW === false) return VideoPlaylistElementType.UNAVAILABLE
327 342
328 return VideoPlaylistElementType.REGULAR 343 return VideoPlaylistElementType.REGULAR
329 } 344 }
330 345
331 getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) { 346 getVideoElement (this: MVideoPlaylistElementFormattable, accountId?: number) {
332 if (!this.Video) return null 347 if (!this.Video) return null
333 if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null 348 if (this.getType(accountId) !== VideoPlaylistElementType.REGULAR) return null
334 349
335 return this.Video.toFormattedJSON() 350 return this.Video.toFormattedJSON()
336 } 351 }
337 352
338 toFormattedJSON (
339 this: MVideoPlaylistElementFormattable,
340 options: { displayNSFW?: boolean, accountId?: number } = {}
341 ): VideoPlaylistElement {
342 return {
343 id: this.id,
344 position: this.position,
345 startTimestamp: this.startTimestamp,
346 stopTimestamp: this.stopTimestamp,
347
348 type: this.getType(options.displayNSFW, options.accountId),
349
350 video: this.getVideoElement(options.displayNSFW, options.accountId)
351 }
352 }
353
354 toActivityPubObject (this: MVideoPlaylistElementAP): PlaylistElementObject { 353 toActivityPubObject (this: MVideoPlaylistElementAP): PlaylistElementObject {
355 const base: PlaylistElementObject = { 354 const base: PlaylistElementObject = {
356 id: this.url, 355 id: this.url,
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index 6a18cf26a..e8e653382 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -3,6 +3,7 @@
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared' 4import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared'
5import { wait } from '@shared/core-utils' 5import { wait } from '@shared/core-utils'
6import { uuidToShort } from '@shared/extra-utils'
6import { 7import {
7 HttpStatusCode, 8 HttpStatusCode,
8 VideoPlaylist, 9 VideoPlaylist,
@@ -23,7 +24,6 @@ import {
23 setDefaultVideoChannel, 24 setDefaultVideoChannel,
24 waitJobs 25 waitJobs
25} from '@shared/server-commands' 26} from '@shared/server-commands'
26import { uuidToShort } from '@shared/extra-utils'
27 27
28async function checkPlaylistElementType ( 28async function checkPlaylistElementType (
29 servers: PeerTubeServer[], 29 servers: PeerTubeServer[],
@@ -752,19 +752,6 @@ describe('Test video playlists', function () {
752 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) 752 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
753 } 753 }
754 }) 754 })
755
756 it('Should hide the video if it is NSFW', async function () {
757 const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } })
758 expect(body.total).to.equal(3)
759
760 const elements = body.data
761 const element = elements.find(e => e.position === 3)
762
763 expect(element).to.exist
764 expect(element.video).to.be.null
765 expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE)
766 })
767
768 }) 755 })
769 756
770 describe('Managing playlist elements', function () { 757 describe('Managing playlist elements', function () {