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 | |
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')
-rw-r--r-- | server/controllers/api/config.ts | 3 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 15 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 38 | ||||
-rw-r--r-- | server/controllers/feeds.ts | 9 |
4 files changed, 52 insertions, 13 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 88f047adc..e47b71f44 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -46,6 +46,7 @@ async function getConfig (req: express.Request, res: express.Response, next: exp | |||
46 | name: CONFIG.INSTANCE.NAME, | 46 | name: CONFIG.INSTANCE.NAME, |
47 | shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, | 47 | shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, |
48 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, | 48 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, |
49 | defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | ||
49 | customizations: { | 50 | customizations: { |
50 | javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, | 51 | javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, |
51 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS | 52 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS |
@@ -128,6 +129,7 @@ async function updateCustomConfig (req: express.Request, res: express.Response, | |||
128 | toUpdateJSON.user['video_quota'] = toUpdate.user.videoQuota | 129 | toUpdateJSON.user['video_quota'] = toUpdate.user.videoQuota |
129 | toUpdateJSON.instance['default_client_route'] = toUpdate.instance.defaultClientRoute | 130 | toUpdateJSON.instance['default_client_route'] = toUpdate.instance.defaultClientRoute |
130 | toUpdateJSON.instance['short_description'] = toUpdate.instance.shortDescription | 131 | toUpdateJSON.instance['short_description'] = toUpdate.instance.shortDescription |
132 | toUpdateJSON.instance['default_nsfw_policy'] = toUpdate.instance.defaultNSFWPolicy | ||
131 | 133 | ||
132 | await writeFilePromise(CONFIG.CUSTOM_FILE, JSON.stringify(toUpdateJSON, undefined, 2)) | 134 | await writeFilePromise(CONFIG.CUSTOM_FILE, JSON.stringify(toUpdateJSON, undefined, 2)) |
133 | 135 | ||
@@ -153,6 +155,7 @@ function customConfig (): CustomConfig { | |||
153 | description: CONFIG.INSTANCE.DESCRIPTION, | 155 | description: CONFIG.INSTANCE.DESCRIPTION, |
154 | terms: CONFIG.INSTANCE.TERMS, | 156 | terms: CONFIG.INSTANCE.TERMS, |
155 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, | 157 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, |
158 | defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | ||
156 | customizations: { | 159 | customizations: { |
157 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS, | 160 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS, |
158 | javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT | 161 | javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT |
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 56cbf9448..6540adb1c 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -42,6 +42,7 @@ import { AccountVideoRateModel } from '../../models/account/account-video-rate' | |||
42 | import { UserModel } from '../../models/account/user' | 42 | import { UserModel } from '../../models/account/user' |
43 | import { OAuthTokenModel } from '../../models/oauth/oauth-token' | 43 | import { OAuthTokenModel } from '../../models/oauth/oauth-token' |
44 | import { VideoModel } from '../../models/video/video' | 44 | import { VideoModel } from '../../models/video/video' |
45 | import { VideoSortField } from '../../../client/src/app/shared/video/sort-field.type' | ||
45 | 46 | ||
46 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) | 47 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) |
47 | const loginRateLimiter = new RateLimit({ | 48 | const loginRateLimiter = new RateLimit({ |
@@ -161,7 +162,13 @@ export { | |||
161 | 162 | ||
162 | async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 163 | async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
163 | const user = res.locals.oauth.token.User as UserModel | 164 | const user = res.locals.oauth.token.User as UserModel |
164 | const resultList = await VideoModel.listAccountVideosForApi(user.Account.id ,req.query.start, req.query.count, req.query.sort) | 165 | const resultList = await VideoModel.listAccountVideosForApi( |
166 | user.Account.id, | ||
167 | req.query.start as number, | ||
168 | req.query.count as number, | ||
169 | req.query.sort as VideoSortField, | ||
170 | false // Display my NSFW videos | ||
171 | ) | ||
165 | 172 | ||
166 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 173 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
167 | } | 174 | } |
@@ -188,7 +195,7 @@ async function createUser (req: express.Request) { | |||
188 | username: body.username, | 195 | username: body.username, |
189 | password: body.password, | 196 | password: body.password, |
190 | email: body.email, | 197 | email: body.email, |
191 | displayNSFW: false, | 198 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
192 | autoPlayVideo: true, | 199 | autoPlayVideo: true, |
193 | role: body.role, | 200 | role: body.role, |
194 | videoQuota: body.videoQuota | 201 | videoQuota: body.videoQuota |
@@ -219,7 +226,7 @@ async function registerUser (req: express.Request) { | |||
219 | username: body.username, | 226 | username: body.username, |
220 | password: body.password, | 227 | password: body.password, |
221 | email: body.email, | 228 | email: body.email, |
222 | displayNSFW: false, | 229 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
223 | autoPlayVideo: true, | 230 | autoPlayVideo: true, |
224 | role: UserRole.USER, | 231 | role: UserRole.USER, |
225 | videoQuota: CONFIG.USER.VIDEO_QUOTA | 232 | videoQuota: CONFIG.USER.VIDEO_QUOTA |
@@ -286,7 +293,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
286 | 293 | ||
287 | if (body.password !== undefined) user.password = body.password | 294 | if (body.password !== undefined) user.password = body.password |
288 | if (body.email !== undefined) user.email = body.email | 295 | if (body.email !== undefined) user.email = body.email |
289 | if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW | 296 | if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy |
290 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo | 297 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo |
291 | 298 | ||
292 | await sequelizeTypescript.transaction(async t => { | 299 | await sequelizeTypescript.transaction(async t => { |
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 | } | ||
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index 3e384c48a..27ebecc40 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts | |||
@@ -6,6 +6,7 @@ import * as Feed from 'pfeed' | |||
6 | import { ResultList } from '../../shared/models' | 6 | import { ResultList } from '../../shared/models' |
7 | import { AccountModel } from '../models/account/account' | 7 | import { AccountModel } from '../models/account/account' |
8 | import { cacheRoute } from '../middlewares/cache' | 8 | import { cacheRoute } from '../middlewares/cache' |
9 | import { VideoSortField } from '../../client/src/app/shared/video/sort-field.type' | ||
9 | 10 | ||
10 | const feedsRouter = express.Router() | 11 | const feedsRouter = express.Router() |
11 | 12 | ||
@@ -31,20 +32,22 @@ async function generateFeed (req: express.Request, res: express.Response, next: | |||
31 | 32 | ||
32 | let resultList: ResultList<VideoModel> | 33 | let resultList: ResultList<VideoModel> |
33 | const account: AccountModel = res.locals.account | 34 | const account: AccountModel = res.locals.account |
35 | const hideNSFW = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list' | ||
34 | 36 | ||
35 | if (account) { | 37 | if (account) { |
36 | resultList = await VideoModel.listAccountVideosForApi( | 38 | resultList = await VideoModel.listAccountVideosForApi( |
37 | account.id, | 39 | account.id, |
38 | start, | 40 | start, |
39 | FEEDS.COUNT, | 41 | FEEDS.COUNT, |
40 | req.query.sort, | 42 | req.query.sort as VideoSortField, |
41 | true | 43 | hideNSFW |
42 | ) | 44 | ) |
43 | } else { | 45 | } else { |
44 | resultList = await VideoModel.listForApi( | 46 | resultList = await VideoModel.listForApi( |
45 | start, | 47 | start, |
46 | FEEDS.COUNT, | 48 | FEEDS.COUNT, |
47 | req.query.sort, | 49 | req.query.sort as VideoSortField, |
50 | hideNSFW, | ||
48 | req.query.filter, | 51 | req.query.filter, |
49 | true | 52 | true |
50 | ) | 53 | ) |