diff options
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 20 | ||||
-rw-r--r-- | server/controllers/api/videos/channel.ts | 28 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 13 |
3 files changed, 31 insertions, 30 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 08cc4d0b4..fecdaf5a3 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -1,22 +1,18 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { | 2 | import { UserRight, VideoAbuseCreate } from '../../../../shared' |
3 | logger, | 3 | import { getFormattedObjects, logger, retryTransactionWrapper } from '../../../helpers' |
4 | getFormattedObjects, | ||
5 | retryTransactionWrapper | ||
6 | } from '../../../helpers' | ||
7 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { sendVideoAbuse } from '../../../lib/activitypub/send' | ||
8 | import { | 6 | import { |
7 | asyncMiddleware, | ||
9 | authenticate, | 8 | authenticate, |
10 | ensureUserHasRight, | 9 | ensureUserHasRight, |
11 | paginationValidator, | 10 | paginationValidator, |
12 | videoAbuseReportValidator, | ||
13 | videoAbusesSortValidator, | ||
14 | setVideoAbusesSort, | ||
15 | setPagination, | 11 | setPagination, |
16 | asyncMiddleware | 12 | setVideoAbusesSort, |
13 | videoAbuseReportValidator, | ||
14 | videoAbusesSortValidator | ||
17 | } from '../../../middlewares' | 15 | } from '../../../middlewares' |
18 | import { VideoAbuseCreate, UserRight } from '../../../../shared' | ||
19 | import { sendVideoAbuse } from '../../../lib/index' | ||
20 | import { AccountModel } from '../../../models/account/account' | 16 | import { AccountModel } from '../../../models/account/account' |
21 | import { VideoModel } from '../../../models/video/video' | 17 | import { VideoModel } from '../../../models/video/video' |
22 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 18 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
@@ -80,7 +76,7 @@ async function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
80 | 76 | ||
81 | // We send the video abuse to the origin server | 77 | // We send the video abuse to the origin server |
82 | if (videoInstance.isOwned() === false) { | 78 | if (videoInstance.isOwned() === false) { |
83 | await sendVideoAbuse(reporterAccount, videoAbuseInstance, videoInstance, t) | 79 | await sendVideoAbuse(reporterAccount.Actor, videoAbuseInstance, videoInstance, t) |
84 | } | 80 | } |
85 | }) | 81 | }) |
86 | 82 | ||
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts index 315469115..cc00d9f8d 100644 --- a/server/controllers/api/videos/channel.ts +++ b/server/controllers/api/videos/channel.ts | |||
@@ -2,8 +2,8 @@ import * as express from 'express' | |||
2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' | 2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared' |
3 | import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' | 3 | import { getFormattedObjects, logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' |
4 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { createVideoChannel } from '../../../lib' | 5 | import { setAsyncActorKeys } from '../../../lib/activitypub' |
6 | import { sendUpdateVideoChannel } from '../../../lib/activitypub/send/send-update' | 6 | import { createVideoChannel } from '../../../lib/video-channel' |
7 | import { | 7 | import { |
8 | asyncMiddleware, | 8 | asyncMiddleware, |
9 | authenticate, | 9 | authenticate, |
@@ -92,15 +92,17 @@ async function addVideoChannelRetryWrapper (req: express.Request, res: express.R | |||
92 | return res.type('json').status(204).end() | 92 | return res.type('json').status(204).end() |
93 | } | 93 | } |
94 | 94 | ||
95 | function addVideoChannel (req: express.Request, res: express.Response) { | 95 | async function addVideoChannel (req: express.Request, res: express.Response) { |
96 | const videoChannelInfo: VideoChannelCreate = req.body | 96 | const videoChannelInfo: VideoChannelCreate = req.body |
97 | const account: AccountModel = res.locals.oauth.token.User.Account | 97 | const account: AccountModel = res.locals.oauth.token.User.Account |
98 | 98 | ||
99 | return sequelizeTypescript.transaction(async t => { | 99 | const videoChannelCreated = await sequelizeTypescript.transaction(async t => { |
100 | const videoChannelCreated = await createVideoChannel(videoChannelInfo, account, t) | 100 | return createVideoChannel(videoChannelInfo, account, t) |
101 | |||
102 | logger.info('Video channel with uuid %s created.', videoChannelCreated.uuid) | ||
103 | }) | 101 | }) |
102 | |||
103 | setAsyncActorKeys(videoChannelCreated.Actor) | ||
104 | |||
105 | logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) | ||
104 | } | 106 | } |
105 | 107 | ||
106 | async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { | 108 | async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
@@ -128,12 +130,13 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
128 | if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) | 130 | if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) |
129 | if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) | 131 | if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) |
130 | 132 | ||
131 | const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) | 133 | await videoChannelInstance.save(sequelizeOptions) |
132 | 134 | ||
133 | await sendUpdateVideoChannel(videoChannelInstanceUpdated, t) | 135 | // TODO |
136 | // await sendUpdateVideoChannel(videoChannelInstanceUpdated, t) | ||
134 | }) | 137 | }) |
135 | 138 | ||
136 | logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.uuid) | 139 | logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) |
137 | } catch (err) { | 140 | } catch (err) { |
138 | logger.debug('Cannot update the video channel.', err) | 141 | logger.debug('Cannot update the video channel.', err) |
139 | 142 | ||
@@ -160,11 +163,12 @@ async function removeVideoChannelRetryWrapper (req: express.Request, res: expres | |||
160 | async function removeVideoChannel (req: express.Request, res: express.Response) { | 163 | async function removeVideoChannel (req: express.Request, res: express.Response) { |
161 | const videoChannelInstance: VideoChannelModel = res.locals.videoChannel | 164 | const videoChannelInstance: VideoChannelModel = res.locals.videoChannel |
162 | 165 | ||
163 | await sequelizeTypescript.transaction(async t => { | 166 | return sequelizeTypescript.transaction(async t => { |
164 | await videoChannelInstance.destroy({ transaction: t }) | 167 | await videoChannelInstance.destroy({ transaction: t }) |
168 | |||
169 | logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) | ||
165 | }) | 170 | }) |
166 | 171 | ||
167 | logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.uuid) | ||
168 | } | 172 | } |
169 | 173 | ||
170 | async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { | 174 | async function getVideoChannel (req: express.Request, res: express.Response, next: express.NextFunction) { |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 91ab8c66a..d6934748f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -11,7 +11,7 @@ import { | |||
11 | resetSequelizeInstance, | 11 | resetSequelizeInstance, |
12 | retryTransactionWrapper | 12 | retryTransactionWrapper |
13 | } from '../../../helpers' | 13 | } from '../../../helpers' |
14 | import { getServerAccount } from '../../../helpers/utils' | 14 | import { getServerActor } from '../../../helpers/utils' |
15 | import { | 15 | import { |
16 | CONFIG, | 16 | CONFIG, |
17 | sequelizeTypescript, | 17 | sequelizeTypescript, |
@@ -22,8 +22,7 @@ import { | |||
22 | VIDEO_PRIVACIES | 22 | VIDEO_PRIVACIES |
23 | } from '../../../initializers' | 23 | } from '../../../initializers' |
24 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer } from '../../../lib/activitypub' | 24 | import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServer } from '../../../lib/activitypub' |
25 | import { sendAddVideo, sendCreateViewToOrigin, sendUpdateVideo } from '../../../lib/activitypub/send' | 25 | import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' |
26 | import { sendCreateViewToVideoFollowers } from '../../../lib/index' | ||
27 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' | 26 | import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' |
28 | import { | 27 | import { |
29 | asyncMiddleware, | 28 | asyncMiddleware, |
@@ -248,7 +247,8 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi | |||
248 | // Don't send video to remote servers, it is private | 247 | // Don't send video to remote servers, it is private |
249 | if (video.privacy === VideoPrivacy.PRIVATE) return videoCreated | 248 | if (video.privacy === VideoPrivacy.PRIVATE) return videoCreated |
250 | 249 | ||
251 | await sendAddVideo(video, t) | 250 | await sendCreateVideo(video, t) |
251 | // TODO: share by video channel | ||
252 | await shareVideoByServer(video, t) | 252 | await shareVideoByServer(video, t) |
253 | 253 | ||
254 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) | 254 | logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) |
@@ -304,7 +304,8 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
304 | 304 | ||
305 | // Video is not private anymore, send a create action to remote servers | 305 | // Video is not private anymore, send a create action to remote servers |
306 | if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) { | 306 | if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) { |
307 | await sendAddVideo(videoInstanceUpdated, t) | 307 | await sendCreateVideo(videoInstanceUpdated, t) |
308 | // TODO: Send by video channel | ||
308 | await shareVideoByServer(videoInstanceUpdated, t) | 309 | await shareVideoByServer(videoInstanceUpdated, t) |
309 | } | 310 | } |
310 | }) | 311 | }) |
@@ -330,7 +331,7 @@ async function viewVideo (req: express.Request, res: express.Response) { | |||
330 | const videoInstance = res.locals.video | 331 | const videoInstance = res.locals.video |
331 | 332 | ||
332 | await videoInstance.increment('views') | 333 | await videoInstance.increment('views') |
333 | const serverAccount = await getServerAccount() | 334 | const serverAccount = await getServerActor() |
334 | 335 | ||
335 | if (videoInstance.isOwned()) { | 336 | if (videoInstance.isOwned()) { |
336 | await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined) | 337 | await sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined) |