diff options
Diffstat (limited to 'server/controllers/api/videos/channel.ts')
-rw-r--r-- | server/controllers/api/videos/channel.ts | 28 |
1 files changed, 16 insertions, 12 deletions
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) { |