From faa9d434b4d681837ff2a87603337c2623419669 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 17 Jun 2020 10:55:40 +0200 Subject: Update server dependencies --- server/controllers/api/users/index.ts | 4 +--- server/controllers/api/videos/import.ts | 2 +- server/controllers/api/videos/index.ts | 4 ++-- server/lib/activitypub/actor.ts | 4 ++-- server/lib/activitypub/audience.ts | 2 +- server/middlewares/oauth.ts | 2 +- .../middlewares/validators/videos/video-imports.ts | 2 +- server/models/video/video-abuse.ts | 2 +- server/models/video/video.ts | 3 +-- server/tests/api/check-params/users.ts | 7 ------- server/tests/api/check-params/video-abuses.ts | 14 -------------- server/tests/api/check-params/video-imports.ts | 3 --- server/tests/api/check-params/video-playlists.ts | 3 --- server/tests/api/ci-2.sh | 2 +- server/tests/api/ci-4.sh | 2 +- .../api/notifications/comments-notifications.ts | 22 +++++++++++----------- server/tests/cli/optimize-old-videos.ts | 10 ++-------- server/tools/peertube-auth.ts | 2 +- server/typings/express.ts | 4 ++++ 19 files changed, 31 insertions(+), 63 deletions(-) (limited to 'server') diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index c488f720b..06a43d7a3 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -53,15 +53,13 @@ import { tokensRouter } from '@server/controllers/api/users/token' const auditLogger = auditLoggerFactory('users') -// @ts-ignore const signupRateLimiter = RateLimit({ windowMs: CONFIG.RATES_LIMIT.SIGNUP.WINDOW_MS, max: CONFIG.RATES_LIMIT.SIGNUP.MAX, skipFailedRequests: true }) -// @ts-ignore -const askSendEmailLimiter = new RateLimit({ +const askSendEmailLimiter = RateLimit({ windowMs: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.WINDOW_MS, max: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.MAX }) diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index b4f70a086..ec270148d 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -68,7 +68,7 @@ export { function addVideoImport (req: express.Request, res: express.Response) { if (req.body.targetUrl) return addYoutubeDLImport(req, res) - const file = req.files && req.files['torrentfile'] ? req.files['torrentfile'][0] : undefined + const file = req.files?.['torrentfile']?.[0] if (req.body.magnetUri || file) return addTorrentImport(req, res, file) } diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 8048c568c..3ca5a9192 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -317,11 +317,11 @@ async function updateVideo (req: express.Request, res: express.Response) { const hadPrivacyForFederation = videoInstance.hasPrivacyForFederation() // Process thumbnail or create it from the video - const thumbnailModel = req.files && req.files['thumbnailfile'] + const thumbnailModel = req.files?.['thumbnailfile'] ? await createVideoMiniatureFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.MINIATURE, false) : undefined - const previewModel = req.files && req.files['previewfile'] + const previewModel = req.files?.['previewfile'] ? await createVideoMiniatureFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW, false) : undefined diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index c743dcf3f..0e5742071 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts @@ -166,7 +166,7 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ actorInstance.followersUrl = attributes.followers actorInstance.followingUrl = attributes.following - if (attributes.endpoints && attributes.endpoints.sharedInbox) { + if (attributes.endpoints?.sharedInbox) { actorInstance.sharedInboxUrl = attributes.endpoints.sharedInbox } } @@ -457,7 +457,7 @@ async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode?: numbe followersUrl: actorJSON.followers, followingUrl: actorJSON.following, - sharedInboxUrl: actorJSON.endpoints && actorJSON.endpoints.sharedInbox + sharedInboxUrl: actorJSON.endpoints?.sharedInbox ? actorJSON.endpoints.sharedInbox : null }) diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts index 551d04ae3..4b30d1f6f 100644 --- a/server/lib/activitypub/audience.ts +++ b/server/lib/activitypub/audience.ts @@ -55,7 +55,7 @@ async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) { const videoAll = video as VideoModel - const videoActor = videoAll.VideoChannel && videoAll.VideoChannel.Account + const videoActor = videoAll.VideoChannel?.Account ? videoAll.VideoChannel.Account.Actor : await ActorModel.loadFromAccountByVideoId(video.id, t) diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index 9d0eaa51f..b1149174b 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts @@ -48,7 +48,7 @@ function authenticateSocket (socket: Socket, next: (err?: any) => void) { function authenticatePromiseIfNeeded (req: express.Request, res: express.Response, authenticateInQuery = false) { return new Promise(resolve => { // Already authenticated? (or tried to) - if (res.locals.oauth && res.locals.oauth.token.User) return resolve() + if (res.locals.oauth?.token.User) return resolve() if (res.locals.authenticated === false) return res.sendStatus(401) diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index e3d900a9e..d69aff118 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts @@ -38,7 +38,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([ logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body }) const user = res.locals.oauth.token.User - const torrentFile = req.files && req.files['torrentfile'] ? req.files['torrentfile'][0] : undefined + const torrentFile = req.files?.['torrentfile'] ? req.files['torrentfile'][0] : undefined if (areValidationErrors(req, res)) return cleanUpReqFiles(req) diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index e0cf50b59..40f0ce12b 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -394,7 +394,7 @@ export class VideoAbuseModel extends Model { name: video.name, nsfw: video.nsfw, deleted: !this.Video, - blacklisted: this.Video && this.Video.isBlacklisted(), + blacklisted: this.Video?.isBlacklisted() || false, thumbnailPath: this.Video?.getMiniatureStaticPath(), channel: this.Video?.VideoChannel.toFormattedJSON() || this.deletedVideo?.channel }, diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 1f590c02d..b4efb76ee 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1605,8 +1605,7 @@ export class VideoModel extends Model { } isBlocked () { - return (this.VideoChannel.Account.Actor.Server && this.VideoChannel.Account.Actor.Server.isBlocked()) || - this.VideoChannel.Account.isBlocked() + return this.VideoChannel.Account.Actor.Server?.isBlocked() || this.VideoChannel.Account.isBlocked() } getQualityFileBy (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 472fbda43..74f0a2d3f 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -55,8 +55,6 @@ describe('Test users API validators', function () { let moderatorAccessToken = '' let emailPort: number let overrideConfig: Object - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let channelId: number // --------------------------------------------------------------- @@ -129,11 +127,6 @@ describe('Test users API validators', function () { }) } - { - const res = await getMyUserInformation(server.url, server.accessToken) - channelId = res.body.videoChannels[0].id - } - { const res = await uploadVideo(server.url, server.accessToken, {}) videoId = res.body.video.id diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts index e643cb95e..a3fe00ffb 100644 --- a/server/tests/api/check-params/video-abuses.ts +++ b/server/tests/api/check-params/video-abuses.ts @@ -141,13 +141,6 @@ describe('Test video abuses API validators', function () { }) describe('When updating a video abuse', function () { - const basePath = '/api/v1/videos/' - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let path: string - - before(() => { - path = basePath + server.video.id + '/abuse/' + videoAbuseId - }) it('Should fail with a non authenticated user', async function () { await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401) @@ -179,13 +172,6 @@ describe('Test video abuses API validators', function () { }) describe('When deleting a video abuse', function () { - const basePath = '/api/v1/videos/' - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let path: string - - before(() => { - path = basePath + server.video.id + '/abuse/' + videoAbuseId - }) it('Should fail with a non authenticated user', async function () { await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index dbea39c48..3759e47c4 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -29,8 +29,6 @@ describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' let server: ServerInfo let userAccessToken = '' - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let accountName: string let channelId: number // --------------------------------------------------------------- @@ -50,7 +48,6 @@ describe('Test video imports API validator', function () { { const res = await getMyUserInformation(server.url, server.accessToken) channelId = res.body.videoChannels[0].id - accountName = res.body.account.name + '@' + res.body.account.host } }) diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 0410e737a..46ec00d46 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -36,8 +36,6 @@ describe('Test video playlists API validator', function () { let privatePlaylistUUID: string let watchLaterPlaylistId: number let videoId: number - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let videoId2: number let playlistElementId: number // --------------------------------------------------------------- @@ -52,7 +50,6 @@ describe('Test video playlists API validator', function () { userAccessToken = await generateUserAccessToken(server, 'user1') videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id - videoId2 = (await uploadVideoAndGetId({ server, videoName: 'video 2' })).id { const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER) diff --git a/server/tests/api/ci-2.sh b/server/tests/api/ci-2.sh index 52c839d12..016df1cfc 100644 --- a/server/tests/api/ci-2.sh +++ b/server/tests/api/ci-2.sh @@ -5,6 +5,6 @@ set -eu serverFiles=$(find server/tests/api/server -type f | grep -v index.ts | xargs echo) usersFiles=$(find server/tests/api/users -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true npm run mocha-parallel-tests -- --max-parallel $1 --timeout 30000 --exit \ +MOCHA_PARALLEL=true npm run mocha -- --parallel --jobs $1 --timeout 30000 --exit \ --require ts-node/register --require tsconfig-paths/register --bail \ $serverFiles $usersFiles diff --git a/server/tests/api/ci-4.sh b/server/tests/api/ci-4.sh index 22785cf33..7d83cbdfc 100644 --- a/server/tests/api/ci-4.sh +++ b/server/tests/api/ci-4.sh @@ -5,6 +5,6 @@ set -eu redundancyFiles=$(find server/tests/api/redundancy -type f | grep -v index.ts | xargs echo) activitypubFiles=$(find server/tests/api/activitypub -type f | grep -v index.ts | xargs echo) -MOCHA_PARALLEL=true npm run mocha-parallel-tests -- --max-parallel $1 --timeout 30000 --exit \ +MOCHA_PARALLEL=true npm run mocha -- --parallel --jobs $1 --timeout 30000 --exit \ --require ts-node/register --require tsconfig-paths/register --bail \ $redundancyFiles $activitypubFiles diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index cd3ed2f70..dfe846cc4 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, getVideoCommentThreads, getVideoThreadComments, updateMyUser, wait } from '../../../../shared/extra-utils' +import { cleanupTests, getVideoCommentThreads, getVideoThreadComments, updateMyUser } from '../../../../shared/extra-utils' import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' @@ -56,7 +56,7 @@ describe('Test comments notifications', function () { const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') }) @@ -69,7 +69,7 @@ describe('Test comments notifications', function () { const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') }) @@ -84,7 +84,7 @@ describe('Test comments notifications', function () { const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') @@ -99,7 +99,7 @@ describe('Test comments notifications', function () { const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') }) @@ -134,7 +134,7 @@ describe('Test comments notifications', function () { const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') }) @@ -200,7 +200,7 @@ describe('Test comments notifications', function () { const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') }) @@ -213,7 +213,7 @@ describe('Test comments notifications', function () { const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') }) @@ -228,7 +228,7 @@ describe('Test comments notifications', function () { const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') @@ -257,13 +257,13 @@ describe('Test comments notifications', function () { const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') const threadId = resThread.body.comment.id - await wait(500) + await waitJobs(servers) await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1') const commentId = resComment.body.comment.id - await wait(500) + await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') }) diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts index e2e13598f..43f9b7f55 100644 --- a/server/tests/cli/optimize-old-videos.ts +++ b/server/tests/cli/optimize-old-videos.ts @@ -28,10 +28,6 @@ const expect = chai.expect describe('Test optimize old videos', function () { let servers: ServerInfo[] = [] - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let video1UUID: string - // eslint-disable-next-line @typescript-eslint/no-unused-vars - let video2UUID: string before(async function () { this.timeout(200000) @@ -52,10 +48,8 @@ describe('Test optimize old videos', function () { } // Upload two videos for our needs - const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1', fixture: tempFixturePath }) - video1UUID = res1.body.video.uuid - const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2', fixture: tempFixturePath }) - video2UUID = res2.body.video.uuid + await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1', fixture: tempFixturePath }) + await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2', fixture: tempFixturePath }) await waitJobs(servers) }) diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts index c1a804f83..74bce7314 100644 --- a/server/tools/peertube-auth.ts +++ b/server/tools/peertube-auth.ts @@ -28,7 +28,7 @@ async function delInstance (url: string) { async function setInstance (url: string, username: string, password: string, isDefault: boolean) { const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) - if (settings.remotes.indexOf(url) === -1) { + if (settings.remotes.includes(url) === false) { settings.remotes.push(url) } diff --git a/server/typings/express.ts b/server/typings/express.ts index 5973496f1..15d445c2d 100644 --- a/server/typings/express.ts +++ b/server/typings/express.ts @@ -32,6 +32,10 @@ import { UserRole } from '@shared/models' import { RegisterServerAuthExternalOptions } from '@shared/models/plugins/register-server-auth.model' declare module 'express' { + interface Request { + query: any + } + interface Response { locals: { -- cgit v1.2.3