diff options
author | Chocobozzz <me@florianbigard.com> | 2019-05-31 16:30:11 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-05-31 16:44:46 +0200 |
commit | 7d14d4d2ca82cc43c93b45bb1f90af975cfbf67c (patch) | |
tree | d2d2c9806dd1bf551ad39102149f514bca4c52eb /server/controllers/api | |
parent | 9977c128387f38dddd697b2e9a405dcea52407b7 (diff) | |
download | PeerTube-7d14d4d2ca82cc43c93b45bb1f90af975cfbf67c.tar.gz PeerTube-7d14d4d2ca82cc43c93b45bb1f90af975cfbf67c.tar.zst PeerTube-7d14d4d2ca82cc43c93b45bb1f90af975cfbf67c.zip |
Server: Bulk update videos support field
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/video-channel.ts | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index c98a39be2..81a03a62b 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -19,7 +19,7 @@ import { VideoChannelModel } from '../../models/video/video-channel' | |||
19 | import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' | 19 | import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' |
20 | import { sendUpdateActor } from '../../lib/activitypub/send' | 20 | import { sendUpdateActor } from '../../lib/activitypub/send' |
21 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' | 21 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' |
22 | import { createVideoChannel } from '../../lib/video-channel' | 22 | import { createVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' |
23 | import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' | 23 | import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
24 | import { setAsyncActorKeys } from '../../lib/activitypub' | 24 | import { setAsyncActorKeys } from '../../lib/activitypub' |
25 | import { AccountModel } from '../../models/account/account' | 25 | import { AccountModel } from '../../models/account/account' |
@@ -160,6 +160,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
160 | const videoChannelFieldsSave = videoChannelInstance.toJSON() | 160 | const videoChannelFieldsSave = videoChannelInstance.toJSON() |
161 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) | 161 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) |
162 | const videoChannelInfoToUpdate = req.body as VideoChannelUpdate | 162 | const videoChannelInfoToUpdate = req.body as VideoChannelUpdate |
163 | let doBulkVideoUpdate = false | ||
163 | 164 | ||
164 | try { | 165 | try { |
165 | await sequelizeTypescript.transaction(async t => { | 166 | await sequelizeTypescript.transaction(async t => { |
@@ -167,9 +168,18 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
167 | transaction: t | 168 | transaction: t |
168 | } | 169 | } |
169 | 170 | ||
170 | if (videoChannelInfoToUpdate.displayName !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.displayName) | 171 | if (videoChannelInfoToUpdate.displayName !== undefined) videoChannelInstance.name = videoChannelInfoToUpdate.displayName |
171 | if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) | 172 | if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.description = videoChannelInfoToUpdate.description |
172 | if (videoChannelInfoToUpdate.support !== undefined) videoChannelInstance.set('support', videoChannelInfoToUpdate.support) | 173 | |
174 | if (videoChannelInfoToUpdate.support !== undefined) { | ||
175 | const oldSupportField = videoChannelInstance.support | ||
176 | videoChannelInstance.support = videoChannelInfoToUpdate.support | ||
177 | |||
178 | if (videoChannelInfoToUpdate.bulkVideosSupportUpdate === true && oldSupportField !== videoChannelInfoToUpdate.support) { | ||
179 | doBulkVideoUpdate = true | ||
180 | await VideoModel.bulkUpdateSupportField(videoChannelInstance, t) | ||
181 | } | ||
182 | } | ||
173 | 183 | ||
174 | const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) | 184 | const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) |
175 | await sendUpdateActor(videoChannelInstanceUpdated, t) | 185 | await sendUpdateActor(videoChannelInstanceUpdated, t) |
@@ -179,6 +189,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
179 | new VideoChannelAuditView(videoChannelInstanceUpdated.toFormattedJSON()), | 189 | new VideoChannelAuditView(videoChannelInstanceUpdated.toFormattedJSON()), |
180 | oldVideoChannelAuditKeys | 190 | oldVideoChannelAuditKeys |
181 | ) | 191 | ) |
192 | |||
182 | logger.info('Video channel %s updated.', videoChannelInstance.Actor.url) | 193 | logger.info('Video channel %s updated.', videoChannelInstance.Actor.url) |
183 | }) | 194 | }) |
184 | } catch (err) { | 195 | } catch (err) { |
@@ -192,7 +203,12 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
192 | throw err | 203 | throw err |
193 | } | 204 | } |
194 | 205 | ||
195 | return res.type('json').status(204).end() | 206 | res.type('json').status(204).end() |
207 | |||
208 | // Don't process in a transaction, and after the response because it could be long | ||
209 | if (doBulkVideoUpdate) { | ||
210 | await federateAllVideosOfChannel(videoChannelInstance) | ||
211 | } | ||
196 | } | 212 | } |
197 | 213 | ||
198 | async function removeVideoChannel (req: express.Request, res: express.Response) { | 214 | async function removeVideoChannel (req: express.Request, res: express.Response) { |