From d5d9b6d7bfb7e9426b6462f7fdf285df39eea820 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 21 Oct 2019 14:50:55 +0200 Subject: Update server dependencies --- server/controllers/api/jobs.ts | 4 ++-- server/controllers/bots.ts | 12 +++--------- server/helpers/custom-validators/video-ownership.ts | 3 ++- server/helpers/middlewares/video-abuses.ts | 3 ++- server/lib/activitypub/send/send-update.ts | 2 +- server/middlewares/validators/redundancy.ts | 18 ++++++++++++++---- server/middlewares/validators/users.ts | 3 ++- server/middlewares/validators/videos/video-comments.ts | 6 ++++-- server/models/account/account-video-rate.ts | 2 +- server/models/activitypub/actor.ts | 2 -- server/models/video/video-file.ts | 2 +- server/models/video/video-playlist-element.ts | 2 +- server/models/video/video-share.ts | 2 +- server/models/video/video.ts | 2 +- 14 files changed, 35 insertions(+), 28 deletions(-) (limited to 'server') diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts index c19596dde..1fa662349 100644 --- a/server/controllers/api/jobs.ts +++ b/server/controllers/api/jobs.ts @@ -36,8 +36,8 @@ export { // --------------------------------------------------------------------------- -async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) { - const state: JobState = req.params.state +async function listJobs (req: express.Request, res: express.Response) { + const state = req.params.state as JobState const asc = req.query.sort === 'createdAt' const jobs = await JobQueue.Instance.listForApi(state, req.query.start, req.query.count, asc) diff --git a/server/controllers/bots.ts b/server/controllers/bots.ts index e25d9c21b..ed1040176 100644 --- a/server/controllers/bots.ts +++ b/server/controllers/bots.ts @@ -2,7 +2,6 @@ import * as express from 'express' import { asyncMiddleware } from '../middlewares' import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' import * as sitemapModule from 'sitemap' -import { logger } from '../helpers/logger' import { VideoModel } from '../models/video/video' import { VideoChannelModel } from '../models/video/video-channel' import { AccountModel } from '../models/account/account' @@ -39,15 +38,10 @@ async function getSitemap (req: express.Request, res: express.Response) { urls: urls }) - sitemap.toXML((err, xml) => { - if (err) { - logger.error('Cannot generate sitemap.', { err }) - return res.sendStatus(500) - } + const xml = sitemap.toXML() - res.header('Content-Type', 'application/xml') - res.send(xml) - }) + res.header('Content-Type', 'application/xml') + res.send(xml) } async function getSitemapVideoChannelUrls () { diff --git a/server/helpers/custom-validators/video-ownership.ts b/server/helpers/custom-validators/video-ownership.ts index 9570b2799..2d1849332 100644 --- a/server/helpers/custom-validators/video-ownership.ts +++ b/server/helpers/custom-validators/video-ownership.ts @@ -3,7 +3,8 @@ import { VideoChangeOwnershipModel } from '../../models/video/video-change-owner import { MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership' import { MUserId } from '@server/typings/models' -export async function doesChangeVideoOwnershipExist (id: number, res: Response) { +export async function doesChangeVideoOwnershipExist (idArg: number | string, res: Response) { + const id = parseInt(idArg + '', 10) const videoChangeOwnership = await VideoChangeOwnershipModel.load(id) if (!videoChangeOwnership) { diff --git a/server/helpers/middlewares/video-abuses.ts b/server/helpers/middlewares/video-abuses.ts index 1b573ca37..8a1d3d618 100644 --- a/server/helpers/middlewares/video-abuses.ts +++ b/server/helpers/middlewares/video-abuses.ts @@ -1,7 +1,8 @@ import { Response } from 'express' import { VideoAbuseModel } from '../../models/video/video-abuse' -async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { +async function doesVideoAbuseExist (abuseIdArg: number | string, videoId: number, res: Response) { + const abuseId = parseInt(abuseIdArg + '', 10) const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) if (videoAbuse === null) { diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 37517c2be..44e0e1161 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -55,7 +55,7 @@ async function sendUpdateActor (accountOrChannel: MChannelDefault | MAccountDefa logger.info('Creating job to update actor %s.', byActor.url) const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) - const accountOrChannelObject = accountOrChannel.toActivityPubObject() + const accountOrChannelObject = (accountOrChannel as any).toActivityPubObject() // FIXME: typescript bug? const audience = getAudience(byActor) const updateActivity = buildUpdateActivity(url, byActor, accountOrChannelObject, audience) diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts index e65d3b8d3..8098e3a44 100644 --- a/server/middlewares/validators/redundancy.ts +++ b/server/middlewares/validators/redundancy.ts @@ -25,8 +25,12 @@ const videoFileRedundancyGetValidator = [ if (!await doesVideoExist(req.params.videoId, res)) return const video = res.locals.videoAll + + const paramResolution = req.params.resolution as unknown as number // We casted to int above + const paramFPS = req.params.fps as unknown as number // We casted to int above + const videoFile = video.VideoFiles.find(f => { - return f.resolution === req.params.resolution && (!req.params.fps || f.fps === req.params.fps) + return f.resolution === paramResolution && (!req.params.fps || paramFPS) }) if (!videoFile) return res.status(404).json({ error: 'Video file not found.' }) @@ -41,8 +45,12 @@ const videoFileRedundancyGetValidator = [ ] const videoPlaylistRedundancyGetValidator = [ - param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), - param('streamingPlaylistType').custom(exists).withMessage('Should have a valid streaming playlist type'), + param('videoId') + .custom(isIdOrUUIDValid) + .not().isEmpty().withMessage('Should have a valid video id'), + param('streamingPlaylistType') + .customSanitizer(toIntOrNull) + .custom(exists).withMessage('Should have a valid streaming playlist type'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params }) @@ -51,7 +59,9 @@ const videoPlaylistRedundancyGetValidator = [ if (!await doesVideoExist(req.params.videoId, res)) return const video = res.locals.videoAll - const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p === req.params.streamingPlaylistType) + + const paramPlaylistType = req.params.streamingPlaylistType as unknown as number // We casted to int above + const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p.type === paramPlaylistType) if (!videoStreamingPlaylist) return res.status(404).json({ error: 'Video playlist not found.' }) res.locals.videoStreamingPlaylist = videoStreamingPlaylist diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index b3466333c..804d1410e 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -448,7 +448,8 @@ export { // --------------------------------------------------------------------------- -function checkUserIdExist (id: number, res: express.Response) { +function checkUserIdExist (idArg: number | string, res: express.Response) { + const id = parseInt(idArg + '', 10) return checkUserExist(() => UserModel.loadById(id), res) } diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 8adbb02ba..1d81eb5d8 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts @@ -120,7 +120,8 @@ export { // --------------------------------------------------------------------------- -async function doesVideoCommentThreadExist (id: number, video: MVideoId, res: express.Response) { +async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) { + const id = parseInt(idArg + '', 10) const videoComment = await VideoCommentModel.loadById(id) if (!videoComment) { @@ -151,7 +152,8 @@ async function doesVideoCommentThreadExist (id: number, video: MVideoId, res: ex return true } -async function doesVideoCommentExist (id: number, video: MVideoId, res: express.Response) { +async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) { + const id = parseInt(idArg + '', 10) const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) if (!videoComment) { diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index a6edbeee8..c593595b2 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts @@ -150,7 +150,7 @@ export class AccountVideoRateModel extends Model { static loadLocalAndPopulateVideo ( rateType: VideoRateType, accountName: string, - videoId: number, + videoId: number | string, t?: Transaction ): Bluebird { const options: FindOptions = { diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 05de1905d..535ebd792 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -430,8 +430,6 @@ export class ActorModel extends Model { } toActivityPubObject (this: MActorAP, name: string) { - let activityPubType - let icon = undefined if (this.avatarId) { const extension = extname(this.Avatar.filename) diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 6304f741c..68e2d562a 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -99,7 +99,7 @@ export class VideoFileModel extends Model { static doesInfohashExist (infoHash: string) { const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' const options = { - type: QueryTypes.SELECT, + type: QueryTypes.SELECT as QueryTypes.SELECT, bind: { infoHash }, raw: true } diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index a28021313..9d2ea710e 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts @@ -181,7 +181,7 @@ export class VideoPlaylistElementModel extends Model return VideoPlaylistElementModel.findOne(query) } - static loadById (playlistElementId: number): Bluebird { + static loadById (playlistElementId: number | string): Bluebird { return VideoPlaylistElementModel.findByPk(playlistElementId) } diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 9019b401a..50525b4c2 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -90,7 +90,7 @@ export class VideoShareModel extends Model { }) Video: VideoModel - static load (actorId: number, videoId: number, t?: Transaction): Bluebird { + static load (actorId: number | string, videoId: number | string, t?: Transaction): Bluebird { return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ where: { actorId, diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 0ee3feaf3..0d1dbf106 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1608,7 +1608,7 @@ export class VideoModel extends Model { 'LIMIT 1' const options = { - type: QueryTypes.SELECT, + type: QueryTypes.SELECT as QueryTypes.SELECT, bind: { followerActorId, videoId }, raw: true } -- cgit v1.2.3