]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Misc cleanup
authorChocobozzz <florian.bigard@gmail.com>
Thu, 23 Nov 2017 17:04:48 +0000 (18:04 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 27 Nov 2017 18:40:53 +0000 (19:40 +0100)
server/helpers/custom-validators/accounts.ts
server/helpers/custom-validators/videos.ts
server/middlewares/servers.ts
server/middlewares/validators/video-channels.ts
server/models/server/server.ts
server/models/video/video-file.ts
server/tests/utils/video-abuses.ts
server/tests/utils/videos.ts

index 83540e54579e729f42844793c543657996d7dc9a..fe0fc650ae89109823da480cee539e502b67eb12 100644 (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)
index c893d2c7cf54c8b88f6f831380222e4cf71783df..205d8c62f56e68fa44000199a362df325f2c5c86 100644 (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
 }
index eaf9aa144a7806b9532b8356d1375543e9c1ec50..488f9c36848dab2c6c97925a7da525032ecacfd8 100644 (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
 }
 
 // ---------------------------------------------------------------------------
index 0326e05b916209a9c2b240247523762bac58938a..c6fd3b59d927158847ee0824eb752e53bb1ceeff 100644 (file)
@@ -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'),
index 75cd5f929bfe49c0e251a9b1961a13f689302c11..fcd7be090ee7500fac670288826b7f49cd9c447b 100644 (file)
@@ -44,7 +44,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
   )
 
   const classMethods = [
-    listBadServers
+    updateServersScoreAndRemoveBadOnes
   ]
   addMethodsToModel(Server, classMethods)
 
index ead7f3e034d43315e2a662523bed24d72a068927..600141994afcf2c0ae509e5472f59922038bf553 100644 (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>
 
index f7ee958d7f4a2dde04475bf9d753816f39a07f12..f0080923446c128d586066f889afa74633b00f40 100644 (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
 }
index d4d5faf0a6e78388ee48dad1a8184adceb78c319..dababe9249e9c87c5d83a48cfb8fff9b8e521bc6 100644 (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,