diff options
Diffstat (limited to 'server/controllers/api/videos/channel.ts')
-rw-r--r-- | server/controllers/api/videos/channel.ts | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts index 8ec53d9ae..fba5681de 100644 --- a/server/controllers/api/videos/channel.ts +++ b/server/controllers/api/videos/channel.ts | |||
@@ -5,6 +5,7 @@ import { logger } from '../../../helpers/logger' | |||
5 | import { getFormattedObjects, resetSequelizeInstance } from '../../../helpers/utils' | 5 | import { getFormattedObjects, resetSequelizeInstance } from '../../../helpers/utils' |
6 | import { sequelizeTypescript } from '../../../initializers' | 6 | import { sequelizeTypescript } from '../../../initializers' |
7 | import { setAsyncActorKeys } from '../../../lib/activitypub' | 7 | import { setAsyncActorKeys } from '../../../lib/activitypub' |
8 | import { sendUpdateActor } from '../../../lib/activitypub/send' | ||
8 | import { createVideoChannel } from '../../../lib/video-channel' | 9 | import { createVideoChannel } from '../../../lib/video-channel' |
9 | import { | 10 | import { |
10 | asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setDefaultSort, setDefaultPagination, | 11 | asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setDefaultSort, setDefaultPagination, |
@@ -80,23 +81,28 @@ async function addVideoChannelRetryWrapper (req: express.Request, res: express.R | |||
80 | errorMessage: 'Cannot insert the video video channel with many retries.' | 81 | errorMessage: 'Cannot insert the video video channel with many retries.' |
81 | } | 82 | } |
82 | 83 | ||
83 | await retryTransactionWrapper(addVideoChannel, options) | 84 | const videoChannel = await retryTransactionWrapper(addVideoChannel, options) |
84 | 85 | return res.json({ | |
85 | // TODO : include Location of the new video channel -> 201 | 86 | videoChannel: { |
86 | return res.type('json').status(204).end() | 87 | id: videoChannel.id |
88 | } | ||
89 | }).end() | ||
87 | } | 90 | } |
88 | 91 | ||
89 | async function addVideoChannel (req: express.Request, res: express.Response) { | 92 | async function addVideoChannel (req: express.Request, res: express.Response) { |
90 | const videoChannelInfo: VideoChannelCreate = req.body | 93 | const videoChannelInfo: VideoChannelCreate = req.body |
91 | const account: AccountModel = res.locals.oauth.token.User.Account | 94 | const account: AccountModel = res.locals.oauth.token.User.Account |
92 | 95 | ||
93 | const videoChannelCreated = await sequelizeTypescript.transaction(async t => { | 96 | const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => { |
94 | return createVideoChannel(videoChannelInfo, account, t) | 97 | return createVideoChannel(videoChannelInfo, account, t) |
95 | }) | 98 | }) |
96 | 99 | ||
97 | setAsyncActorKeys(videoChannelCreated.Actor) | 100 | setAsyncActorKeys(videoChannelCreated.Actor) |
101 | .catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, err)) | ||
98 | 102 | ||
99 | logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) | 103 | logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) |
104 | |||
105 | return videoChannelCreated | ||
100 | } | 106 | } |
101 | 107 | ||
102 | 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) { |
@@ -123,11 +129,10 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
123 | 129 | ||
124 | if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) | 130 | if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) |
125 | if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) | 131 | if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) |
132 | if (videoChannelInfoToUpdate.support !== undefined) videoChannelInstance.set('support', videoChannelInfoToUpdate.support) | ||
126 | 133 | ||
127 | await videoChannelInstance.save(sequelizeOptions) | 134 | const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) |
128 | 135 | await sendUpdateActor(videoChannelInstanceUpdated, t) | |
129 | // TODO | ||
130 | // await sendUpdateVideoChannel(videoChannelInstanceUpdated, t) | ||
131 | }) | 136 | }) |
132 | 137 | ||
133 | logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) | 138 | logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) |