From d4f1e94c89336255537b0b82913591f00e716201 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 23 Nov 2017 18:04:48 +0100 Subject: Misc cleanup --- server/helpers/custom-validators/accounts.ts | 5 +---- server/helpers/custom-validators/videos.ts | 14 ++++++++++-- server/middlewares/servers.ts | 18 +-------------- server/middlewares/validators/video-channels.ts | 19 ++++++---------- server/models/server/server.ts | 2 +- server/models/video/video-file.ts | 16 ++++---------- server/tests/utils/video-abuses.ts | 29 +------------------------ server/tests/utils/videos.ts | 14 ------------ 8 files changed, 27 insertions(+), 90 deletions(-) (limited to 'server') diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts index 83540e545..fe0fc650a 100644 --- a/server/helpers/custom-validators/accounts.ts +++ b/server/helpers/custom-validators/accounts.ts @@ -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) diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index c893d2c7c..205d8c62f 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -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 } diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts index eaf9aa144..488f9c368 100644 --- a/server/middlewares/servers.ts +++ b/server/middlewares/servers.ts @@ -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 } // --------------------------------------------------------------------------- diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 0326e05b9..c6fd3b59d 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts @@ -1,18 +1,13 @@ -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'), diff --git a/server/models/server/server.ts b/server/models/server/server.ts index 75cd5f929..fcd7be090 100644 --- a/server/models/server/server.ts +++ b/server/models/server/server.ts @@ -44,7 +44,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da ) const classMethods = [ - listBadServers + updateServersScoreAndRemoveBadOnes ] addMethodsToModel(Server, classMethods) diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index ead7f3e03..600141994 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -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 diff --git a/server/tests/utils/video-abuses.ts b/server/tests/utils/video-abuses.ts index f7ee958d7..f00809234 100644 --- a/server/tests/utils/video-abuses.ts +++ b/server/tests/utils/video-abuses.ts @@ -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 } diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index d4d5faf0a..dababe924 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts @@ -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, -- cgit v1.2.3