diff options
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 17 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 1 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 35 |
4 files changed, 39 insertions, 16 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index fe0a95cd5..32f9c4793 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -3,7 +3,6 @@ import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared | |||
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { getFormattedObjects } from '../../../helpers/utils' | 4 | import { getFormattedObjects } from '../../../helpers/utils' |
5 | import { sequelizeTypescript } from '../../../initializers' | 5 | import { sequelizeTypescript } from '../../../initializers' |
6 | import { sendVideoAbuse } from '../../../lib/activitypub/send' | ||
7 | import { | 6 | import { |
8 | asyncMiddleware, | 7 | asyncMiddleware, |
9 | asyncRetryTransactionMiddleware, | 8 | asyncRetryTransactionMiddleware, |
@@ -23,6 +22,7 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse' | |||
23 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' | 22 | import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger' |
24 | import { UserModel } from '../../../models/account/user' | 23 | import { UserModel } from '../../../models/account/user' |
25 | import { Notifier } from '../../../lib/notifier' | 24 | import { Notifier } from '../../../lib/notifier' |
25 | import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag' | ||
26 | 26 | ||
27 | const auditLogger = auditLoggerFactory('abuse') | 27 | const auditLogger = auditLoggerFactory('abuse') |
28 | const abuseVideoRouter = express.Router() | 28 | const abuseVideoRouter = express.Router() |
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 9ef08812b..43b0516e7 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -18,6 +18,8 @@ import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | |||
18 | import { sequelizeTypescript } from '../../../initializers' | 18 | import { sequelizeTypescript } from '../../../initializers' |
19 | import { Notifier } from '../../../lib/notifier' | 19 | import { Notifier } from '../../../lib/notifier' |
20 | import { VideoModel } from '../../../models/video/video' | 20 | import { VideoModel } from '../../../models/video/video' |
21 | import { sendCreateVideo, sendDeleteVideo, sendUpdateVideo } from '../../../lib/activitypub/send' | ||
22 | import { federateVideoIfNeeded } from '../../../lib/activitypub' | ||
21 | 23 | ||
22 | const blacklistRouter = express.Router() | 24 | const blacklistRouter = express.Router() |
23 | 25 | ||
@@ -66,12 +68,17 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response) | |||
66 | 68 | ||
67 | const toCreate = { | 69 | const toCreate = { |
68 | videoId: videoInstance.id, | 70 | videoId: videoInstance.id, |
71 | unfederated: body.unfederate === true, | ||
69 | reason: body.reason | 72 | reason: body.reason |
70 | } | 73 | } |
71 | 74 | ||
72 | const blacklist = await VideoBlacklistModel.create(toCreate) | 75 | const blacklist = await VideoBlacklistModel.create(toCreate) |
73 | blacklist.Video = videoInstance | 76 | blacklist.Video = videoInstance |
74 | 77 | ||
78 | if (body.unfederate === true) { | ||
79 | await sendDeleteVideo(videoInstance, undefined) | ||
80 | } | ||
81 | |||
75 | Notifier.Instance.notifyOnVideoBlacklist(blacklist) | 82 | Notifier.Instance.notifyOnVideoBlacklist(blacklist) |
76 | 83 | ||
77 | logger.info('Video %s blacklisted.', res.locals.video.uuid) | 84 | logger.info('Video %s blacklisted.', res.locals.video.uuid) |
@@ -101,8 +108,14 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex | |||
101 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel | 108 | const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel |
102 | const video: VideoModel = res.locals.video | 109 | const video: VideoModel = res.locals.video |
103 | 110 | ||
104 | await sequelizeTypescript.transaction(t => { | 111 | await sequelizeTypescript.transaction(async t => { |
105 | return videoBlacklist.destroy({ transaction: t }) | 112 | const unfederated = videoBlacklist.unfederated |
113 | await videoBlacklist.destroy({ transaction: t }) | ||
114 | |||
115 | // Re federate the video | ||
116 | if (unfederated === true) { | ||
117 | await federateVideoIfNeeded(video, true, t) | ||
118 | } | ||
106 | }) | 119 | }) |
107 | 120 | ||
108 | Notifier.Instance.notifyOnVideoUnblacklist(video) | 121 | Notifier.Instance.notifyOnVideoUnblacklist(video) |
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 98366cd82..7053d5253 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -164,6 +164,7 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You | |||
164 | licence: body.licence || importData.licence, | 164 | licence: body.licence || importData.licence, |
165 | language: body.language || undefined, | 165 | language: body.language || undefined, |
166 | commentsEnabled: body.commentsEnabled || true, | 166 | commentsEnabled: body.commentsEnabled || true, |
167 | downloadEnabled: body.downloadEnabled || true, | ||
167 | waitTranscoding: body.waitTranscoding || false, | 168 | waitTranscoding: body.waitTranscoding || false, |
168 | state: VideoState.TO_IMPORT, | 169 | state: VideoState.TO_IMPORT, |
169 | nsfw: body.nsfw || importData.nsfw || false, | 170 | nsfw: body.nsfw || importData.nsfw || false, |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index b26dcabe1..6ac13e6a4 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -23,7 +23,6 @@ import { | |||
23 | fetchRemoteVideoDescription, | 23 | fetchRemoteVideoDescription, |
24 | getVideoActivityPubUrl | 24 | getVideoActivityPubUrl |
25 | } from '../../../lib/activitypub' | 25 | } from '../../../lib/activitypub' |
26 | import { sendCreateView } from '../../../lib/activitypub/send' | ||
27 | import { JobQueue } from '../../../lib/job-queue' | 26 | import { JobQueue } from '../../../lib/job-queue' |
28 | import { Redis } from '../../../lib/redis' | 27 | import { Redis } from '../../../lib/redis' |
29 | import { | 28 | import { |
@@ -37,6 +36,7 @@ import { | |||
37 | setDefaultPagination, | 36 | setDefaultPagination, |
38 | setDefaultSort, | 37 | setDefaultSort, |
39 | videosAddValidator, | 38 | videosAddValidator, |
39 | videosCustomGetValidator, | ||
40 | videosGetValidator, | 40 | videosGetValidator, |
41 | videosRemoveValidator, | 41 | videosRemoveValidator, |
42 | videosSortValidator, | 42 | videosSortValidator, |
@@ -59,6 +59,7 @@ import { resetSequelizeInstance } from '../../../helpers/database-utils' | |||
59 | import { move } from 'fs-extra' | 59 | import { move } from 'fs-extra' |
60 | import { watchingRouter } from './watching' | 60 | import { watchingRouter } from './watching' |
61 | import { Notifier } from '../../../lib/notifier' | 61 | import { Notifier } from '../../../lib/notifier' |
62 | import { sendView } from '../../../lib/activitypub/send/send-view' | ||
62 | 63 | ||
63 | const auditLogger = auditLoggerFactory('videos') | 64 | const auditLogger = auditLoggerFactory('videos') |
64 | const videosRouter = express.Router() | 65 | const videosRouter = express.Router() |
@@ -123,9 +124,9 @@ videosRouter.get('/:id/description', | |||
123 | ) | 124 | ) |
124 | videosRouter.get('/:id', | 125 | videosRouter.get('/:id', |
125 | optionalAuthenticate, | 126 | optionalAuthenticate, |
126 | asyncMiddleware(videosGetValidator), | 127 | asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), |
127 | asyncMiddleware(checkVideoFollowConstraints), | 128 | asyncMiddleware(checkVideoFollowConstraints), |
128 | getVideo | 129 | asyncMiddleware(getVideo) |
129 | ) | 130 | ) |
130 | videosRouter.post('/:id/views', | 131 | videosRouter.post('/:id/views', |
131 | asyncMiddleware(videosGetValidator), | 132 | asyncMiddleware(videosGetValidator), |
@@ -181,6 +182,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
181 | licence: videoInfo.licence, | 182 | licence: videoInfo.licence, |
182 | language: videoInfo.language, | 183 | language: videoInfo.language, |
183 | commentsEnabled: videoInfo.commentsEnabled || false, | 184 | commentsEnabled: videoInfo.commentsEnabled || false, |
185 | downloadEnabled: videoInfo.downloadEnabled || true, | ||
184 | waitTranscoding: videoInfo.waitTranscoding || false, | 186 | waitTranscoding: videoInfo.waitTranscoding || false, |
185 | state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED, | 187 | state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED, |
186 | nsfw: videoInfo.nsfw || false, | 188 | nsfw: videoInfo.nsfw || false, |
@@ -326,8 +328,9 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
326 | if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) | 328 | if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) |
327 | if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) | 329 | if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) |
328 | if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) | 330 | if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) |
329 | if (videoInfoToUpdate.originallyPublishedAt !== undefined && | 331 | if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled) |
330 | videoInfoToUpdate.originallyPublishedAt !== null) { | 332 | |
333 | if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) { | ||
331 | videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt) | 334 | videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt) |
332 | } | 335 | } |
333 | 336 | ||
@@ -370,7 +373,11 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
370 | } | 373 | } |
371 | 374 | ||
372 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE | 375 | const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE |
373 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | 376 | |
377 | // Don't send update if the video was unfederated | ||
378 | if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) { | ||
379 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | ||
380 | } | ||
374 | 381 | ||
375 | auditLogger.update( | 382 | auditLogger.update( |
376 | getAuditIdFromRes(res), | 383 | getAuditIdFromRes(res), |
@@ -397,15 +404,17 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
397 | return res.type('json').status(204).end() | 404 | return res.type('json').status(204).end() |
398 | } | 405 | } |
399 | 406 | ||
400 | function getVideo (req: express.Request, res: express.Response) { | 407 | async function getVideo (req: express.Request, res: express.Response) { |
401 | const videoInstance = res.locals.video | 408 | // We need more attributes |
409 | const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null | ||
410 | const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id, undefined, userId) | ||
402 | 411 | ||
403 | if (videoInstance.isOutdated()) { | 412 | if (video.isOutdated()) { |
404 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoInstance.url } }) | 413 | JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) |
405 | .catch(err => logger.error('Cannot create AP refresher job for video %s.', videoInstance.url, { err })) | 414 | .catch(err => logger.error('Cannot create AP refresher job for video %s.', video.url, { err })) |
406 | } | 415 | } |
407 | 416 | ||
408 | return res.json(videoInstance.toFormattedDetailsJSON()) | 417 | return res.json(video.toFormattedDetailsJSON()) |
409 | } | 418 | } |
410 | 419 | ||
411 | async function viewVideo (req: express.Request, res: express.Response) { | 420 | async function viewVideo (req: express.Request, res: express.Response) { |
@@ -424,7 +433,7 @@ async function viewVideo (req: express.Request, res: express.Response) { | |||
424 | ]) | 433 | ]) |
425 | 434 | ||
426 | const serverActor = await getServerActor() | 435 | const serverActor = await getServerActor() |
427 | await sendCreateView(serverActor, videoInstance, undefined) | 436 | await sendView(serverActor, videoInstance, undefined) |
428 | 437 | ||
429 | return res.status(204).end() | 438 | return res.status(204).end() |
430 | } | 439 | } |