Server: Bulk update videos support field
This commit is contained in:
parent
9977c12838
commit
7d14d4d2ca
11 changed files with 154 additions and 32 deletions
|
@ -19,7 +19,7 @@ import { VideoChannelModel } from '../../models/video/video-channel'
|
|||
import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators'
|
||||
import { sendUpdateActor } from '../../lib/activitypub/send'
|
||||
import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
|
||||
import { createVideoChannel } from '../../lib/video-channel'
|
||||
import { createVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
|
||||
import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
|
||||
import { setAsyncActorKeys } from '../../lib/activitypub'
|
||||
import { AccountModel } from '../../models/account/account'
|
||||
|
@ -160,6 +160,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
|
|||
const videoChannelFieldsSave = videoChannelInstance.toJSON()
|
||||
const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON())
|
||||
const videoChannelInfoToUpdate = req.body as VideoChannelUpdate
|
||||
let doBulkVideoUpdate = false
|
||||
|
||||
try {
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
|
@ -167,9 +168,18 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
|
|||
transaction: t
|
||||
}
|
||||
|
||||
if (videoChannelInfoToUpdate.displayName !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.displayName)
|
||||
if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description)
|
||||
if (videoChannelInfoToUpdate.support !== undefined) videoChannelInstance.set('support', videoChannelInfoToUpdate.support)
|
||||
if (videoChannelInfoToUpdate.displayName !== undefined) videoChannelInstance.name = videoChannelInfoToUpdate.displayName
|
||||
if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.description = videoChannelInfoToUpdate.description
|
||||
|
||||
if (videoChannelInfoToUpdate.support !== undefined) {
|
||||
const oldSupportField = videoChannelInstance.support
|
||||
videoChannelInstance.support = videoChannelInfoToUpdate.support
|
||||
|
||||
if (videoChannelInfoToUpdate.bulkVideosSupportUpdate === true && oldSupportField !== videoChannelInfoToUpdate.support) {
|
||||
doBulkVideoUpdate = true
|
||||
await VideoModel.bulkUpdateSupportField(videoChannelInstance, t)
|
||||
}
|
||||
}
|
||||
|
||||
const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions)
|
||||
await sendUpdateActor(videoChannelInstanceUpdated, t)
|
||||
|
@ -179,6 +189,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
|
|||
new VideoChannelAuditView(videoChannelInstanceUpdated.toFormattedJSON()),
|
||||
oldVideoChannelAuditKeys
|
||||
)
|
||||
|
||||
logger.info('Video channel %s updated.', videoChannelInstance.Actor.url)
|
||||
})
|
||||
} catch (err) {
|
||||
|
@ -192,7 +203,12 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
|
|||
throw err
|
||||
}
|
||||
|
||||
return res.type('json').status(204).end()
|
||||
res.type('json').status(204).end()
|
||||
|
||||
// Don't process in a transaction, and after the response because it could be long
|
||||
if (doBulkVideoUpdate) {
|
||||
await federateAllVideosOfChannel(videoChannelInstance)
|
||||
}
|
||||
}
|
||||
|
||||
async function removeVideoChannel (req: express.Request, res: express.Response) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue