Cleanup helpers
This commit is contained in:
parent
39445ead45
commit
8d468a16fd
|
@ -3,23 +3,14 @@
|
||||||
Useful to avoid circular dependencies.
|
Useful to avoid circular dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { join } from 'path'
|
|
||||||
import { pseudoRandomBytes } from 'crypto'
|
|
||||||
import {
|
|
||||||
readdir,
|
|
||||||
readFile,
|
|
||||||
rename,
|
|
||||||
unlink,
|
|
||||||
writeFile,
|
|
||||||
access,
|
|
||||||
stat,
|
|
||||||
Stats
|
|
||||||
} from 'fs'
|
|
||||||
import * as mkdirp from 'mkdirp'
|
|
||||||
import * as bcrypt from 'bcrypt'
|
import * as bcrypt from 'bcrypt'
|
||||||
import * as createTorrent from 'create-torrent'
|
import * as createTorrent from 'create-torrent'
|
||||||
import * as rimraf from 'rimraf'
|
import { pseudoRandomBytes } from 'crypto'
|
||||||
|
import { readdir, readFile, rename, stat, Stats, unlink, writeFile } from 'fs'
|
||||||
|
import * as mkdirp from 'mkdirp'
|
||||||
|
import { join } from 'path'
|
||||||
import * as pem from 'pem'
|
import * as pem from 'pem'
|
||||||
|
import * as rimraf from 'rimraf'
|
||||||
|
|
||||||
function isTestInstance () {
|
function isTestInstance () {
|
||||||
return process.env.NODE_ENV === 'test'
|
return process.env.NODE_ENV === 'test'
|
||||||
|
@ -100,7 +91,6 @@ function promisify2WithVoid<T, U> (func: (arg1: T, arg2: U, cb: (err: any) => vo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const readFilePromise = promisify2<string, string, string>(readFile)
|
|
||||||
const readFileBufferPromise = promisify1<string, Buffer>(readFile)
|
const readFileBufferPromise = promisify1<string, Buffer>(readFile)
|
||||||
const unlinkPromise = promisify1WithVoid<string>(unlink)
|
const unlinkPromise = promisify1WithVoid<string>(unlink)
|
||||||
const renamePromise = promisify2WithVoid<string, string>(rename)
|
const renamePromise = promisify2WithVoid<string, string>(rename)
|
||||||
|
@ -108,7 +98,6 @@ const writeFilePromise = promisify2WithVoid<string, any>(writeFile)
|
||||||
const readdirPromise = promisify1<string, string[]>(readdir)
|
const readdirPromise = promisify1<string, string[]>(readdir)
|
||||||
const mkdirpPromise = promisify1<string, string>(mkdirp)
|
const mkdirpPromise = promisify1<string, string>(mkdirp)
|
||||||
const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes)
|
const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes)
|
||||||
const accessPromise = promisify1WithVoid<string | Buffer>(access)
|
|
||||||
const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey)
|
const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey)
|
||||||
const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey)
|
const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey)
|
||||||
const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare)
|
const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare)
|
||||||
|
@ -130,14 +119,12 @@ export {
|
||||||
promisify1,
|
promisify1,
|
||||||
|
|
||||||
readdirPromise,
|
readdirPromise,
|
||||||
readFilePromise,
|
|
||||||
readFileBufferPromise,
|
readFileBufferPromise,
|
||||||
unlinkPromise,
|
unlinkPromise,
|
||||||
renamePromise,
|
renamePromise,
|
||||||
writeFilePromise,
|
writeFilePromise,
|
||||||
mkdirpPromise,
|
mkdirpPromise,
|
||||||
pseudoRandomBytesPromise,
|
pseudoRandomBytesPromise,
|
||||||
accessPromise,
|
|
||||||
createPrivateKey,
|
createPrivateKey,
|
||||||
getPublicKey,
|
getPublicKey,
|
||||||
bcryptComparePromise,
|
bcryptComparePromise,
|
||||||
|
|
|
@ -14,12 +14,6 @@ function isAccountNameValid (value: string) {
|
||||||
return isUserUsernameValid(value)
|
return isUserUsernameValid(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAccountNameWithHostValid (value: string) {
|
|
||||||
const [ name, host ] = value.split('@')
|
|
||||||
|
|
||||||
return isAccountNameValid(name) && isHostValid(host)
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) {
|
function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) {
|
||||||
let promise: Promise<AccountInstance>
|
let promise: Promise<AccountInstance>
|
||||||
if (validator.isInt(id)) {
|
if (validator.isInt(id)) {
|
||||||
|
@ -48,6 +42,5 @@ function checkVideoAccountExists (id: string, res: express.Response, callback: (
|
||||||
|
|
||||||
export {
|
export {
|
||||||
checkVideoAccountExists,
|
checkVideoAccountExists,
|
||||||
isAccountNameWithHostValid,
|
|
||||||
isAccountNameValid
|
isAccountNameValid
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,6 @@ function isVideoChannelNameValid (value: string) {
|
||||||
return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME)
|
return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoChannelUUIDValid (value: string) {
|
|
||||||
return exists(value) && validator.isUUID('' + value, 4)
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) {
|
function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) {
|
||||||
let promise: Promise<VideoChannelInstance>
|
let promise: Promise<VideoChannelInstance>
|
||||||
if (validator.isInt(id)) {
|
if (validator.isInt(id)) {
|
||||||
|
@ -57,7 +53,6 @@ function checkVideoChannelExists (id: string, res: express.Response, callback: (
|
||||||
export {
|
export {
|
||||||
isVideoChannelDescriptionValid,
|
isVideoChannelDescriptionValid,
|
||||||
isVideoChannelNameValid,
|
isVideoChannelNameValid,
|
||||||
isVideoChannelUUIDValid,
|
|
||||||
checkVideoChannelExists,
|
checkVideoChannelExists,
|
||||||
isVideoChannelUrlValid
|
isVideoChannelUrlValid
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,25 @@
|
||||||
import * as Promise from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import * as express from 'express'
|
import { Response } from 'express'
|
||||||
import 'express-validator'
|
import 'express-validator'
|
||||||
import { values } from 'lodash'
|
import { values } from 'lodash'
|
||||||
import 'multer'
|
import 'multer'
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { VideoRateType } from '../../../shared'
|
import { VideoRateType } from '../../../shared'
|
||||||
import { logger } from '../../helpers'
|
import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_RATE_TYPES } from '../../initializers'
|
||||||
import {
|
import { database as db } from '../../initializers/database'
|
||||||
CONSTRAINTS_FIELDS,
|
import { VideoInstance } from '../../models/video/video-interface'
|
||||||
database as db,
|
import { logger } from '../logger'
|
||||||
VIDEO_CATEGORIES,
|
|
||||||
VIDEO_LANGUAGES,
|
|
||||||
VIDEO_LICENCES,
|
|
||||||
VIDEO_PRIVACIES,
|
|
||||||
VIDEO_RATE_TYPES
|
|
||||||
} from '../../initializers'
|
|
||||||
import { VideoInstance } from '../../models'
|
|
||||||
import { isActivityPubUrlValid } from './activitypub/misc'
|
import { isActivityPubUrlValid } from './activitypub/misc'
|
||||||
import { exists, isArray } from './misc'
|
import { exists, isArray } from './misc'
|
||||||
|
import { VIDEO_PRIVACIES } from '../../initializers/constants'
|
||||||
|
|
||||||
const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
|
const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
|
||||||
const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
|
const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
|
||||||
const VIDEO_EVENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_EVENTS
|
|
||||||
|
|
||||||
function isVideoCategoryValid (value: number) {
|
function isVideoCategoryValid (value: number) {
|
||||||
return VIDEO_CATEGORIES[value] !== undefined
|
return VIDEO_CATEGORIES[value] !== undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maybe we don't know the remote category, but that doesn't matter
|
|
||||||
function isRemoteVideoCategoryValid (value: string) {
|
|
||||||
return validator.isInt('' + value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoUrlValid (value: string) {
|
function isVideoUrlValid (value: string) {
|
||||||
return isActivityPubUrlValid(value)
|
return isActivityPubUrlValid(value)
|
||||||
}
|
}
|
||||||
|
@ -40,29 +28,10 @@ function isVideoLicenceValid (value: number) {
|
||||||
return VIDEO_LICENCES[value] !== undefined
|
return VIDEO_LICENCES[value] !== undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoPrivacyValid (value: string) {
|
|
||||||
return VIDEO_PRIVACIES[value] !== undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
// Maybe we don't know the remote privacy setting, but that doesn't matter
|
|
||||||
function isRemoteVideoPrivacyValid (value: string) {
|
|
||||||
return validator.isInt('' + value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Maybe we don't know the remote licence, but that doesn't matter
|
|
||||||
function isRemoteVideoLicenceValid (value: string) {
|
|
||||||
return validator.isInt('' + value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoLanguageValid (value: number) {
|
function isVideoLanguageValid (value: number) {
|
||||||
return value === null || VIDEO_LANGUAGES[value] !== undefined
|
return value === null || VIDEO_LANGUAGES[value] !== undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maybe we don't know the remote language, but that doesn't matter
|
|
||||||
function isRemoteVideoLanguageValid (value: string) {
|
|
||||||
return validator.isInt('' + value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoNSFWValid (value: any) {
|
function isVideoNSFWValid (value: any) {
|
||||||
return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
|
return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
|
||||||
}
|
}
|
||||||
|
@ -93,14 +62,6 @@ function isVideoTagsValid (tags: string[]) {
|
||||||
tags.every(tag => isVideoTagValid(tag))
|
tags.every(tag => isVideoTagValid(tag))
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoThumbnailValid (value: string) {
|
|
||||||
return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoThumbnailDataValid (value: string) {
|
|
||||||
return exists(value) && validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL_DATA)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoAbuseReasonValid (value: string) {
|
function isVideoAbuseReasonValid (value: string) {
|
||||||
return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
|
return exists(value) && validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON)
|
||||||
}
|
}
|
||||||
|
@ -109,18 +70,6 @@ function isVideoViewsValid (value: string) {
|
||||||
return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS)
|
return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoLikesValid (value: string) {
|
|
||||||
return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.LIKES)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoDislikesValid (value: string) {
|
|
||||||
return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DISLIKES)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoEventCountValid (value: string) {
|
|
||||||
return exists(value) && validator.isInt(value + '', VIDEO_EVENTS_CONSTRAINTS_FIELDS.COUNT)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoRatingTypeValid (value: string) {
|
function isVideoRatingTypeValid (value: string) {
|
||||||
return values(VIDEO_RATE_TYPES).indexOf(value as VideoRateType) !== -1
|
return values(VIDEO_RATE_TYPES).indexOf(value as VideoRateType) !== -1
|
||||||
}
|
}
|
||||||
|
@ -141,24 +90,16 @@ function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } |
|
||||||
return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype)
|
return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoFileSizeValid (value: string) {
|
|
||||||
return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoFileResolutionValid (value: string) {
|
|
||||||
return exists(value) && validator.isInt(value + '')
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoFileExtnameValid (value: string) {
|
|
||||||
return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVideoFileInfoHashValid (value: string) {
|
function isVideoFileInfoHashValid (value: string) {
|
||||||
return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
|
return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkVideoExists (id: string, res: express.Response, callback: () => void) {
|
function isVideoPrivacyValid (value: string) {
|
||||||
let promise: Promise<VideoInstance>
|
return VIDEO_PRIVACIES[value] !== undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkVideoExists (id: string, res: Response, callback: () => void) {
|
||||||
|
let promise: Bluebird<VideoInstance>
|
||||||
if (validator.isInt(id)) {
|
if (validator.isInt(id)) {
|
||||||
promise = db.Video.loadAndPopulateAccountAndServerAndTags(+id)
|
promise = db.Video.loadAndPopulateAccountAndServerAndTags(+id)
|
||||||
} else { // UUID
|
} else { // UUID
|
||||||
|
@ -168,17 +109,17 @@ function checkVideoExists (id: string, res: express.Response, callback: () => vo
|
||||||
promise.then(video => {
|
promise.then(video => {
|
||||||
if (!video) {
|
if (!video) {
|
||||||
return res.status(404)
|
return res.status(404)
|
||||||
.json({ error: 'Video not found' })
|
.json({ error: 'Video not found' })
|
||||||
.end()
|
.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locals.video = video
|
res.locals.video = video
|
||||||
callback()
|
callback()
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.error('Error in video request validator.', err)
|
logger.error('Error in video request validator.', err)
|
||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@ -193,25 +134,13 @@ export {
|
||||||
isVideoFileInfoHashValid,
|
isVideoFileInfoHashValid,
|
||||||
isVideoNameValid,
|
isVideoNameValid,
|
||||||
isVideoTagsValid,
|
isVideoTagsValid,
|
||||||
isVideoThumbnailValid,
|
|
||||||
isVideoThumbnailDataValid,
|
|
||||||
isVideoFileExtnameValid,
|
|
||||||
isVideoAbuseReasonValid,
|
isVideoAbuseReasonValid,
|
||||||
isVideoFile,
|
isVideoFile,
|
||||||
isVideoViewsValid,
|
isVideoViewsValid,
|
||||||
isVideoLikesValid,
|
|
||||||
isVideoRatingTypeValid,
|
isVideoRatingTypeValid,
|
||||||
isVideoDislikesValid,
|
|
||||||
isVideoEventCountValid,
|
|
||||||
isVideoFileSizeValid,
|
|
||||||
isVideoPrivacyValid,
|
|
||||||
isRemoteVideoPrivacyValid,
|
|
||||||
isVideoDurationValid,
|
isVideoDurationValid,
|
||||||
isVideoFileResolutionValid,
|
|
||||||
checkVideoExists,
|
|
||||||
isVideoTagValid,
|
isVideoTagValid,
|
||||||
isRemoteVideoCategoryValid,
|
|
||||||
isRemoteVideoLicenceValid,
|
|
||||||
isVideoUrlValid,
|
isVideoUrlValid,
|
||||||
isRemoteVideoLanguageValid
|
isVideoPrivacyValid,
|
||||||
|
checkVideoExists
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// TODO: import from ES6 when retry typing file will include errorFilter function
|
|
||||||
import * as retry from 'async/retry'
|
import * as retry from 'async/retry'
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import * as ffmpeg from 'fluent-ffmpeg'
|
import * as ffmpeg from 'fluent-ffmpeg'
|
||||||
|
|
||||||
import { CONFIG } from '../initializers'
|
|
||||||
import { VideoResolution } from '../../shared/models/videos/video-resolution.enum'
|
import { VideoResolution } from '../../shared/models/videos/video-resolution.enum'
|
||||||
|
import { CONFIG } from '../initializers'
|
||||||
|
|
||||||
function getVideoFileHeight (path: string) {
|
function getVideoFileHeight (path: string) {
|
||||||
return new Promise<number>((res, rej) => {
|
return new Promise<number>((res, rej) => {
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
import * as mkdirp from 'mkdirp'
|
import * as mkdirp from 'mkdirp'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as winston from 'winston'
|
import * as winston from 'winston'
|
||||||
|
|
||||||
// Do not use barrel (dependencies issues)
|
|
||||||
import { CONFIG } from '../initializers/constants'
|
import { CONFIG } from '../initializers/constants'
|
||||||
|
|
||||||
const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
|
const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
|
||||||
|
|
|
@ -1,17 +1,8 @@
|
||||||
import {
|
import { BCRYPT_SALT_SIZE, PRIVATE_RSA_KEY_SIZE } from '../initializers'
|
||||||
PRIVATE_RSA_KEY_SIZE,
|
|
||||||
BCRYPT_SALT_SIZE
|
|
||||||
} from '../initializers'
|
|
||||||
import {
|
|
||||||
bcryptComparePromise,
|
|
||||||
bcryptGenSaltPromise,
|
|
||||||
bcryptHashPromise,
|
|
||||||
createPrivateKey,
|
|
||||||
getPublicKey
|
|
||||||
} from './core-utils'
|
|
||||||
import { logger } from './logger'
|
|
||||||
import { AccountInstance } from '../models/account/account-interface'
|
import { AccountInstance } from '../models/account/account-interface'
|
||||||
|
import { bcryptComparePromise, bcryptGenSaltPromise, bcryptHashPromise, createPrivateKey, getPublicKey } from './core-utils'
|
||||||
import { jsig } from './custom-jsonld-signature'
|
import { jsig } from './custom-jsonld-signature'
|
||||||
|
import { logger } from './logger'
|
||||||
|
|
||||||
async function createPrivateAndPublicKeys () {
|
async function createPrivateAndPublicKeys () {
|
||||||
logger.info('Generating a RSA key...')
|
logger.info('Generating a RSA key...')
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import * as Sequelize from 'sequelize'
|
import * as Sequelize from 'sequelize'
|
||||||
|
|
||||||
import { pseudoRandomBytesPromise } from './core-utils'
|
|
||||||
import { CONFIG, database as db } from '../initializers'
|
|
||||||
import { ResultList } from '../../shared'
|
import { ResultList } from '../../shared'
|
||||||
import { VideoResolution } from '../../shared/models/videos/video-resolution.enum'
|
import { VideoResolution } from '../../shared/models/videos/video-resolution.enum'
|
||||||
|
import { CONFIG, database as db } from '../initializers'
|
||||||
import { AccountInstance } from '../models/account/account-interface'
|
import { AccountInstance } from '../models/account/account-interface'
|
||||||
|
import { pseudoRandomBytesPromise } from './core-utils'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
|
|
||||||
function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) {
|
function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import * as WebFinger from 'webfinger.js'
|
import * as WebFinger from 'webfinger.js'
|
||||||
import { WebFingerData } from '../../shared'
|
import { WebFingerData } from '../../shared'
|
||||||
import { fetchRemoteAccount } from '../lib/activitypub/account'
|
import { fetchRemoteAccount } from '../lib/activitypub/account'
|
||||||
|
|
||||||
import { isTestInstance } from './core-utils'
|
import { isTestInstance } from './core-utils'
|
||||||
import { isActivityPubUrlValid } from './custom-validators'
|
import { isActivityPubUrlValid } from './custom-validators'
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
import { body, param, query } from 'express-validator/check'
|
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
|
import { body, param, query } from 'express-validator/check'
|
||||||
import { database as db } from '../../initializers/database'
|
import { UserRight, VideoPrivacy } from '../../../shared'
|
||||||
import { checkErrors } from './utils'
|
import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
|
||||||
import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers'
|
|
||||||
import {
|
import {
|
||||||
logger,
|
checkVideoExists,
|
||||||
|
isVideoAbuseReasonValid,
|
||||||
|
isVideoCategoryValid,
|
||||||
|
isVideoDescriptionValid,
|
||||||
isVideoDurationValid,
|
isVideoDurationValid,
|
||||||
isVideoFile,
|
isVideoFile,
|
||||||
isVideoNameValid,
|
|
||||||
isVideoCategoryValid,
|
|
||||||
isVideoLicenceValid,
|
|
||||||
isVideoDescriptionValid,
|
|
||||||
isVideoLanguageValid,
|
isVideoLanguageValid,
|
||||||
isVideoTagsValid,
|
isVideoLicenceValid,
|
||||||
|
isVideoNameValid,
|
||||||
isVideoNSFWValid,
|
isVideoNSFWValid,
|
||||||
isIdOrUUIDValid,
|
isVideoPrivacyValid,
|
||||||
isVideoAbuseReasonValid,
|
|
||||||
isVideoRatingTypeValid,
|
isVideoRatingTypeValid,
|
||||||
getDurationFromVideoFile,
|
isVideoTagsValid
|
||||||
checkVideoExists,
|
} from '../../helpers/custom-validators/videos'
|
||||||
isIdValid,
|
import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils'
|
||||||
isVideoPrivacyValid
|
import { logger } from '../../helpers/logger'
|
||||||
} from '../../helpers'
|
import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers'
|
||||||
import { UserRight, VideoPrivacy } from '../../../shared'
|
|
||||||
|
import { database as db } from '../../initializers/database'
|
||||||
|
import { UserInstance } from '../../models/account/user-interface'
|
||||||
import { authenticate } from '../oauth'
|
import { authenticate } from '../oauth'
|
||||||
|
import { checkErrors } from './utils'
|
||||||
|
|
||||||
const videosAddValidator = [
|
const videosAddValidator = [
|
||||||
body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage(
|
body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage(
|
||||||
|
@ -185,7 +185,7 @@ const videosRemoveValidator = [
|
||||||
checkErrors(req, res, () => {
|
checkErrors(req, res, () => {
|
||||||
checkVideoExists(req.params.id, res, () => {
|
checkVideoExists(req.params.id, res, () => {
|
||||||
// Check if the user who did the request is able to delete the video
|
// Check if the user who did the request is able to delete the video
|
||||||
checkUserCanDeleteVideo(res.locals.oauth.token.User.id, res, () => {
|
checkUserCanDeleteVideo(res.locals.oauth.token.User, res, () => {
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -246,7 +246,7 @@ export {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
function checkUserCanDeleteVideo (userId: number, res: express.Response, callback: () => void) {
|
function checkUserCanDeleteVideo (user: UserInstance, res: express.Response, callback: () => void) {
|
||||||
// Retrieve the user who did the request
|
// Retrieve the user who did the request
|
||||||
if (res.locals.video.isOwned() === false) {
|
if (res.locals.video.isOwned() === false) {
|
||||||
return res.status(403)
|
return res.status(403)
|
||||||
|
@ -258,7 +258,6 @@ function checkUserCanDeleteVideo (userId: number, res: express.Response, callbac
|
||||||
// The user can delete it if s/he is an admin
|
// The user can delete it if s/he is an admin
|
||||||
// Or if s/he is the video's account
|
// Or if s/he is the video's account
|
||||||
const account = res.locals.video.VideoChannel.Account
|
const account = res.locals.video.VideoChannel.Account
|
||||||
const user = res.locals.oauth.token.User
|
|
||||||
if (user.hasRight(UserRight.REMOVE_ANY_VIDEO) === false && account.userId !== user.id) {
|
if (user.hasRight(UserRight.REMOVE_ANY_VIDEO) === false && account.userId !== user.id) {
|
||||||
return res.status(403)
|
return res.status(403)
|
||||||
.json({ error: 'Cannot remove video of another user' })
|
.json({ error: 'Cannot remove video of another user' })
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { query } from 'express-validator/check'
|
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
|
import { query } from 'express-validator/check'
|
||||||
import { checkErrors } from './utils'
|
import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger'
|
||||||
import { logger, isWebfingerResourceValid } from '../../helpers'
|
|
||||||
import { database as db } from '../../initializers'
|
import { database as db } from '../../initializers'
|
||||||
|
import { checkErrors } from './utils'
|
||||||
|
import { logger } from '../../helpers/logger'
|
||||||
|
|
||||||
const webfingerValidator = [
|
const webfingerValidator = [
|
||||||
query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'),
|
query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'),
|
||||||
|
|
Loading…
Reference in New Issue