Misc cleanup

This commit is contained in:
Chocobozzz 2017-11-23 18:04:48 +01:00
parent 8d468a16fd
commit d4f1e94c89
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
8 changed files with 28 additions and 91 deletions

View File

@ -1,14 +1,11 @@
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)

View File

@ -90,12 +90,20 @@ function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } |
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) {
@ -142,5 +150,7 @@ export {
isVideoTagValid,
isVideoUrlValid,
isVideoPrivacyValid,
isVideoFileResolutionValid,
isVideoFileSizeValid,
checkVideoExists
}

View File

@ -20,26 +20,10 @@ function setBodyHostsPort (req: express.Request, res: express.Response, next: ex
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
}
// ---------------------------------------------------------------------------

View File

@ -1,18 +1,13 @@
import { body, param } from 'express-validator/check'
import * as express from 'express'
import { checkErrors } from './utils'
import { database as db } from '../../initializers'
import {
logger,
isIdOrUUIDValid,
isVideoChannelDescriptionValid,
isVideoChannelNameValid,
checkVideoChannelExists,
checkVideoAccountExists
} from '../../helpers'
import { UserInstance } from '../../models'
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 { UserInstance } from '../../models'
import { checkErrors } from './utils'
const listVideoAccountChannelsValidator = [
param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),

View File

@ -44,7 +44,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
)
const classMethods = [
listBadServers
updateServersScoreAndRemoveBadOnes
]
addMethodsToModel(Server, classMethods)

View File

@ -1,18 +1,10 @@
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>

View File

@ -23,36 +23,9 @@ function getVideoAbusesList (url: string, token: string) {
.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
}

View File

@ -46,19 +46,6 @@ function getVideoPrivacies (url: string) {
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
@ -312,7 +299,6 @@ export {
getVideoLicences,
getVideoPrivacies,
getVideoLanguages,
getAllVideosListBy,
getMyVideos,
getVideo,
getVideoWithToken,