import * as Promise from 'bluebird'
-import * as validator from 'validator'
import * as express from 'express'
import 'express-validator'
-
+import * as validator from 'validator'
import { database as db } from '../../initializers'
import { AccountInstance } from '../../models'
import { logger } from '../logger'
-
import { isUserUsernameValid } from './users'
-import { isHostValid } from './servers'
function isAccountNameValid (value: string) {
return isUserUsernameValid(value)
return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype)
}
+function isVideoPrivacyValid (value: string) {
+ return VIDEO_PRIVACIES[value] !== undefined
+}
+
function isVideoFileInfoHashValid (value: string) {
return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
}
-function isVideoPrivacyValid (value: string) {
- return VIDEO_PRIVACIES[value] !== undefined
+function isVideoFileResolutionValid (value: string) {
+ return exists(value) && validator.isInt(value + '')
+}
+
+function isVideoFileSizeValid (value: string) {
+ return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE)
}
function checkVideoExists (id: string, res: Response, callback: () => void) {
isVideoTagValid,
isVideoUrlValid,
isVideoPrivacyValid,
+ isVideoFileResolutionValid,
+ isVideoFileSizeValid,
checkVideoExists
}
return next()
}
-function setBodyHostPort (req: express.Request, res: express.Response, next: express.NextFunction) {
- if (!req.body.host) return next()
-
- const hostWithPort = getHostWithPort(req.body.host)
-
- // Problem with the url parsing?
- if (hostWithPort === null) {
- return res.sendStatus(500)
- }
-
- req.body.host = hostWithPort
-
- return next()
-}
-
// ---------------------------------------------------------------------------
export {
- setBodyHostsPort,
- setBodyHostPort
+ setBodyHostsPort
}
// ---------------------------------------------------------------------------
-import { body, param } from 'express-validator/check'
import * as express from 'express'
-
-import { checkErrors } from './utils'
+import { body, param } from 'express-validator/check'
+import { UserRight } from '../../../shared'
+import { checkVideoAccountExists } from '../../helpers/custom-validators/accounts'
+import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels'
+import { checkVideoChannelExists, isIdOrUUIDValid } from '../../helpers/index'
+import { logger } from '../../helpers/logger'
import { database as db } from '../../initializers'
-import {
- logger,
- isIdOrUUIDValid,
- isVideoChannelDescriptionValid,
- isVideoChannelNameValid,
- checkVideoChannelExists,
- checkVideoAccountExists
-} from '../../helpers'
import { UserInstance } from '../../models'
-import { UserRight } from '../../../shared'
+import { checkErrors } from './utils'
const listVideoAccountChannelsValidator = [
param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
)
const classMethods = [
- listBadServers
+ updateServersScoreAndRemoveBadOnes
]
addMethodsToModel(Server, classMethods)
-import * as Sequelize from 'sequelize'
import { values } from 'lodash'
-
-import { CONSTRAINTS_FIELDS } from '../../initializers'
-import {
- isVideoFileResolutionValid,
- isVideoFileSizeValid,
- isVideoFileInfoHashValid
-} from '../../helpers'
+import * as Sequelize from 'sequelize'
+import { isVideoFileInfoHashValid, isVideoFileResolutionValid, isVideoFileSizeValid } from '../../helpers/custom-validators/videos'
+import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { addMethodsToModel } from '../utils'
-import {
- VideoFileInstance,
- VideoFileAttributes
-} from './video-file-interface'
+import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes>
.expect('Content-Type', /json/)
}
-function getVideoAbusesListPagination (url: string, token: string, start: number, count: number) {
- const path = '/api/v1/videos/abuse'
-
- return request(url)
- .get(path)
- .query({ start: start })
- .query({ count: count })
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + token)
- .expect(200)
- .expect('Content-Type', /json/)
-}
-
-function getVideoAbusesListSort (url: string, token: string, sort: string) {
- const path = '/api/v1/videos/abuse'
-
- return request(url)
- .get(path)
- .query({ sort: sort })
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + token)
- .expect(200)
- .expect('Content-Type', /json/)
-}
-
// ---------------------------------------------------------------------------
export {
reportVideoAbuse,
- getVideoAbusesList,
- getVideoAbusesListPagination,
- getVideoAbusesListSort
+ getVideoAbusesList
}
return makeGetRequest(url, path)
}
-function getAllVideosListBy (url: string) {
- const path = '/api/v1/videos'
-
- return request(url)
- .get(path)
- .query({ sort: 'createdAt' })
- .query({ start: 0 })
- .query({ count: 10000 })
- .set('Accept', 'application/json')
- .expect(200)
- .expect('Content-Type', /json/)
-}
-
function getVideo (url: string, id: number | string, expectedStatus = 200) {
const path = '/api/v1/videos/' + id
getVideoLicences,
getVideoPrivacies,
getVideoLanguages,
- getAllVideosListBy,
getMyVideos,
getVideo,
getVideoWithToken,