diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-20 16:24:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-20 16:24:31 +0200 |
commit | 0491173a61aed66205c017e0d7e0503ea316c144 (patch) | |
tree | ce6621597505f9518cfdf0981977d097c63f9fad /server/controllers/api/video-channel.ts | |
parent | 8704acf49efc770d73bf07c10468ed8c74d28a83 (diff) | |
parent | 6247b2057b792cea155a1abd9788c363ae7d2cc2 (diff) | |
download | PeerTube-0491173a61aed66205c017e0d7e0503ea316c144.tar.gz PeerTube-0491173a61aed66205c017e0d7e0503ea316c144.tar.zst PeerTube-0491173a61aed66205c017e0d7e0503ea316c144.zip |
Merge branch 'develop' into cli-wrapper
Diffstat (limited to 'server/controllers/api/video-channel.ts')
-rw-r--r-- | server/controllers/api/video-channel.ts | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index a7a36080b..ff6bbe44c 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -27,8 +27,9 @@ import { logger } from '../../helpers/logger' | |||
27 | import { VideoModel } from '../../models/video/video' | 27 | import { VideoModel } from '../../models/video/video' |
28 | import { updateAvatarValidator } from '../../middlewares/validators/avatar' | 28 | import { updateAvatarValidator } from '../../middlewares/validators/avatar' |
29 | import { updateActorAvatarFile } from '../../lib/avatar' | 29 | import { updateActorAvatarFile } from '../../lib/avatar' |
30 | import { auditLoggerFactory, VideoChannelAuditView } from '../../helpers/audit-logger' | 30 | import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger' |
31 | import { resetSequelizeInstance } from '../../helpers/database-utils' | 31 | import { resetSequelizeInstance } from '../../helpers/database-utils' |
32 | import { UserModel } from '../../models/account/user' | ||
32 | 33 | ||
33 | const auditLogger = auditLoggerFactory('channels') | 34 | const auditLogger = auditLoggerFactory('channels') |
34 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) | 35 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) |
@@ -55,7 +56,7 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick', | |||
55 | // Check the rights | 56 | // Check the rights |
56 | asyncMiddleware(videoChannelsUpdateValidator), | 57 | asyncMiddleware(videoChannelsUpdateValidator), |
57 | updateAvatarValidator, | 58 | updateAvatarValidator, |
58 | asyncMiddleware(updateVideoChannelAvatar) | 59 | asyncRetryTransactionMiddleware(updateVideoChannelAvatar) |
59 | ) | 60 | ) |
60 | 61 | ||
61 | videoChannelRouter.put('/:nameWithHost', | 62 | videoChannelRouter.put('/:nameWithHost', |
@@ -106,13 +107,9 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp | |||
106 | const videoChannel = res.locals.videoChannel as VideoChannelModel | 107 | const videoChannel = res.locals.videoChannel as VideoChannelModel |
107 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) | 108 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) |
108 | 109 | ||
109 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel.Actor, videoChannel) | 110 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel) |
110 | 111 | ||
111 | auditLogger.update( | 112 | auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys) |
112 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
113 | new VideoChannelAuditView(videoChannel.toFormattedJSON()), | ||
114 | oldVideoChannelAuditKeys | ||
115 | ) | ||
116 | 113 | ||
117 | return res | 114 | return res |
118 | .json({ | 115 | .json({ |
@@ -123,19 +120,17 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp | |||
123 | 120 | ||
124 | async function addVideoChannel (req: express.Request, res: express.Response) { | 121 | async function addVideoChannel (req: express.Request, res: express.Response) { |
125 | const videoChannelInfo: VideoChannelCreate = req.body | 122 | const videoChannelInfo: VideoChannelCreate = req.body |
126 | const account: AccountModel = res.locals.oauth.token.User.Account | ||
127 | 123 | ||
128 | const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => { | 124 | const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => { |
125 | const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t) | ||
126 | |||
129 | return createVideoChannel(videoChannelInfo, account, t) | 127 | return createVideoChannel(videoChannelInfo, account, t) |
130 | }) | 128 | }) |
131 | 129 | ||
132 | setAsyncActorKeys(videoChannelCreated.Actor) | 130 | setAsyncActorKeys(videoChannelCreated.Actor) |
133 | .catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err })) | 131 | .catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err })) |
134 | 132 | ||
135 | auditLogger.create( | 133 | auditLogger.create(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelCreated.toFormattedJSON())) |
136 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
137 | new VideoChannelAuditView(videoChannelCreated.toFormattedJSON()) | ||
138 | ) | ||
139 | logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) | 134 | logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) |
140 | 135 | ||
141 | return res.json({ | 136 | return res.json({ |
@@ -166,7 +161,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
166 | await sendUpdateActor(videoChannelInstanceUpdated, t) | 161 | await sendUpdateActor(videoChannelInstanceUpdated, t) |
167 | 162 | ||
168 | auditLogger.update( | 163 | auditLogger.update( |
169 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | 164 | getAuditIdFromRes(res), |
170 | new VideoChannelAuditView(videoChannelInstanceUpdated.toFormattedJSON()), | 165 | new VideoChannelAuditView(videoChannelInstanceUpdated.toFormattedJSON()), |
171 | oldVideoChannelAuditKeys | 166 | oldVideoChannelAuditKeys |
172 | ) | 167 | ) |
@@ -192,10 +187,7 @@ async function removeVideoChannel (req: express.Request, res: express.Response) | |||
192 | await sequelizeTypescript.transaction(async t => { | 187 | await sequelizeTypescript.transaction(async t => { |
193 | await videoChannelInstance.destroy({ transaction: t }) | 188 | await videoChannelInstance.destroy({ transaction: t }) |
194 | 189 | ||
195 | auditLogger.delete( | 190 | auditLogger.delete(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelInstance.toFormattedJSON())) |
196 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
197 | new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) | ||
198 | ) | ||
199 | logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) | 191 | logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) |
200 | }) | 192 | }) |
201 | 193 | ||