aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/index.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-19 11:01:34 +0200
committerChocobozzz <me@florianbigard.com>2018-04-19 11:01:34 +0200
commit0883b3245bf0deb9106c4041e9afbd3521b79280 (patch)
treefcb73005e0b31a3b763ee5d22d5fc39c2da89907 /server/controllers/api/videos/index.ts
parent04ed10b21e8e1339514faae0bb690e4d97c23b0a (diff)
downloadPeerTube-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.ts38
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'
22import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' 22import {
23 fetchRemoteVideoDescription,
24 getVideoActivityPubUrl,
25 shareVideoByServerAndChannel
26} from '../../../lib/activitypub'
23import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send' 27import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send'
24import { JobQueue } from '../../../lib/job-queue' 28import { JobQueue } from '../../../lib/job-queue'
25import { Redis } from '../../../lib/redis' 29import { Redis } from '../../../lib/redis'
26import { 30import {
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'
44import { videoChannelRouter } from './channel' 49import { videoChannelRouter } from './channel'
45import { videoCommentRouter } from './comment' 50import { videoCommentRouter } from './comment'
46import { rateVideoRouter } from './rate' 51import { rateVideoRouter } from './rate'
52import { User } from '../../../../shared/models/users'
53import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
54import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type'
47 55
48const videosRouter = express.Router() 56const 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)
86videosRouter.get('/search', 95videosRouter.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)
94videosRouter.put('/:id', 104videosRouter.put('/:id',
@@ -391,7 +401,13 @@ async function getVideoDescription (req: express.Request, res: express.Response)
391} 401}
392 402
393async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 403async 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
420async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 436async 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
448function 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}