mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-08-17 17:30:32 +03:00
Upgrade common server dependencies
This commit is contained in:
parent
d15ab38a90
commit
556ddc3192
16
package.json
16
package.json
@ -57,8 +57,6 @@
|
||||
"config": "^1.14.0",
|
||||
"cors": "^2.8.1",
|
||||
"create-torrent": "^3.24.5",
|
||||
"debug": "^2.2.0",
|
||||
"dezalgo": "^1.0.3",
|
||||
"express": "^4.12.4",
|
||||
"express-oauth-server": "2.0.0-b1",
|
||||
"express-validator": "^3.1.0",
|
||||
@ -82,9 +80,9 @@
|
||||
"sequelize": "4.0.0-2",
|
||||
"ts-node": "^3.0.6",
|
||||
"typescript": "^2.4.1",
|
||||
"validator": "^7.0.0",
|
||||
"validator": "^8.1.0",
|
||||
"winston": "^2.1.1",
|
||||
"ws": "^2.0.0"
|
||||
"ws": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/async": "^2.0.40",
|
||||
@ -95,16 +93,16 @@
|
||||
"@types/express": "^4.0.35",
|
||||
"@types/lodash": "^4.14.64",
|
||||
"@types/magnet-uri": "^5.1.1",
|
||||
"@types/mkdirp": "^0.3.29",
|
||||
"@types/mkdirp": "^0.5.1",
|
||||
"@types/morgan": "^1.7.32",
|
||||
"@types/multer": "^0.0.34",
|
||||
"@types/multer": "^1.3.3",
|
||||
"@types/node": "^8.0.3",
|
||||
"@types/request": "^0.0.44",
|
||||
"@types/request": "^2.0.3",
|
||||
"@types/sequelize": "^4.0.55",
|
||||
"@types/validator": "^6.2.0",
|
||||
"@types/winston": "^2.3.2",
|
||||
"@types/ws": "^0.0.41",
|
||||
"chai": "^3.3.0",
|
||||
"@types/ws": "^3.0.2",
|
||||
"chai": "^4.1.1",
|
||||
"commander": "^2.9.0",
|
||||
"mocha": "^3.0.1",
|
||||
"nodemon": "^1.11.0",
|
||||
|
@ -160,7 +160,7 @@ function onDatabaseInitDone () {
|
||||
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
|
||||
|
||||
logger.info('Server listening on port %d', port)
|
||||
logger.info('Webserver: %s', CONFIG.WEBSERVER.URL)
|
||||
logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import {
|
||||
} from '../../../middlewares'
|
||||
import { logger, retryTransactionWrapper } from '../../../helpers'
|
||||
import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib'
|
||||
import { PodInstance, VideoInstance } from '../../../models'
|
||||
import { PodInstance } from '../../../models'
|
||||
import {
|
||||
RemoteVideoRequest,
|
||||
RemoteVideoCreateData,
|
||||
|
@ -61,8 +61,7 @@ const storage = multer.diskStorage({
|
||||
else if (file.mimetype === 'video/ogg') extension = 'ogv'
|
||||
generateRandomString(16)
|
||||
.then(randomString => {
|
||||
const filename = randomString
|
||||
cb(null, filename + '.' + extension)
|
||||
cb(null, randomString + '.' + extension)
|
||||
})
|
||||
.catch(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)
|
||||
}
|
||||
|
||||
function listVideoLicences (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
function listVideoLicences (req: express.Request, res: express.Response) {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
const options = {
|
||||
arguments: [ req, res, req.files.videofile[0] ],
|
||||
arguments: [ req, res, req.files['videofile'][0] ],
|
||||
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) {
|
||||
const videoInfos: VideoCreate = req.body
|
||||
const videoInfo: VideoCreate = req.body
|
||||
|
||||
return db.sequelize.transaction(t => {
|
||||
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)
|
||||
.then(author => {
|
||||
const tags = videoInfos.tags
|
||||
const tags = videoInfo.tags
|
||||
if (!tags) return { author, tagInstances: undefined }
|
||||
|
||||
return db.Tag.findOrCreateTags(tags, t).then(tagInstances => ({ author, tagInstances }))
|
||||
})
|
||||
.then(({ author, tagInstances }) => {
|
||||
const videoData = {
|
||||
name: videoInfos.name,
|
||||
name: videoInfo.name,
|
||||
remote: false,
|
||||
extname: extname(videoPhysicalFile.filename),
|
||||
category: videoInfos.category,
|
||||
licence: videoInfos.licence,
|
||||
language: videoInfos.language,
|
||||
nsfw: videoInfos.nsfw,
|
||||
description: videoInfos.description,
|
||||
category: videoInfo.category,
|
||||
licence: videoInfo.licence,
|
||||
language: videoInfo.language,
|
||||
nsfw: videoInfo.nsfw,
|
||||
description: videoInfo.description,
|
||||
duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
|
||||
authorId: author.id
|
||||
}
|
||||
@ -240,7 +239,7 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
|
||||
|
||||
return video.save(options)
|
||||
.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
|
||||
|
||||
return { tagInstances, video: videoCreated, videoFile }
|
||||
@ -265,7 +264,7 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
|
||||
})
|
||||
})
|
||||
.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
|
||||
|
||||
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) => {
|
||||
logger.debug('Cannot insert the video.', err)
|
||||
throw err
|
||||
@ -299,14 +298,14 @@ function updateVideoRetryWrapper (req: express.Request, res: express.Response, n
|
||||
function updateVideo (req: express.Request, res: express.Response) {
|
||||
const videoInstance = res.locals.video
|
||||
const videoFieldsSave = videoInstance.toJSON()
|
||||
const videoInfosToUpdate: VideoUpdate = req.body
|
||||
const videoInfoToUpdate: VideoUpdate = req.body
|
||||
|
||||
return db.sequelize.transaction(t => {
|
||||
let tagsPromise: Promise<TagInstance[]>
|
||||
if (!videoInfosToUpdate.tags) {
|
||||
if (!videoInfoToUpdate.tags) {
|
||||
tagsPromise = Promise.resolve(null)
|
||||
} else {
|
||||
tagsPromise = db.Tag.findOrCreateTags(videoInfosToUpdate.tags, t)
|
||||
tagsPromise = db.Tag.findOrCreateTags(videoInfoToUpdate.tags, t)
|
||||
}
|
||||
|
||||
return tagsPromise
|
||||
@ -315,12 +314,12 @@ function updateVideo (req: express.Request, res: express.Response) {
|
||||
transaction: t
|
||||
}
|
||||
|
||||
if (videoInfosToUpdate.name !== undefined) videoInstance.set('name', videoInfosToUpdate.name)
|
||||
if (videoInfosToUpdate.category !== undefined) videoInstance.set('category', videoInfosToUpdate.category)
|
||||
if (videoInfosToUpdate.licence !== undefined) videoInstance.set('licence', videoInfosToUpdate.licence)
|
||||
if (videoInfosToUpdate.language !== undefined) videoInstance.set('language', videoInfosToUpdate.language)
|
||||
if (videoInfosToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfosToUpdate.nsfw)
|
||||
if (videoInfosToUpdate.description !== undefined) videoInstance.set('description', videoInfosToUpdate.description)
|
||||
if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name)
|
||||
if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category)
|
||||
if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
|
||||
if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
|
||||
if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
|
||||
if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
|
||||
|
||||
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
|
||||
|
||||
if (videoInstance.isOwned()) {
|
||||
|
@ -74,7 +74,7 @@ const readFilePromise = promisify2<string, string, string>(readFile)
|
||||
const readFileBufferPromise = promisify1<string, Buffer>(readFile)
|
||||
const unlinkPromise = promisify1WithVoid<string>(unlink)
|
||||
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 mkdirpPromise = promisify1<string, string>(mkdirp)
|
||||
const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes)
|
||||
|
@ -13,11 +13,9 @@ export {
|
||||
isArray
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace ExpressValidator {
|
||||
export interface Validator {
|
||||
exists,
|
||||
isArray
|
||||
}
|
||||
declare module 'express-validator' {
|
||||
export interface Validator {
|
||||
exists,
|
||||
isArray
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,20 @@
|
||||
import * as validator from 'validator'
|
||||
|
||||
import { isArray, exists } from './misc'
|
||||
import { isTestInstance } from '../core-utils'
|
||||
|
||||
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[]) {
|
||||
@ -21,11 +32,9 @@ export {
|
||||
isHostValid
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace ExpressValidator {
|
||||
export interface Validator {
|
||||
isEachUniqueHostValid
|
||||
isHostValid
|
||||
}
|
||||
declare module 'express-validator' {
|
||||
export interface Validator {
|
||||
isEachUniqueHostValid
|
||||
isHostValid
|
||||
}
|
||||
}
|
||||
|
@ -101,13 +101,11 @@ export {
|
||||
isEachRemoteRequestVideosEventsValid
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace ExpressValidator {
|
||||
export interface Validator {
|
||||
isEachRemoteRequestVideosValid,
|
||||
isEachRemoteRequestVideosQaduValid,
|
||||
isEachRemoteRequestVideosEventsValid
|
||||
}
|
||||
declare module 'express-validator' {
|
||||
export interface Validator {
|
||||
isEachRemoteRequestVideosValid,
|
||||
isEachRemoteRequestVideosQaduValid,
|
||||
isEachRemoteRequestVideosEventsValid
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,11 @@ export {
|
||||
isUserDisplayNSFWValid
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace ExpressValidator {
|
||||
export interface Validator {
|
||||
isUserPasswordValid,
|
||||
isUserRoleValid,
|
||||
isUserUsernameValid,
|
||||
isUserDisplayNSFWValid
|
||||
}
|
||||
declare module 'express-validator' {
|
||||
export interface Validator {
|
||||
isUserPasswordValid,
|
||||
isUserRoleValid,
|
||||
isUserUsernameValid,
|
||||
isUserDisplayNSFWValid
|
||||
}
|
||||
}
|
||||
|
@ -168,35 +168,33 @@ export {
|
||||
isVideoFileResolutionValid
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace ExpressValidator {
|
||||
export interface Validator {
|
||||
isVideoIdOrUUIDValid,
|
||||
isVideoAuthorValid,
|
||||
isVideoDateValid,
|
||||
isVideoCategoryValid,
|
||||
isVideoLicenceValid,
|
||||
isVideoLanguageValid,
|
||||
isVideoNSFWValid,
|
||||
isVideoDescriptionValid,
|
||||
isVideoDurationValid,
|
||||
isVideoInfoHashValid,
|
||||
isVideoNameValid,
|
||||
isVideoTagsValid,
|
||||
isVideoThumbnailValid,
|
||||
isVideoThumbnailDataValid,
|
||||
isVideoExtnameValid,
|
||||
isVideoUUIDValid,
|
||||
isVideoAbuseReasonValid,
|
||||
isVideoAbuseReporterUsernameValid,
|
||||
isVideoFile,
|
||||
isVideoViewsValid,
|
||||
isVideoLikesValid,
|
||||
isVideoRatingTypeValid,
|
||||
isVideoDislikesValid,
|
||||
isVideoEventCountValid,
|
||||
isVideoFileSizeValid,
|
||||
isVideoFileResolutionValid
|
||||
}
|
||||
declare module 'express-validator' {
|
||||
export interface Validator {
|
||||
isVideoIdOrUUIDValid,
|
||||
isVideoAuthorValid,
|
||||
isVideoDateValid,
|
||||
isVideoCategoryValid,
|
||||
isVideoLicenceValid,
|
||||
isVideoLanguageValid,
|
||||
isVideoNSFWValid,
|
||||
isVideoDescriptionValid,
|
||||
isVideoDurationValid,
|
||||
isVideoInfoHashValid,
|
||||
isVideoNameValid,
|
||||
isVideoTagsValid,
|
||||
isVideoThumbnailValid,
|
||||
isVideoThumbnailDataValid,
|
||||
isVideoExtnameValid,
|
||||
isVideoUUIDValid,
|
||||
isVideoAbuseReasonValid,
|
||||
isVideoAbuseReporterUsernameValid,
|
||||
isVideoFile,
|
||||
isVideoViewsValid,
|
||||
isVideoLikesValid,
|
||||
isVideoRatingTypeValid,
|
||||
isVideoDislikesValid,
|
||||
isVideoEventCountValid,
|
||||
isVideoFileSizeValid,
|
||||
isVideoFileResolutionValid
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import { isTestInstance } from '../../helpers'
|
||||
function makeFriendsValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
// Force https if the administrator wants to make friends
|
||||
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()
|
||||
|
@ -24,7 +24,7 @@ function videosAddValidator (req: express.Request, res: express.Response, next:
|
||||
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
|
||||
|
||||
checkErrors(req, res, () => {
|
||||
const videoFile = req.files.videofile[0]
|
||||
const videoFile = req.files['videofile'][0]
|
||||
|
||||
db.Video.getDurationFromFile(videoFile.path)
|
||||
.then(duration => {
|
||||
|
@ -42,6 +42,7 @@ export interface PodClass {
|
||||
}
|
||||
|
||||
export interface PodAttributes {
|
||||
id?: number
|
||||
host?: string
|
||||
publicKey?: string
|
||||
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> {
|
||||
id: number
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
|
||||
|
@ -143,7 +143,7 @@ list = function () {
|
||||
}
|
||||
|
||||
listAllIds = function (transaction: Sequelize.Transaction) {
|
||||
const query: Sequelize.FindOptions = {
|
||||
const query = {
|
||||
attributes: [ 'id' ],
|
||||
transaction
|
||||
}
|
||||
@ -170,9 +170,7 @@ listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, ta
|
||||
limit: limit,
|
||||
where: {
|
||||
id: {
|
||||
$in: [
|
||||
Sequelize.literal(`SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins}`)
|
||||
]
|
||||
$in: Sequelize.literal(`(SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins})`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ export interface UserVideoRateClass {
|
||||
|
||||
export interface UserVideoRateAttributes {
|
||||
type: VideoRateType
|
||||
userId: number
|
||||
videoId: number
|
||||
}
|
||||
|
||||
export interface UserVideoRateInstance extends UserVideoRateClass, UserVideoRateAttributes, Sequelize.Instance<UserVideoRateAttributes> {
|
||||
|
@ -66,7 +66,7 @@ function associate (models) {
|
||||
}
|
||||
|
||||
load = function (userId: number, videoId: number, transaction: Sequelize.Transaction) {
|
||||
const options: Sequelize.FindOptions = {
|
||||
const options: Sequelize.FindOptions<UserVideoRateAttributes> = {
|
||||
where: {
|
||||
userId,
|
||||
videoId
|
||||
|
@ -198,7 +198,7 @@ loadById = function (id: number) {
|
||||
loadByUsername = function (username: string) {
|
||||
const query = {
|
||||
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)
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ export interface VideoClass {
|
||||
}
|
||||
|
||||
export interface VideoAttributes {
|
||||
id?: number
|
||||
uuid?: string
|
||||
name: string
|
||||
category: number
|
||||
@ -140,7 +141,6 @@ export interface VideoAttributes {
|
||||
}
|
||||
|
||||
export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
|
||||
id: number
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
|
||||
|
@ -643,7 +643,7 @@ list = function () {
|
||||
}
|
||||
|
||||
listForApi = function (start: number, count: number, sort: string) {
|
||||
// Exclude Blakclisted videos from the list
|
||||
// Exclude blacklisted videos from the list
|
||||
const query = {
|
||||
distinct: true,
|
||||
offset: start,
|
||||
@ -807,7 +807,7 @@ searchAndPopulateAuthorAndPodAndTags = function (value: string, field: string, s
|
||||
model: Video['sequelize'].models.VideoFile
|
||||
}
|
||||
|
||||
const query: Sequelize.FindOptions = {
|
||||
const query: Sequelize.FindOptions<VideoAttributes> = {
|
||||
distinct: true,
|
||||
where: createBaseVideosWhere(),
|
||||
offset: start,
|
||||
|
@ -35,7 +35,7 @@ describe('Test config', function () {
|
||||
|
||||
const data = res.body
|
||||
|
||||
expect(data.signup.allowed).to.be.truthy
|
||||
expect(data.signup.allowed).to.be.true
|
||||
|
||||
done()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user