Misc cleanup
This commit is contained in:
parent
8d468a16fd
commit
d4f1e94c89
|
@ -1,14 +1,11 @@
|
||||||
import * as Promise from 'bluebird'
|
import * as Promise from 'bluebird'
|
||||||
import * as validator from 'validator'
|
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import 'express-validator'
|
import 'express-validator'
|
||||||
|
import * as validator from 'validator'
|
||||||
import { database as db } from '../../initializers'
|
import { database as db } from '../../initializers'
|
||||||
import { AccountInstance } from '../../models'
|
import { AccountInstance } from '../../models'
|
||||||
import { logger } from '../logger'
|
import { logger } from '../logger'
|
||||||
|
|
||||||
import { isUserUsernameValid } from './users'
|
import { isUserUsernameValid } from './users'
|
||||||
import { isHostValid } from './servers'
|
|
||||||
|
|
||||||
function isAccountNameValid (value: string) {
|
function isAccountNameValid (value: string) {
|
||||||
return isUserUsernameValid(value)
|
return isUserUsernameValid(value)
|
||||||
|
|
|
@ -90,12 +90,20 @@ 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 isVideoPrivacyValid (value: string) {
|
||||||
|
return VIDEO_PRIVACIES[value] !== undefined
|
||||||
|
}
|
||||||
|
|
||||||
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 isVideoPrivacyValid (value: string) {
|
function isVideoFileResolutionValid (value: string) {
|
||||||
return VIDEO_PRIVACIES[value] !== undefined
|
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) {
|
function checkVideoExists (id: string, res: Response, callback: () => void) {
|
||||||
|
@ -142,5 +150,7 @@ export {
|
||||||
isVideoTagValid,
|
isVideoTagValid,
|
||||||
isVideoUrlValid,
|
isVideoUrlValid,
|
||||||
isVideoPrivacyValid,
|
isVideoPrivacyValid,
|
||||||
|
isVideoFileResolutionValid,
|
||||||
|
isVideoFileSizeValid,
|
||||||
checkVideoExists
|
checkVideoExists
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,26 +20,10 @@ function setBodyHostsPort (req: express.Request, res: express.Response, next: ex
|
||||||
return next()
|
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 {
|
export {
|
||||||
setBodyHostsPort,
|
setBodyHostsPort
|
||||||
setBodyHostPort
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
import { body, param } from 'express-validator/check'
|
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
|
import { body, param } from 'express-validator/check'
|
||||||
import { checkErrors } from './utils'
|
|
||||||
import { database as db } from '../../initializers'
|
|
||||||
import {
|
|
||||||
logger,
|
|
||||||
isIdOrUUIDValid,
|
|
||||||
isVideoChannelDescriptionValid,
|
|
||||||
isVideoChannelNameValid,
|
|
||||||
checkVideoChannelExists,
|
|
||||||
checkVideoAccountExists
|
|
||||||
} from '../../helpers'
|
|
||||||
import { UserInstance } from '../../models'
|
|
||||||
import { UserRight } from '../../../shared'
|
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 { UserInstance } from '../../models'
|
||||||
|
import { checkErrors } from './utils'
|
||||||
|
|
||||||
const listVideoAccountChannelsValidator = [
|
const listVideoAccountChannelsValidator = [
|
||||||
param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
|
param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
|
||||||
|
|
|
@ -44,7 +44,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
|
||||||
)
|
)
|
||||||
|
|
||||||
const classMethods = [
|
const classMethods = [
|
||||||
listBadServers
|
updateServersScoreAndRemoveBadOnes
|
||||||
]
|
]
|
||||||
addMethodsToModel(Server, classMethods)
|
addMethodsToModel(Server, classMethods)
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
import * as Sequelize from 'sequelize'
|
|
||||||
import { values } from 'lodash'
|
import { values } from 'lodash'
|
||||||
|
import * as Sequelize from 'sequelize'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../initializers'
|
import { isVideoFileInfoHashValid, isVideoFileResolutionValid, isVideoFileSizeValid } from '../../helpers/custom-validators/videos'
|
||||||
import {
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
||||||
isVideoFileResolutionValid,
|
|
||||||
isVideoFileSizeValid,
|
|
||||||
isVideoFileInfoHashValid
|
|
||||||
} from '../../helpers'
|
|
||||||
|
|
||||||
import { addMethodsToModel } from '../utils'
|
import { addMethodsToModel } from '../utils'
|
||||||
import {
|
import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
|
||||||
VideoFileInstance,
|
|
||||||
VideoFileAttributes
|
|
||||||
} from './video-file-interface'
|
|
||||||
|
|
||||||
let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes>
|
let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes>
|
||||||
|
|
||||||
|
|
|
@ -23,36 +23,9 @@ function getVideoAbusesList (url: string, token: string) {
|
||||||
.expect('Content-Type', /json/)
|
.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 {
|
export {
|
||||||
reportVideoAbuse,
|
reportVideoAbuse,
|
||||||
getVideoAbusesList,
|
getVideoAbusesList
|
||||||
getVideoAbusesListPagination,
|
|
||||||
getVideoAbusesListSort
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,19 +46,6 @@ function getVideoPrivacies (url: string) {
|
||||||
return makeGetRequest(url, path)
|
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) {
|
function getVideo (url: string, id: number | string, expectedStatus = 200) {
|
||||||
const path = '/api/v1/videos/' + id
|
const path = '/api/v1/videos/' + id
|
||||||
|
|
||||||
|
@ -312,7 +299,6 @@ export {
|
||||||
getVideoLicences,
|
getVideoLicences,
|
||||||
getVideoPrivacies,
|
getVideoPrivacies,
|
||||||
getVideoLanguages,
|
getVideoLanguages,
|
||||||
getAllVideosListBy,
|
|
||||||
getMyVideos,
|
getMyVideos,
|
||||||
getVideo,
|
getVideo,
|
||||||
getVideoWithToken,
|
getVideoWithToken,
|
||||||
|
|
Loading…
Reference in New Issue