]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix server lint
authorChocobozzz <me@florianbigard.com>
Tue, 15 Nov 2022 14:00:19 +0000 (15:00 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 15 Nov 2022 14:00:23 +0000 (15:00 +0100)
19 files changed:
server/controllers/api/video-playlist.ts
server/helpers/custom-validators/misc.ts
server/helpers/ffmpeg/ffmpeg-commons.ts
server/helpers/youtube-dl/youtube-dl-wrapper.ts
server/initializers/constants.ts
server/lib/activitypub/share.ts
server/lib/job-queue/handlers/activitypub-cleaner.ts
server/lib/job-queue/handlers/video-import.ts
server/lib/moderation.ts
server/lib/schedulers/plugins-check-scheduler.ts
server/middlewares/activitypub.ts
server/middlewares/validators/user-subscriptions.ts
server/models/abuse/abuse.ts
server/models/server/plugin.ts
server/models/video/formatter/video-format-utils.ts
server/models/video/sql/video/shared/abstract-video-query-builder.ts
server/tests/api/live/live-fast-restream.ts
shared/core-utils/i18n/i18n.ts
shared/server-commands/server/server.ts

index 67fac375168b190a7051d39a65bfde7dba6d01c7..f8a607170082d9ca03dfeb885ac41d8c1cb05b7b 100644 (file)
@@ -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)
index 17750379de66946b186ef7d476b50ac1957891cf..3dc5504e32545d611c3b9a1d325621cd6613c87a 100644 (file)
@@ -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
index b0198989930ce853cf6b83e70f9e05a6af3d29ae..3906a2089246eeb9c7f4d82d09a683113f1f6903 100644 (file)
@@ -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]
index 966b8df78e096a6d96df3e76cdc67a800a8ecdf3..ac3cd190e1538ae3d544ac7fa2c3fed49e8ab01c 100644 (file)
@@ -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,
index 66eb31230b5cde07552cf0f3237f3fe2ecf31f95..65940f4ae8c83a456112d0448c3b0a83f48db5fd 100644 (file)
@@ -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,
index 0fefcbbc560fdfafb0febaa0d611ae9365803bc8..af0dd510a97bf4179e1b11e04245e7f37c948d28 100644 (file)
@@ -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) {
index 84c0a2de2bcafb9486782e41b553524daefee3b9..a25f00b0a8491dad5ead3ac7013940d00a0e4a56 100644 (file)
@@ -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()
index 83d582cb415083b86a8009c4fb94b06de68776cd..4d361c7b915762101ea2c7c3a776670733a4b5ff 100644 (file)
@@ -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.`)
   }
 
index 3cc92ca302599936d9ff4e594c9046225c4cc5cf..dc5d8c83c3592bc94235805255a4900cb4805581 100644 (file)
@@ -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
 }) {
index 06450fa01e2a935ad8deffbfe01e4556d2d4e9e3..820c01693d96cc5e06a8df9f8f94f4e88a9e1aab 100644 (file)
@@ -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
       }
index 0064a4760870a2aebd7639a8acee61e6fac1083f..261b9f690981370a38affc1eb580c6d00acaca8e 100644 (file)
@@ -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'
index d01043c176c8a6fb3490af8945e7adb388f3ddcc..d8d3fc28b8fb9e6756ab9bbb76071d414e44b5b4 100644 (file)
@@ -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.`
index f85f48e86b0d04e707de206ccebd0dc0147046b4..4c6a96a86d3f882c0afd06ca5035aa2118d8f3d9 100644 (file)
@@ -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
 
index 6a5d801823f42b0768c38357f168f620c10bebcd..71c205ffaa2fd1b1904c9e7b118f29e3ef0e6aab 100644 (file)
@@ -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) {
index 240619f6952ee5dfc6f0f24917584e1fd787f963..f285db477bf72e095f742433c82e7181ef6d5eb2 100644 (file)
@@ -58,7 +58,7 @@ export type VideoFormattingJSONOptions = {
 }
 
 function guessAdditionalAttributesFromQuery (query: VideosCommonQueryAfterSanitize): VideoFormattingJSONOptions {
-  if (!query || !query.include) return {}
+  if (!query?.include) return {}
 
   return {
     additionalAttributes: {
index 3c74b0ea6cc652768f6485a16538912d914ec600..f0ce69501aab1a2fd911658006cc305d6d73b0d8 100644 (file)
@@ -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, '.')
 
index 971df1a61880e716e31189f81793d34845d6ac3f..c0bb8d529f28f41a3a6b0a085d92f45abf9dc80a 100644 (file)
@@ -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([
index abc7acc8b1444ebaae73f3586284ff7e545e1fbc..b720fb84e3e06d11595f95434ad6345ddcefc965 100644 (file)
@@ -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]
 }
index c062e6986904f2bcf0601b159c3f944e8dd461d2..f2ca51431c6618e6e12b813d10c8a283b180c259 100644 (file)
@@ -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)