1
0
Fork 0

Fix removing scheduled update

This commit is contained in:
Chocobozzz 2018-06-18 10:24:53 +02:00
parent fc11a44ec9
commit e94fc29706
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 25 additions and 3 deletions

View File

@ -55,7 +55,7 @@ export class VideoEdit implements VideoUpdate {
}) })
// If schedule publication, the video is private and will be changed to public privacy // If schedule publication, the video is private and will be changed to public privacy
if (values['schedulePublicationAt']) { if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
const updateAt = (values['schedulePublicationAt'] as Date) const updateAt = (values['schedulePublicationAt'] as Date)
updateAt.setSeconds(0) updateAt.setSeconds(0)
@ -64,6 +64,8 @@ export class VideoEdit implements VideoUpdate {
updateAt: updateAt.toISOString(), updateAt: updateAt.toISOString(),
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC
} }
} else {
this.scheduleUpdate = null
} }
} }

View File

@ -68,6 +68,7 @@ export class VideoService {
const category = video.category || null const category = video.category || null
const description = video.description || null const description = video.description || null
const support = video.support || null const support = video.support || null
const scheduleUpdate = video.scheduleUpdate || null
const body: VideoUpdate = { const body: VideoUpdate = {
name: video.name, name: video.name,
@ -84,7 +85,7 @@ export class VideoService {
commentsEnabled: video.commentsEnabled, commentsEnabled: video.commentsEnabled,
thumbnailfile: video.thumbnailfile, thumbnailfile: video.thumbnailfile,
previewfile: video.previewfile, previewfile: video.previewfile,
scheduleUpdate: video.scheduleUpdate || undefined scheduleUpdate
} }
const data = objectToFormData(body) const data = objectToFormData(body)

View File

@ -342,10 +342,12 @@ async function updateVideo (req: express.Request, res: express.Response) {
updateAt: videoInfoToUpdate.scheduleUpdate.updateAt, updateAt: videoInfoToUpdate.scheduleUpdate.updateAt,
privacy: videoInfoToUpdate.scheduleUpdate.privacy || null privacy: videoInfoToUpdate.scheduleUpdate.privacy || null
}, { transaction: t }) }, { transaction: t })
} else if (videoInfoToUpdate.scheduleUpdate === null) {
await ScheduleVideoUpdateModel.deleteByVideoId(videoInstanceUpdated.id, t)
} }
const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo) await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
}) })
logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid) logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid)

View File

@ -94,6 +94,9 @@ const videosAddValidator = [
body('channelId') body('channelId')
.toInt() .toInt()
.custom(isIdValid).withMessage('Should have correct video channel id'), .custom(isIdValid).withMessage('Should have correct video channel id'),
body('scheduleUpdate')
.optional()
.customSanitizer(toValueOrNull),
body('scheduleUpdate.updateAt') body('scheduleUpdate.updateAt')
.optional() .optional()
.custom(isDateValid).withMessage('Should have a valid schedule update date'), .custom(isDateValid).withMessage('Should have a valid schedule update date'),
@ -199,6 +202,9 @@ const videosUpdateValidator = [
.optional() .optional()
.toInt() .toInt()
.custom(isIdValid).withMessage('Should have correct video channel id'), .custom(isIdValid).withMessage('Should have correct video channel id'),
body('scheduleUpdate')
.optional()
.customSanitizer(toValueOrNull),
body('scheduleUpdate.updateAt') body('scheduleUpdate.updateAt')
.optional() .optional()
.custom(isDateValid).withMessage('Should have a valid schedule update date'), .custom(isDateValid).withMessage('Should have a valid schedule update date'),

View File

@ -83,6 +83,17 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
return ScheduleVideoUpdateModel.findAll(query) return ScheduleVideoUpdateModel.findAll(query)
} }
static deleteByVideoId (videoId: number, t: Transaction) {
const query = {
where: {
videoId
},
transaction: t
}
return ScheduleVideoUpdateModel.destroy(query)
}
toFormattedJSON () { toFormattedJSON () {
return { return {
updateAt: this.updateAt, updateAt: this.updateAt,