Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix server lint

Chocobozzz99b757488c07
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index 67fac37516..f8a6071700 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -4,6 +4,7 @@ import { scheduleRefreshIfNeeded } from '@server/lib/activitypub/playlists'
import { Hooks } from '@server/lib/plugins/hooks'
import { getServerActor } from '@server/models/application/application'
import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/types/models'
+import { forceNumber } from '@shared/core-utils'
import { uuidToShort } from '@shared/extra-utils'
import { VideoPlaylistCreateResult, VideoPlaylistElementCreateResult } from '@shared/models'
import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
@@ -46,7 +47,6 @@ import {
import { AccountModel } from '../../models/account/account'
import { VideoPlaylistModel } from '../../models/video/video-playlist'
import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
-import { forceNumber } from '@shared/core-utils'
const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT)
@@ -425,7 +425,13 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
const endOldPosition = oldPosition + reorderLength - 1
// Insert our reordered elements in their place (update)
- await VideoPlaylistElementModel.reassignPositionOf({ videoPlaylistId: videoPlaylist.id, firstPosition: oldPosition, endPosition: endOldPosition, newPosition, transaction: t })
+ await VideoPlaylistElementModel.reassignPositionOf({
+ videoPlaylistId: videoPlaylist.id,
+ firstPosition: oldPosition,
+ endPosition: endOldPosition,
+ newPosition,
+ transaction: t
+ })
// Decrease positions of elements after the old position of our ordered elements (decrease)
await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, -reorderLength, t)
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts
index 17750379de..3dc5504e32 100644
--- a/server/helpers/custom-validators/misc.ts
+++ b/server/helpers/custom-validators/misc.ts
@@ -86,7 +86,7 @@ function isFileValid (options: {
// The file exists
const file = fileArray[0]
- if (!file || !file.originalname) return false
+ if (!file?.originalname) return false
// Check size
if ((maxSize !== null) && file.size > maxSize) return false
diff --git a/server/helpers/ffmpeg/ffmpeg-commons.ts b/server/helpers/ffmpeg/ffmpeg-commons.ts
index b019898993..3906a20892 100644
--- a/server/helpers/ffmpeg/ffmpeg-commons.ts
+++ b/server/helpers/ffmpeg/ffmpeg-commons.ts
@@ -38,7 +38,7 @@ function getFFmpegVersion () {
return execPromise(`${ffmpegPath} -version`)
.then(stdout => {
const parsed = stdout.match(/ffmpeg version .?(\d+\.\d+(\.\d+)?)/)
- if (!parsed || !parsed[1]) return rej(new Error(`Could not find ffmpeg version in ${stdout}`))
+ if (!parsed?.[1]) return rej(new Error(`Could not find ffmpeg version in ${stdout}`))
// Fix ffmpeg version that does not include patch version (4.4 for example)
let version = parsed[1]
diff --git a/server/helpers/youtube-dl/youtube-dl-wrapper.ts b/server/helpers/youtube-dl/youtube-dl-wrapper.ts
index 966b8df78e..ac3cd190e1 100644
--- a/server/helpers/youtube-dl/youtube-dl-wrapper.ts
+++ b/server/helpers/youtube-dl/youtube-dl-wrapper.ts
@@ -77,7 +77,7 @@ class YoutubeDLWrapper {
const subtitles = files.reduce((acc, filename) => {
const matched = filename.match(/\.([a-z]{2})(-[a-z]+)?\.(vtt|ttml)/i)
- if (!matched || !matched[1]) return acc
+ if (!matched?.[1]) return acc
return [
...acc,
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 66eb31230b..65940f4ae8 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -711,7 +711,7 @@ const PREVIEWS_SIZE = {
height: 480,
minWidth: 400
}
-const ACTOR_IMAGES_SIZE: { [key in ActorImageType]: { width: number, height: number }[]} = {
+const ACTOR_IMAGES_SIZE: { [key in ActorImageType]: { width: number, height: number }[] } = {
[ActorImageType.AVATAR]: [
{
width: 120,
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts
index 0fefcbbc56..af0dd510a9 100644
--- a/server/lib/activitypub/share.ts
+++ b/server/lib/activitypub/share.ts
@@ -57,7 +57,7 @@ export {
async function addVideoShare (shareUrl: string, video: MVideoId) {
const { body } = await doJSONRequest<any>(shareUrl, { activityPub: true })
- if (!body || !body.actor) throw new Error('Body or body actor is invalid')
+ if (!body?.actor) throw new Error('Body or body actor is invalid')
const actorUrl = getAPId(body.actor)
if (checkUrlsSameHost(shareUrl, actorUrl) !== true) {
diff --git a/server/lib/job-queue/handlers/activitypub-cleaner.ts b/server/lib/job-queue/handlers/activitypub-cleaner.ts
index 84c0a2de2b..a25f00b0a8 100644
--- a/server/lib/job-queue/handlers/activitypub-cleaner.ts
+++ b/server/lib/job-queue/handlers/activitypub-cleaner.ts
@@ -88,7 +88,7 @@ async function updateObjectIfNeeded <T> (options: {
const { body } = await doJSONRequest<any>(url, { activityPub: true })
// If not same id, check same host and update
- if (!body || !body.id || !bodyValidator(body)) throw new Error(`Body or body id of ${url} is invalid`)
+ if (!body?.id || !bodyValidator(body)) throw new Error(`Body or body id of ${url} is invalid`)
if (body.type === 'Tombstone') {
return on404OrTombstone()
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 83d582cb41..4d361c7b91 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -107,7 +107,7 @@ async function processYoutubeDLImport (job: Job, videoImport: MVideoImportDefaul
async function getVideoImportOrDie (payload: VideoImportPayload) {
const videoImport = await VideoImportModel.loadAndPopulateVideo(payload.videoImportId)
- if (!videoImport || !videoImport.Video) {
+ if (!videoImport?.Video) {
throw new Error(`Cannot import video ${payload.videoImportId}: the video import or video linked to this import does not exist anymore.`)
}
diff --git a/server/lib/moderation.ts b/server/lib/moderation.ts
index 3cc92ca302..dc5d8c83c3 100644
--- a/server/lib/moderation.ts
+++ b/server/lib/moderation.ts
@@ -220,7 +220,7 @@ async function createAbuse (options: {
base: FilteredModelAttributes<AbuseModel>
reporterAccount: MAccountDefault
flaggedAccount: MAccountLight
- associateFun: (abuseInstance: MAbuseFull) => Promise<{ isOwned: boolean} >
+ associateFun: (abuseInstance: MAbuseFull) => Promise<{ isOwned: boolean }>
skipNotification: boolean
transaction: Transaction
}) {
diff --git a/server/lib/schedulers/plugins-check-scheduler.ts b/server/lib/schedulers/plugins-check-scheduler.ts
index 06450fa01e..820c01693d 100644
--- a/server/lib/schedulers/plugins-check-scheduler.ts
+++ b/server/lib/schedulers/plugins-check-scheduler.ts
@@ -33,7 +33,7 @@ export class PluginsCheckScheduler extends AbstractScheduler {
const chunks = chunk(plugins, 10)
for (const chunk of chunks) {
// Find plugins according to their npm name
- const pluginIndex: { [npmName: string]: PluginModel} = {}
+ const pluginIndex: { [npmName: string]: PluginModel } = {}
for (const plugin of chunk) {
pluginIndex[PluginModel.buildNpmName(plugin.name, plugin.type)] = plugin
}
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts
index 0064a47608..261b9f6909 100644
--- a/server/middlewares/activitypub.ts
+++ b/server/middlewares/activitypub.ts
@@ -125,7 +125,7 @@ async function checkJsonLDSignature (req: Request, res: Response) {
return wrapWithSpanAndContext('peertube.activitypub.JSONLDSignature', async () => {
const signatureObject: ActivityPubSignature = req.body.signature
- if (!signatureObject || !signatureObject.creator) {
+ if (!signatureObject?.creator) {
res.fail({
status: HttpStatusCode.FORBIDDEN_403,
message: 'Object and creator signature do not match'
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts
index d01043c176..d8d3fc28b8 100644
--- a/server/middlewares/validators/user-subscriptions.ts
+++ b/server/middlewares/validators/user-subscriptions.ts
@@ -1,6 +1,6 @@
-import { arrayify } from '@shared/core-utils'
import express from 'express'
import { body, param, query } from 'express-validator'
+import { arrayify } from '@shared/core-utils'
import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
import { WEBSERVER } from '../../initializers/constants'
@@ -60,7 +60,7 @@ const userSubscriptionGetValidator = [
state: 'accepted'
})
- if (!subscription || !subscription.ActorFollowing.VideoChannel) {
+ if (!subscription?.ActorFollowing.VideoChannel) {
return res.fail({
status: HttpStatusCode.NOT_FOUND_404,
message: `Subscription ${req.params.uri} not found.`
diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts
index f85f48e86b..4c6a96a86d 100644
--- a/server/models/abuse/abuse.ts
+++ b/server/models/abuse/abuse.ts
@@ -436,7 +436,7 @@ export class AbuseModel extends Model<Partial<AttributesOnly<AbuseModel>>> {
buildBaseVideoCommentAbuse (this: MAbuseUserFormattable) {
// Associated video comment could have been destroyed if the video has been deleted
- if (!this.VideoCommentAbuse || !this.VideoCommentAbuse.VideoComment) return null
+ if (!this.VideoCommentAbuse?.VideoComment) return null
const entity = this.VideoCommentAbuse.VideoComment
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts
index 6a5d801823..71c205ffaa 100644
--- a/server/models/server/plugin.ts
+++ b/server/models/server/plugin.ts
@@ -122,7 +122,7 @@ export class PluginModel extends Model<Partial<AttributesOnly<PluginModel>>> {
return PluginModel.findOne(query)
.then(p => {
- if (!p || !p.settings || p.settings === undefined) {
+ if (!p?.settings || p.settings === undefined) {
const registered = registeredSettings.find(s => s.name === settingName)
if (!registered || registered.default === undefined) return undefined
@@ -152,7 +152,7 @@ export class PluginModel extends Model<Partial<AttributesOnly<PluginModel>>> {
const result: SettingEntries = {}
for (const name of settingNames) {
- if (!p || !p.settings || p.settings[name] === undefined) {
+ if (!p?.settings || p.settings[name] === undefined) {
const registered = registeredSettings.find(s => s.name === name)
if (registered?.default !== undefined) {
diff --git a/server/models/video/formatter/video-format-utils.ts b/server/models/video/formatter/video-format-utils.ts
index 240619f695..f285db477b 100644
--- a/server/models/video/formatter/video-format-utils.ts
+++ b/server/models/video/formatter/video-format-utils.ts
@@ -58,7 +58,7 @@ export type VideoFormattingJSONOptions = {
}
function guessAdditionalAttributesFromQuery (query: VideosCommonQueryAfterSanitize): VideoFormattingJSONOptions {
- if (!query || !query.include) return {}
+ if (!query?.include) return {}
return {
additionalAttributes: {
diff --git a/server/models/video/sql/video/shared/abstract-video-query-builder.ts b/server/models/video/sql/video/shared/abstract-video-query-builder.ts
index 3c74b0ea6c..f0ce69501a 100644
--- a/server/models/video/sql/video/shared/abstract-video-query-builder.ts
+++ b/server/models/video/sql/video/shared/abstract-video-query-builder.ts
@@ -302,7 +302,7 @@ export class AbstractVideoQueryBuilder extends AbstractRunQuery {
}
protected buildAttributesObject (prefixKey: string, attributeKeys: string[]) {
- const result: { [id: string]: string} = {}
+ const result: { [id: string]: string } = {}
const prefixValue = prefixKey.replace(/->/g, '.')
diff --git a/server/tests/api/live/live-fast-restream.ts b/server/tests/api/live/live-fast-restream.ts
index 971df1a618..c0bb8d529f 100644
--- a/server/tests/api/live/live-fast-restream.ts
+++ b/server/tests/api/live/live-fast-restream.ts
@@ -130,7 +130,7 @@ describe('Fast restream in live', function () {
})
it('Should correctly fast reastream in a permanent live with and without save replay', async function () {
- this.timeout(240000)
+ this.timeout(480000)
// A test can take a long time, so prefer to run them in parallel
await Promise.all([
diff --git a/shared/core-utils/i18n/i18n.ts b/shared/core-utils/i18n/i18n.ts
index abc7acc8b1..b720fb84e3 100644
--- a/shared/core-utils/i18n/i18n.ts
+++ b/shared/core-utils/i18n/i18n.ts
@@ -82,7 +82,7 @@ export function isDefaultLocale (locale: string) {
}
export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
- if (!translations || !translations[str]) return str
+ if (!translations?.[str]) return str
return translations[str]
}
diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts
index c062e69869..f2ca51431c 100644
--- a/shared/server-commands/server/server.ts
+++ b/shared/server-commands/server/server.ts
@@ -259,7 +259,7 @@ export class PeerTubeServer {
const onPeerTubeExit = () => rej(new Error('Process exited:\n' + aggregatedLogs))
const onParentExit = () => {
- if (!this.app || !this.app.pid) return
+ if (!this.app?.pid) return
try {
process.kill(self.app.pid)