diff --git a/packages/tests/src/api/check-params/plugins.ts b/packages/tests/src/api/check-params/plugins.ts index ab2a426fe..7d1a28a62 100644 --- a/packages/tests/src/api/check-params/plugins.ts +++ b/packages/tests/src/api/check-params/plugins.ts @@ -96,14 +96,14 @@ describe('Test server plugins API validators', function () { it('Should fail with invalid paths', async function () { const paths = [ '/plugins/' + pluginName + '/' + npmVersion + '/static/images/../chocobo.png', - '/plugins/' + pluginName + '/' + npmVersion + '/client-scripts/../client/common-client-plugin.js', - '/themes/' + themeName + '/' + themeVersion + '/static/../images/chocobo.png', + '/plugins/' + pluginName + '/' + npmVersion + '/client-scripts/h/o/../client/common-client-plugin.js', + '/themes/' + themeName + '/' + themeVersion + '/static/hola/a/../images/chocobo.png', '/themes/' + themeName + '/' + themeVersion + '/client-scripts/client/video-watch-client-plugin.js/..', - '/themes/' + themeName + '/' + themeVersion + '/css/../assets/style1.css' + '/themes/' + themeName + '/' + themeVersion + '/css/hiha//j../assets/style1.css' ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) diff --git a/packages/tests/src/api/server/tracker.ts b/packages/tests/src/api/server/tracker.ts index 159b49c49..9c5600582 100644 --- a/packages/tests/src/api/server/tracker.ts +++ b/packages/tests/src/api/server/tracker.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */ -import WebTorrent from 'webtorrent' import { cleanupTests, createSingleServer, @@ -9,11 +8,13 @@ import { setAccessTokensToServers } from '@peertube/peertube-server-commands' import { magnetUriDecode, magnetUriEncode } from '@tests/shared/webtorrent.js' +import WebTorrent from 'webtorrent' describe('Test tracker', function () { let server: PeerTubeServer let badMagnet: string let goodMagnet: string + let webtorrent: WebTorrent.Instance before(async function () { this.timeout(60000) @@ -32,9 +33,15 @@ describe('Test tracker', function () { } }) - it('Should succeed with the correct infohash', function (done) { - const webtorrent = new WebTorrent() + beforeEach(() => { + webtorrent = new WebTorrent() + }) + afterEach(() => { + webtorrent.destroy() + }) + + it('Should succeed with the correct infohash', function (done) { const torrent = webtorrent.add(goodMagnet) torrent.on('error', done) @@ -54,8 +61,6 @@ describe('Test tracker', function () { killallServers([ server ]) .then(() => server.run({ tracker: { enabled: false } })) .then(() => { - const webtorrent = new WebTorrent() - const torrent = webtorrent.add(goodMagnet) torrent.on('error', done) @@ -78,14 +83,16 @@ describe('Test tracker', function () { killallServers([ server ]) .then(() => server.run()) .then(() => { - const webtorrent = new WebTorrent() - const torrent = webtorrent.add(badMagnet) torrent.on('error', done) - torrent.on('warning', warn => { + torrent.on('warning', function onWarn (warn) { const message = typeof warn === 'string' ? warn : warn.message - if (message.includes('Unknown infoHash ')) return done() + if (message.includes('Unknown infoHash ')) { + torrent.off('warning', onWarn) + + return done() + } }) torrent.on('done', () => done(new Error('No error on infohash'))) @@ -100,7 +107,7 @@ describe('Test tracker', function () { torrent.on('error', done) torrent.on('warning', warn => { const message = typeof warn === 'string' ? warn : warn.message - if (message.includes('Unsupported tracker protocol')) return done() + if (message.includes('Error connecting')) return done() }) }) diff --git a/server/core/initializers/checker-after-init.ts b/server/core/initializers/checker-after-init.ts index 34792b756..c76c2fb81 100644 --- a/server/core/initializers/checker-after-init.ts +++ b/server/core/initializers/checker-after-init.ts @@ -1,10 +1,11 @@ -import config from 'config' -import { readFileSync, writeFileSync } from 'fs' -import { URL } from 'url' import { uniqify } from '@peertube/peertube-core-utils' import { getFFmpegVersion } from '@peertube/peertube-ffmpeg' -import { RecentlyAddedStrategy, VideoRedundancyConfigFilter } from '@peertube/peertube-models' +import { VideoRedundancyConfigFilter } from '@peertube/peertube-models' import { isProdInstance } from '@peertube/peertube-node-utils' +import config from 'config' +import { readFileSync, writeFileSync } from 'fs' +import { basename } from 'path' +import { URL } from 'url' import { parseBytes, parseSemVersion } from '../helpers/core-utils.js' import { isArray } from '../helpers/custom-validators/misc.js' import { logger } from '../helpers/logger.js' @@ -13,7 +14,6 @@ import { OAuthClientModel } from '../models/oauth/oauth-client.js' import { UserModel } from '../models/user/user.js' import { CONFIG, getLocalConfigFilePath, isEmailEnabled, reloadConfig } from './config.js' import { WEBSERVER } from './constants.js' -import { basename } from 'path' async function checkActivityPubUrls () { const actor = await getServerActor() @@ -101,12 +101,8 @@ async function checkFFmpegVersion () { // --------------------------------------------------------------------------- export { - checkConfig, - clientsExist, - checkFFmpegVersion, - usersExist, applicationExist, - checkActivityPubUrls + checkActivityPubUrls, checkConfig, checkFFmpegVersion, clientsExist, usersExist } // --------------------------------------------------------------------------- @@ -194,7 +190,7 @@ function checkLocalRedundancyConfig () { throw new Error('Redundancy video entries should have unique strategies') } - const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy + const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) { throw new Error('Min views in recently added strategy is not a number') } diff --git a/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts b/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts index c87030019..9f6eb8b1b 100644 --- a/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts +++ b/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts @@ -52,7 +52,7 @@ export function getFileAttributesFromUrl ( videoOrPlaylist: MVideo | MStreamingPlaylistVideo, urls: (ActivityTagObject | ActivityUrlObject)[] ) { - const fileUrls = urls.filter(u => isAPVideoUrlObject(u)) as ActivityVideoUrlObject[] + const fileUrls = urls.filter(u => isAPVideoUrlObject(u)) if (fileUrls.length === 0) return [] const attributes: FilteredModelAttributes[] = [] @@ -107,14 +107,14 @@ export function getFileAttributesFromUrl ( } export function getStreamingPlaylistAttributesFromObject (video: MVideoId, videoObject: VideoObject) { - const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] + const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) if (playlistUrls.length === 0) return [] const attributes: (FilteredModelAttributes & { tagAPObject?: ActivityTagObject[] })[] = [] for (const playlistUrlObject of playlistUrls) { const segmentsSha256UrlObject = playlistUrlObject.tag.find(isAPPlaylistSegmentHashesUrlObject) - const files: unknown[] = playlistUrlObject.tag.filter(u => isAPVideoUrlObject(u)) as ActivityVideoUrlObject[] + const files: unknown[] = playlistUrlObject.tag.filter(u => isAPVideoUrlObject(u)) const attribute = { type: VideoStreamingPlaylistType.HLS, diff --git a/server/core/lib/job-queue/handlers/activitypub-refresher.ts b/server/core/lib/job-queue/handlers/activitypub-refresher.ts index ae238396e..5e85f4b4b 100644 --- a/server/core/lib/job-queue/handlers/activitypub-refresher.ts +++ b/server/core/lib/job-queue/handlers/activitypub-refresher.ts @@ -1,8 +1,8 @@ -import { Job } from 'bullmq' +import { RefreshPayload } from '@peertube/peertube-models' import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists/index.js' import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos/index.js' -import { loadVideoByUrl } from '@server/lib/model-loaders/index.js' -import { RefreshPayload } from '@peertube/peertube-models' +import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders/index.js' +import { Job } from 'bullmq' import { logger } from '../../../helpers/logger.js' import { ActorModel } from '../../../models/actor/actor.js' import { VideoPlaylistModel } from '../../../models/video/video-playlist.js' @@ -27,14 +27,14 @@ export { // --------------------------------------------------------------------------- async function refreshVideo (videoUrl: string) { - const fetchType = 'all' as 'all' + const fetchType = 'all' const syncParam = { rates: true, shares: true, comments: true } const videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType) if (videoFromDatabase) { const refreshOptions = { video: videoFromDatabase, - fetchedType: fetchType, + fetchedType: fetchType as VideoLoadByUrlType, syncParam } @@ -43,7 +43,7 @@ async function refreshVideo (videoUrl: string) { } async function refreshActor (actorUrl: string) { - const fetchType = 'all' as 'all' + const fetchType = 'all' const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl) if (actor) { diff --git a/server/core/middlewares/async.ts b/server/core/middlewares/async.ts index e1483ed09..04d85a95c 100644 --- a/server/core/middlewares/async.ts +++ b/server/core/middlewares/async.ts @@ -1,6 +1,6 @@ +import { ExpressPromiseHandler } from '@server/types/express-handler.js' import { NextFunction, Request, RequestHandler, Response } from 'express' import { ValidationChain } from 'express-validator' -import { ExpressPromiseHandler } from '@server/types/express-handler.js' import { retryTransactionWrapper } from '../helpers/database-utils.js' // Syntactic sugar to avoid try/catch in express controllers/middlewares @@ -15,7 +15,7 @@ function asyncMiddleware (fun: RequestPromiseHandler | RequestPromiseHandler[]) } try { - for (const f of (fun as RequestPromiseHandler[])) { + for (const f of fun) { await new Promise((resolve, reject) => { return asyncMiddleware(f)(req, res, err => { if (err) return reject(err) diff --git a/server/core/models/actor/actor.ts b/server/core/models/actor/actor.ts index d9586a9d7..c5d6c9eb3 100644 --- a/server/core/models/actor/actor.ts +++ b/server/core/models/actor/actor.ts @@ -354,7 +354,7 @@ export class ActorModel extends SequelizeModel { const options = { type: QueryTypes.SELECT as QueryTypes.SELECT, replacements: { videoId }, - plain: true as true, + plain: true, transaction }