Fix lint and tests

This commit is contained in:
Chocobozzz
2024-06-21 15:24:49 +02:00
parent 4f4d3adf73
commit 985e79f61e
7 changed files with 40 additions and 37 deletions

View File

@@ -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')
}

View File

@@ -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<VideoFileModel>[] = []
@@ -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<VideoStreamingPlaylistModel> & { 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,

View File

@@ -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) {

View File

@@ -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<void>((resolve, reject) => {
return asyncMiddleware(f)(req, res, err => {
if (err) return reject(err)

View File

@@ -354,7 +354,7 @@ export class ActorModel extends SequelizeModel<ActorModel> {
const options = {
type: QueryTypes.SELECT as QueryTypes.SELECT,
replacements: { videoId },
plain: true as true,
plain: true,
transaction
}