Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Misc cleanup

Chocobozzzd4f1e94c8933
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts
index 83540e5457..fe0fc650ae 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 c893d2c7cf..205d8c62f5 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 eaf9aa144a..488f9c3684 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 0326e05b91..c6fd3b59d9 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 75cd5f929b..fcd7be090e 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 ead7f3e034..600141994a 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<VideoFileInstance, VideoFileAttributes>
diff --git a/server/tests/utils/video-abuses.ts b/server/tests/utils/video-abuses.ts
index f7ee958d7f..f008092344 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 d4d5faf0a6..dababe9249 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,