From 2baea0c77cc765f7cbca9c9a2f4272268892a35c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Jun 2018 18:06:56 +0200 Subject: Add ability for uploaders to schedule video update --- server/helpers/custom-validators/videos.ts | 13 +++++++++++-- server/helpers/database-utils.ts | 6 +++++- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 8496e679a..a227136ac 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -3,7 +3,7 @@ import 'express-validator' import { values } from 'lodash' import 'multer' import * as validator from 'validator' -import { UserRight, VideoRateType } from '../../../shared' +import { UserRight, VideoPrivacy, VideoRateType } from '../../../shared' import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, @@ -98,10 +98,18 @@ function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | return isFileValid(files, videoImageTypesRegex, field, true) } -function isVideoPrivacyValid (value: string) { +function isVideoPrivacyValid (value: number) { return validator.isInt(value + '') && VIDEO_PRIVACIES[ value ] !== undefined } +function isScheduleVideoUpdatePrivacyValid (value: number) { + return validator.isInt(value + '') && + ( + value === VideoPrivacy.UNLISTED || + value === VideoPrivacy.PUBLIC + ) +} + function isVideoFileInfoHashValid (value: string) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) } @@ -174,6 +182,7 @@ export { isVideoFileInfoHashValid, isVideoNameValid, isVideoTagsValid, + isScheduleVideoUpdatePrivacyValid, isVideoAbuseReasonValid, isVideoFile, isVideoStateValid, diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 9b861a88c..ededa7901 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -21,12 +21,16 @@ function retryTransactionWrapper ( arg1: A ): Promise +function retryTransactionWrapper ( + functionToRetry: () => Promise | Bluebird +): Promise + function retryTransactionWrapper ( functionToRetry: (...args: any[]) => Promise | Bluebird, ...args: any[] ): Promise { return transactionRetryer(callback => { - functionToRetry.apply(this, args) + functionToRetry.apply(null, args) .then((result: T) => callback(null, result)) .catch(err => callback(err)) }) -- cgit v1.2.3