Upgrade common server dependencies

This commit is contained in:
Chocobozzz 2017-08-25 18:36:49 +02:00
parent d15ab38a90
commit 556ddc3192
21 changed files with 505 additions and 564 deletions

View File

@ -57,8 +57,6 @@
"config": "^1.14.0", "config": "^1.14.0",
"cors": "^2.8.1", "cors": "^2.8.1",
"create-torrent": "^3.24.5", "create-torrent": "^3.24.5",
"debug": "^2.2.0",
"dezalgo": "^1.0.3",
"express": "^4.12.4", "express": "^4.12.4",
"express-oauth-server": "2.0.0-b1", "express-oauth-server": "2.0.0-b1",
"express-validator": "^3.1.0", "express-validator": "^3.1.0",
@ -82,9 +80,9 @@
"sequelize": "4.0.0-2", "sequelize": "4.0.0-2",
"ts-node": "^3.0.6", "ts-node": "^3.0.6",
"typescript": "^2.4.1", "typescript": "^2.4.1",
"validator": "^7.0.0", "validator": "^8.1.0",
"winston": "^2.1.1", "winston": "^2.1.1",
"ws": "^2.0.0" "ws": "^3.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/async": "^2.0.40", "@types/async": "^2.0.40",
@ -95,16 +93,16 @@
"@types/express": "^4.0.35", "@types/express": "^4.0.35",
"@types/lodash": "^4.14.64", "@types/lodash": "^4.14.64",
"@types/magnet-uri": "^5.1.1", "@types/magnet-uri": "^5.1.1",
"@types/mkdirp": "^0.3.29", "@types/mkdirp": "^0.5.1",
"@types/morgan": "^1.7.32", "@types/morgan": "^1.7.32",
"@types/multer": "^0.0.34", "@types/multer": "^1.3.3",
"@types/node": "^8.0.3", "@types/node": "^8.0.3",
"@types/request": "^0.0.44", "@types/request": "^2.0.3",
"@types/sequelize": "^4.0.55", "@types/sequelize": "^4.0.55",
"@types/validator": "^6.2.0", "@types/validator": "^6.2.0",
"@types/winston": "^2.3.2", "@types/winston": "^2.3.2",
"@types/ws": "^0.0.41", "@types/ws": "^3.0.2",
"chai": "^3.3.0", "chai": "^4.1.1",
"commander": "^2.9.0", "commander": "^2.9.0",
"mocha": "^3.0.1", "mocha": "^3.0.1",
"nodemon": "^1.11.0", "nodemon": "^1.11.0",

View File

@ -160,7 +160,7 @@ function onDatabaseInitDone () {
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE) VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
logger.info('Server listening on port %d', port) logger.info('Server listening on port %d', port)
logger.info('Webserver: %s', CONFIG.WEBSERVER.URL) logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
}) })
}) })
} }

View File

@ -17,7 +17,7 @@ import {
} from '../../../middlewares' } from '../../../middlewares'
import { logger, retryTransactionWrapper } from '../../../helpers' import { logger, retryTransactionWrapper } from '../../../helpers'
import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib'
import { PodInstance, VideoInstance } from '../../../models' import { PodInstance } from '../../../models'
import { import {
RemoteVideoRequest, RemoteVideoRequest,
RemoteVideoCreateData, RemoteVideoCreateData,

View File

@ -61,8 +61,7 @@ const storage = multer.diskStorage({
else if (file.mimetype === 'video/ogg') extension = 'ogv' else if (file.mimetype === 'video/ogg') extension = 'ogv'
generateRandomString(16) generateRandomString(16)
.then(randomString => { .then(randomString => {
const filename = randomString cb(null, randomString + '.' + extension)
cb(null, filename + '.' + extension)
}) })
.catch(err => { .catch(err => {
logger.error('Cannot generate random string for file name.', err) logger.error('Cannot generate random string for file name.', err)
@ -128,15 +127,15 @@ export {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function listVideoCategories (req: express.Request, res: express.Response, next: express.NextFunction) { function listVideoCategories (req: express.Request, res: express.Response) {
res.json(VIDEO_CATEGORIES) res.json(VIDEO_CATEGORIES)
} }
function listVideoLicences (req: express.Request, res: express.Response, next: express.NextFunction) { function listVideoLicences (req: express.Request, res: express.Response) {
res.json(VIDEO_LICENCES) res.json(VIDEO_LICENCES)
} }
function listVideoLanguages (req: express.Request, res: express.Response, next: express.NextFunction) { function listVideoLanguages (req: express.Request, res: express.Response) {
res.json(VIDEO_LANGUAGES) res.json(VIDEO_LANGUAGES)
} }
@ -144,7 +143,7 @@ function listVideoLanguages (req: express.Request, res: express.Response, next:
// We need this because we run the transaction in SERIALIZABLE isolation that can fail // We need this because we run the transaction in SERIALIZABLE isolation that can fail
function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
const options = { const options = {
arguments: [ req, res, req.files.videofile[0] ], arguments: [ req, res, req.files['videofile'][0] ],
errorMessage: 'Cannot insert the video with many retries.' errorMessage: 'Cannot insert the video with many retries.'
} }
@ -157,7 +156,7 @@ function addVideoRetryWrapper (req: express.Request, res: express.Response, next
} }
function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) { function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) {
const videoInfos: VideoCreate = req.body const videoInfo: VideoCreate = req.body
return db.sequelize.transaction(t => { return db.sequelize.transaction(t => {
const user = res.locals.oauth.token.User const user = res.locals.oauth.token.User
@ -169,21 +168,21 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
return db.Author.findOrCreateAuthor(name, podId, userId, t) return db.Author.findOrCreateAuthor(name, podId, userId, t)
.then(author => { .then(author => {
const tags = videoInfos.tags const tags = videoInfo.tags
if (!tags) return { author, tagInstances: undefined } if (!tags) return { author, tagInstances: undefined }
return db.Tag.findOrCreateTags(tags, t).then(tagInstances => ({ author, tagInstances })) return db.Tag.findOrCreateTags(tags, t).then(tagInstances => ({ author, tagInstances }))
}) })
.then(({ author, tagInstances }) => { .then(({ author, tagInstances }) => {
const videoData = { const videoData = {
name: videoInfos.name, name: videoInfo.name,
remote: false, remote: false,
extname: extname(videoPhysicalFile.filename), extname: extname(videoPhysicalFile.filename),
category: videoInfos.category, category: videoInfo.category,
licence: videoInfos.licence, licence: videoInfo.licence,
language: videoInfos.language, language: videoInfo.language,
nsfw: videoInfos.nsfw, nsfw: videoInfo.nsfw,
description: videoInfos.description, description: videoInfo.description,
duration: videoPhysicalFile['duration'], // duration was added by a previous middleware duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
authorId: author.id authorId: author.id
} }
@ -240,7 +239,7 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
return video.save(options) return video.save(options)
.then(videoCreated => { .then(videoCreated => {
// Do not forget to add Author informations to the created video // Do not forget to add Author information to the created video
videoCreated.Author = author videoCreated.Author = author
return { tagInstances, video: videoCreated, videoFile } return { tagInstances, video: videoCreated, videoFile }
@ -265,7 +264,7 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
}) })
}) })
.then(video => { .then(video => {
// Let transcoding job send the video to friends because the videofile extension might change // Let transcoding job send the video to friends because the video file extension might change
if (CONFIG.TRANSCODING.ENABLED === true) return undefined if (CONFIG.TRANSCODING.ENABLED === true) return undefined
return video.toAddRemoteJSON() return video.toAddRemoteJSON()
@ -275,7 +274,7 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
}) })
}) })
}) })
.then(() => logger.info('Video with name %s created.', videoInfos.name)) .then(() => logger.info('Video with name %s created.', videoInfo.name))
.catch((err: Error) => { .catch((err: Error) => {
logger.debug('Cannot insert the video.', err) logger.debug('Cannot insert the video.', err)
throw err throw err
@ -299,14 +298,14 @@ function updateVideoRetryWrapper (req: express.Request, res: express.Response, n
function updateVideo (req: express.Request, res: express.Response) { function updateVideo (req: express.Request, res: express.Response) {
const videoInstance = res.locals.video const videoInstance = res.locals.video
const videoFieldsSave = videoInstance.toJSON() const videoFieldsSave = videoInstance.toJSON()
const videoInfosToUpdate: VideoUpdate = req.body const videoInfoToUpdate: VideoUpdate = req.body
return db.sequelize.transaction(t => { return db.sequelize.transaction(t => {
let tagsPromise: Promise<TagInstance[]> let tagsPromise: Promise<TagInstance[]>
if (!videoInfosToUpdate.tags) { if (!videoInfoToUpdate.tags) {
tagsPromise = Promise.resolve(null) tagsPromise = Promise.resolve(null)
} else { } else {
tagsPromise = db.Tag.findOrCreateTags(videoInfosToUpdate.tags, t) tagsPromise = db.Tag.findOrCreateTags(videoInfoToUpdate.tags, t)
} }
return tagsPromise return tagsPromise
@ -315,12 +314,12 @@ function updateVideo (req: express.Request, res: express.Response) {
transaction: t transaction: t
} }
if (videoInfosToUpdate.name !== undefined) videoInstance.set('name', videoInfosToUpdate.name) if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name)
if (videoInfosToUpdate.category !== undefined) videoInstance.set('category', videoInfosToUpdate.category) if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category)
if (videoInfosToUpdate.licence !== undefined) videoInstance.set('licence', videoInfosToUpdate.licence) if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
if (videoInfosToUpdate.language !== undefined) videoInstance.set('language', videoInfosToUpdate.language) if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
if (videoInfosToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfosToUpdate.nsfw) if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
if (videoInfosToUpdate.description !== undefined) videoInstance.set('description', videoInfosToUpdate.description) if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
return videoInstance.save(options).then(() => tagInstances) return videoInstance.save(options).then(() => tagInstances)
}) })
@ -360,7 +359,7 @@ function updateVideo (req: express.Request, res: express.Response) {
}) })
} }
function getVideo (req: express.Request, res: express.Response, next: express.NextFunction) { function getVideo (req: express.Request, res: express.Response) {
const videoInstance = res.locals.video const videoInstance = res.locals.video
if (videoInstance.isOwned()) { if (videoInstance.isOwned()) {

View File

@ -74,7 +74,7 @@ const readFilePromise = promisify2<string, string, string>(readFile)
const readFileBufferPromise = promisify1<string, Buffer>(readFile) const readFileBufferPromise = promisify1<string, Buffer>(readFile)
const unlinkPromise = promisify1WithVoid<string>(unlink) const unlinkPromise = promisify1WithVoid<string>(unlink)
const renamePromise = promisify2WithVoid<string, string>(rename) const renamePromise = promisify2WithVoid<string, string>(rename)
const writeFilePromise = promisify2<string, any, void>(writeFile) const writeFilePromise = promisify2WithVoid<string, any>(writeFile)
const readdirPromise = promisify1<string, string[]>(readdir) const readdirPromise = promisify1<string, string[]>(readdir)
const mkdirpPromise = promisify1<string, string>(mkdirp) const mkdirpPromise = promisify1<string, string>(mkdirp)
const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes)

View File

@ -13,11 +13,9 @@ export {
isArray isArray
} }
declare global { declare module 'express-validator' {
namespace ExpressValidator { export interface Validator {
export interface Validator { exists,
exists, isArray
isArray
}
} }
} }

View File

@ -1,9 +1,20 @@
import * as validator from 'validator' import * as validator from 'validator'
import { isArray, exists } from './misc' import { isArray, exists } from './misc'
import { isTestInstance } from '../core-utils'
function isHostValid (host: string) { function isHostValid (host: string) {
return exists(host) && validator.isURL(host) && host.split('://').length === 1 const isURLOptions = {
require_host: true,
require_tld: true
}
// We validate 'localhost', so we don't have the top level domain
if (isTestInstance()) {
isURLOptions.require_tld = false
}
return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1
} }
function isEachUniqueHostValid (hosts: string[]) { function isEachUniqueHostValid (hosts: string[]) {
@ -21,11 +32,9 @@ export {
isHostValid isHostValid
} }
declare global { declare module 'express-validator' {
namespace ExpressValidator { export interface Validator {
export interface Validator { isEachUniqueHostValid
isEachUniqueHostValid isHostValid
isHostValid
}
} }
} }

View File

@ -101,13 +101,11 @@ export {
isEachRemoteRequestVideosEventsValid isEachRemoteRequestVideosEventsValid
} }
declare global { declare module 'express-validator' {
namespace ExpressValidator { export interface Validator {
export interface Validator { isEachRemoteRequestVideosValid,
isEachRemoteRequestVideosValid, isEachRemoteRequestVideosQaduValid,
isEachRemoteRequestVideosQaduValid, isEachRemoteRequestVideosEventsValid
isEachRemoteRequestVideosEventsValid
}
} }
} }

View File

@ -34,13 +34,11 @@ export {
isUserDisplayNSFWValid isUserDisplayNSFWValid
} }
declare global { declare module 'express-validator' {
namespace ExpressValidator { export interface Validator {
export interface Validator { isUserPasswordValid,
isUserPasswordValid, isUserRoleValid,
isUserRoleValid, isUserUsernameValid,
isUserUsernameValid, isUserDisplayNSFWValid
isUserDisplayNSFWValid
}
} }
} }

View File

@ -168,35 +168,33 @@ export {
isVideoFileResolutionValid isVideoFileResolutionValid
} }
declare global { declare module 'express-validator' {
namespace ExpressValidator { export interface Validator {
export interface Validator { isVideoIdOrUUIDValid,
isVideoIdOrUUIDValid, isVideoAuthorValid,
isVideoAuthorValid, isVideoDateValid,
isVideoDateValid, isVideoCategoryValid,
isVideoCategoryValid, isVideoLicenceValid,
isVideoLicenceValid, isVideoLanguageValid,
isVideoLanguageValid, isVideoNSFWValid,
isVideoNSFWValid, isVideoDescriptionValid,
isVideoDescriptionValid, isVideoDurationValid,
isVideoDurationValid, isVideoInfoHashValid,
isVideoInfoHashValid, isVideoNameValid,
isVideoNameValid, isVideoTagsValid,
isVideoTagsValid, isVideoThumbnailValid,
isVideoThumbnailValid, isVideoThumbnailDataValid,
isVideoThumbnailDataValid, isVideoExtnameValid,
isVideoExtnameValid, isVideoUUIDValid,
isVideoUUIDValid, isVideoAbuseReasonValid,
isVideoAbuseReasonValid, isVideoAbuseReporterUsernameValid,
isVideoAbuseReporterUsernameValid, isVideoFile,
isVideoFile, isVideoViewsValid,
isVideoViewsValid, isVideoLikesValid,
isVideoLikesValid, isVideoRatingTypeValid,
isVideoRatingTypeValid, isVideoDislikesValid,
isVideoDislikesValid, isVideoEventCountValid,
isVideoEventCountValid, isVideoFileSizeValid,
isVideoFileSizeValid, isVideoFileResolutionValid
isVideoFileResolutionValid
}
} }
} }

View File

@ -11,7 +11,7 @@ import { isTestInstance } from '../../helpers'
function makeFriendsValidator (req: express.Request, res: express.Response, next: express.NextFunction) { function makeFriendsValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
// Force https if the administrator wants to make friends // Force https if the administrator wants to make friends
if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') {
return res.status(400).send('Cannot make friends with a non HTTPS webserver.') return res.status(400).send('Cannot make friends with a non HTTPS web server.')
} }
req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid() req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid()

View File

@ -24,7 +24,7 @@ function videosAddValidator (req: express.Request, res: express.Response, next:
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
checkErrors(req, res, () => { checkErrors(req, res, () => {
const videoFile = req.files.videofile[0] const videoFile = req.files['videofile'][0]
db.Video.getDurationFromFile(videoFile.path) db.Video.getDurationFromFile(videoFile.path)
.then(duration => { .then(duration => {

View File

@ -42,6 +42,7 @@ export interface PodClass {
} }
export interface PodAttributes { export interface PodAttributes {
id?: number
host?: string host?: string
publicKey?: string publicKey?: string
score?: number | Sequelize.literal // Sequelize literal for 'score +' + value score?: number | Sequelize.literal // Sequelize literal for 'score +' + value
@ -49,7 +50,6 @@ export interface PodAttributes {
} }
export interface PodInstance extends PodClass, PodAttributes, Sequelize.Instance<PodAttributes> { export interface PodInstance extends PodClass, PodAttributes, Sequelize.Instance<PodAttributes> {
id: number
createdAt: Date createdAt: Date
updatedAt: Date updatedAt: Date

View File

@ -143,7 +143,7 @@ list = function () {
} }
listAllIds = function (transaction: Sequelize.Transaction) { listAllIds = function (transaction: Sequelize.Transaction) {
const query: Sequelize.FindOptions = { const query = {
attributes: [ 'id' ], attributes: [ 'id' ],
transaction transaction
} }
@ -170,9 +170,7 @@ listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, ta
limit: limit, limit: limit,
where: { where: {
id: { id: {
$in: [ $in: Sequelize.literal(`(SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins})`)
Sequelize.literal(`SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins}`)
]
} }
} }
} }

View File

@ -13,6 +13,8 @@ export interface UserVideoRateClass {
export interface UserVideoRateAttributes { export interface UserVideoRateAttributes {
type: VideoRateType type: VideoRateType
userId: number
videoId: number
} }
export interface UserVideoRateInstance extends UserVideoRateClass, UserVideoRateAttributes, Sequelize.Instance<UserVideoRateAttributes> { export interface UserVideoRateInstance extends UserVideoRateClass, UserVideoRateAttributes, Sequelize.Instance<UserVideoRateAttributes> {

View File

@ -66,7 +66,7 @@ function associate (models) {
} }
load = function (userId: number, videoId: number, transaction: Sequelize.Transaction) { load = function (userId: number, videoId: number, transaction: Sequelize.Transaction) {
const options: Sequelize.FindOptions = { const options: Sequelize.FindOptions<UserVideoRateAttributes> = {
where: { where: {
userId, userId,
videoId videoId

View File

@ -198,7 +198,7 @@ loadById = function (id: number) {
loadByUsername = function (username: string) { loadByUsername = function (username: string) {
const query = { const query = {
where: { where: {
username: username username
} }
} }
@ -212,5 +212,6 @@ loadByUsernameOrEmail = function (username: string, email: string) {
} }
} }
return User.findOne(query) // FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18387
return (User as any).findOne(query)
} }

View File

@ -121,6 +121,7 @@ export interface VideoClass {
} }
export interface VideoAttributes { export interface VideoAttributes {
id?: number
uuid?: string uuid?: string
name: string name: string
category: number category: number
@ -140,7 +141,6 @@ export interface VideoAttributes {
} }
export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> { export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
id: number
createdAt: Date createdAt: Date
updatedAt: Date updatedAt: Date

View File

@ -643,7 +643,7 @@ list = function () {
} }
listForApi = function (start: number, count: number, sort: string) { listForApi = function (start: number, count: number, sort: string) {
// Exclude Blakclisted videos from the list // Exclude blacklisted videos from the list
const query = { const query = {
distinct: true, distinct: true,
offset: start, offset: start,
@ -807,7 +807,7 @@ searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, s
model: Video['sequelize'].models.VideoFile model: Video['sequelize'].models.VideoFile
} }
const query: Sequelize.FindOptions = { const query: Sequelize.FindOptions<VideoAttributes> = {
distinct: true, distinct: true,
where: createBaseVideosWhere(), where: createBaseVideosWhere(),
offset: start, offset: start,

View File

@ -35,7 +35,7 @@ describe('Test config', function () {
const data = res.body const data = res.body
expect(data.signup.allowed).to.be.truthy expect(data.signup.allowed).to.be.true
done() done()
}) })

848
yarn.lock

File diff suppressed because it is too large Load Diff