diff options
author | Chocobozzz <me@florianbigard.com> | 2018-04-19 11:01:34 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-04-19 11:01:34 +0200 |
commit | 0883b3245bf0deb9106c4041e9afbd3521b79280 (patch) | |
tree | fcb73005e0b31a3b763ee5d22d5fc39c2da89907 /server/controllers/api/videos/index.ts | |
parent | 04ed10b21e8e1339514faae0bb690e4d97c23b0a (diff) | |
download | PeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.tar.gz PeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.tar.zst PeerTube-0883b3245bf0deb9106c4041e9afbd3521b79280.zip |
Add ability to choose what policy we have for NSFW videos
There is a global instance setting and a per user setting
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index b4cd67158..6e8601fa1 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -19,13 +19,18 @@ import { | |||
19 | VIDEO_MIMETYPE_EXT, | 19 | VIDEO_MIMETYPE_EXT, |
20 | VIDEO_PRIVACIES | 20 | VIDEO_PRIVACIES |
21 | } from '../../../initializers' | 21 | } from '../../../initializers' |
22 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' | 22 | import { |
23 | fetchRemoteVideoDescription, | ||
24 | getVideoActivityPubUrl, | ||
25 | shareVideoByServerAndChannel | ||
26 | } from '../../../lib/activitypub' | ||
23 | import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send' | 27 | import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send' |
24 | import { JobQueue } from '../../../lib/job-queue' | 28 | import { JobQueue } from '../../../lib/job-queue' |
25 | import { Redis } from '../../../lib/redis' | 29 | import { Redis } from '../../../lib/redis' |
26 | import { | 30 | import { |
27 | asyncMiddleware, | 31 | asyncMiddleware, |
28 | authenticate, | 32 | authenticate, |
33 | optionalAuthenticate, | ||
29 | paginationValidator, | 34 | paginationValidator, |
30 | setDefaultPagination, | 35 | setDefaultPagination, |
31 | setDefaultSort, | 36 | setDefaultSort, |
@@ -44,6 +49,9 @@ import { blacklistRouter } from './blacklist' | |||
44 | import { videoChannelRouter } from './channel' | 49 | import { videoChannelRouter } from './channel' |
45 | import { videoCommentRouter } from './comment' | 50 | import { videoCommentRouter } from './comment' |
46 | import { rateVideoRouter } from './rate' | 51 | import { rateVideoRouter } from './rate' |
52 | import { User } from '../../../../shared/models/users' | ||
53 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | ||
54 | import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type' | ||
47 | 55 | ||
48 | const videosRouter = express.Router() | 56 | const videosRouter = express.Router() |
49 | 57 | ||
@@ -81,6 +89,7 @@ videosRouter.get('/', | |||
81 | videosSortValidator, | 89 | videosSortValidator, |
82 | setDefaultSort, | 90 | setDefaultSort, |
83 | setDefaultPagination, | 91 | setDefaultPagination, |
92 | optionalAuthenticate, | ||
84 | asyncMiddleware(listVideos) | 93 | asyncMiddleware(listVideos) |
85 | ) | 94 | ) |
86 | videosRouter.get('/search', | 95 | videosRouter.get('/search', |
@@ -89,6 +98,7 @@ videosRouter.get('/search', | |||
89 | videosSortValidator, | 98 | videosSortValidator, |
90 | setDefaultSort, | 99 | setDefaultSort, |
91 | setDefaultPagination, | 100 | setDefaultPagination, |
101 | optionalAuthenticate, | ||
92 | asyncMiddleware(searchVideos) | 102 | asyncMiddleware(searchVideos) |
93 | ) | 103 | ) |
94 | videosRouter.put('/:id', | 104 | videosRouter.put('/:id', |
@@ -391,7 +401,13 @@ async function getVideoDescription (req: express.Request, res: express.Response) | |||
391 | } | 401 | } |
392 | 402 | ||
393 | async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 403 | async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
394 | const resultList = await VideoModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.filter) | 404 | const resultList = await VideoModel.listForApi( |
405 | req.query.start as number, | ||
406 | req.query.count as number, | ||
407 | req.query.sort as VideoSortField, | ||
408 | isNSFWHidden(res), | ||
409 | req.query.filter as VideoFilter | ||
410 | ) | ||
395 | 411 | ||
396 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 412 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
397 | } | 413 | } |
@@ -419,11 +435,21 @@ async function removeVideo (req: express.Request, res: express.Response) { | |||
419 | 435 | ||
420 | async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 436 | async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
421 | const resultList = await VideoModel.searchAndPopulateAccountAndServer( | 437 | const resultList = await VideoModel.searchAndPopulateAccountAndServer( |
422 | req.query.search, | 438 | req.query.search as string, |
423 | req.query.start, | 439 | req.query.start as number, |
424 | req.query.count, | 440 | req.query.count as number, |
425 | req.query.sort | 441 | req.query.sort as VideoSortField, |
442 | isNSFWHidden(res) | ||
426 | ) | 443 | ) |
427 | 444 | ||
428 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 445 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
429 | } | 446 | } |
447 | |||
448 | function isNSFWHidden (res: express.Response) { | ||
449 | if (res.locals.oauth) { | ||
450 | const user: User = res.locals.oauth.token.User | ||
451 | if (user) return user.nsfwPolicy === 'do_not_list' | ||
452 | } | ||
453 | |||
454 | return CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list' | ||
455 | } | ||