From 690bb8f9f3413147a4f71d5ff0a3cd8170a94ce3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 17 Aug 2022 15:36:03 +0200 Subject: Prefer using Object.values --- server/helpers/custom-validators/users.ts | 5 ++--- server/helpers/custom-validators/videos.ts | 4 ++-- server/initializers/checker-after-init.ts | 4 ++-- server/lib/emailer.ts | 5 ++--- server/lib/hls.ts | 7 ++++--- server/models/account/account-video-rate.ts | 3 +-- server/models/actor/actor-follow.ts | 4 ++-- server/models/actor/actor.ts | 3 +-- server/models/user/user.ts | 3 +-- server/models/video/video-comment.ts | 4 ++-- server/tools/peertube-redundancy.ts | 5 ++--- 11 files changed, 21 insertions(+), 26 deletions(-) (limited to 'server') diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 8a6f6fca1..9df550fc2 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -1,4 +1,3 @@ -import { values } from 'lodash' import validator from 'validator' import { UserRole } from '@shared/models' import { isEmailEnabled } from '../../initializers/config' @@ -44,9 +43,9 @@ function isUserEmailVerifiedValid (value: any) { return isBooleanValid(value) } -const nsfwPolicies = values(NSFW_POLICY_TYPES) +const nsfwPolicies = new Set(Object.values(NSFW_POLICY_TYPES)) function isUserNSFWPolicyValid (value: any) { - return exists(value) && nsfwPolicies.includes(value) + return exists(value) && nsfwPolicies.has(value) } function isUserP2PEnabledValid (value: any) { diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index ca5f70fdc..3ebfe2937 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -1,5 +1,4 @@ import { UploadFilesForCheck } from 'express' -import { values } from 'lodash' import magnetUtil from 'magnet-uri' import validator from 'validator' import { VideoFilter, VideoInclude, VideoPrivacy, VideoRateType } from '@shared/models' @@ -78,8 +77,9 @@ function isVideoViewsValid (value: string) { return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS) } +const ratingTypes = new Set(Object.values(VIDEO_RATE_TYPES)) function isVideoRatingTypeValid (value: string) { - return value === 'none' || values(VIDEO_RATE_TYPES).includes(value as VideoRateType) + return value === 'none' || ratingTypes.has(value as VideoRateType) } function isVideoFileExtnameValid (value: string) { diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts index 74c82541e..42839d1c9 100644 --- a/server/initializers/checker-after-init.ts +++ b/server/initializers/checker-after-init.ts @@ -1,7 +1,7 @@ import config from 'config' -import { uniq } from 'lodash' import { URL } from 'url' import { getFFmpegVersion } from '@server/helpers/ffmpeg' +import { uniqify } from '@shared/core-utils' import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' import { RecentlyAddedStrategy } from '../../shared/models/redundancy' import { isProdInstance, parseSemVersion } from '../helpers/core-utils' @@ -141,7 +141,7 @@ function checkLocalRedundancyConfig () { } } - const filtered = uniq(redundancyVideos.map(r => r.strategy)) + const filtered = uniqify(redundancyVideos.map(r => r.strategy)) if (filtered.length !== redundancyVideos.length) { throw new Error('Redundancy video entries should have unique strategies') } diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 3cdba5c76..39b662eb2 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts @@ -2,8 +2,7 @@ import { readFileSync } from 'fs-extra' import { merge } from 'lodash' import { createTransport, Transporter } from 'nodemailer' import { join } from 'path' -import { toArray } from '@server/helpers/custom-validators/misc' -import { root } from '@shared/core-utils' +import { arrayify, root } from '@shared/core-utils' import { EmailPayload } from '@shared/models' import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model' import { isTestOrDevInstance } from '../helpers/core-utils' @@ -159,7 +158,7 @@ class Emailer { subjectPrefix: CONFIG.EMAIL.SUBJECT.PREFIX }) - const toEmails = toArray(options.to) + const toEmails = arrayify(options.to) for (const to of toEmails) { const baseOptions: SendEmailDefaultOptions = { diff --git a/server/lib/hls.ts b/server/lib/hls.ts index 9ec931b4f..a0a5afc0f 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -1,8 +1,9 @@ import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra' -import { flatten, uniq } from 'lodash' +import { flatten } from 'lodash' import PQueue from 'p-queue' import { basename, dirname, join } from 'path' import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models' +import { uniqify } from '@shared/core-utils' import { sha256 } from '@shared/extra-utils' import { VideoStorage } from '@shared/models' import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamDimensionsInfo } from '../helpers/ffmpeg' @@ -182,7 +183,7 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, const subPlaylistUrls = await fetchUniqUrls(playlistUrl) const subRequests = subPlaylistUrls.map(u => fetchUniqUrls(u)) - const fileUrls = uniq(flatten(await Promise.all(subRequests))) + const fileUrls = uniqify(flatten(await Promise.all(subRequests))) logger.debug('Will download %d HLS files.', fileUrls.length, { fileUrls }) @@ -227,7 +228,7 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, return `${dirname(playlistUrl)}/${url}` }) - return uniq(urls) + return uniqify(urls) } } diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index 5c7d9cfc0..7afc907da 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts @@ -1,4 +1,3 @@ -import { values } from 'lodash' import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { @@ -45,7 +44,7 @@ import { AccountModel } from './account' export class AccountVideoRateModel extends Model>> { @AllowNull(false) - @Column(DataType.ENUM(...values(VIDEO_RATE_TYPES))) + @Column(DataType.ENUM(...Object.values(VIDEO_RATE_TYPES))) type: VideoRateType @AllowNull(false) diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts index 127b29ad7..9615229dd 100644 --- a/server/models/actor/actor-follow.ts +++ b/server/models/actor/actor-follow.ts @@ -1,4 +1,4 @@ -import { difference, values } from 'lodash' +import { difference } from 'lodash' import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize' import { AfterCreate, @@ -69,7 +69,7 @@ import { InstanceListFollowingQueryBuilder, ListFollowingOptions } from './sql/i export class ActorFollowModel extends Model>> { @AllowNull(false) - @Column(DataType.ENUM(...values(FOLLOW_STATES))) + @Column(DataType.ENUM(...Object.values(FOLLOW_STATES))) state: FollowState @AllowNull(false) diff --git a/server/models/actor/actor.ts b/server/models/actor/actor.ts index 7be5a140c..88db241dc 100644 --- a/server/models/actor/actor.ts +++ b/server/models/actor/actor.ts @@ -1,4 +1,3 @@ -import { values } from 'lodash' import { literal, Op, QueryTypes, Transaction } from 'sequelize' import { AllowNull, @@ -163,7 +162,7 @@ export const unusedActorAttributesForAPI = [ export class ActorModel extends Model>> { @AllowNull(false) - @Column(DataType.ENUM(...values(ACTIVITY_PUB_ACTOR_TYPES))) + @Column(DataType.ENUM(...Object.values(ACTIVITY_PUB_ACTOR_TYPES))) type: ActivityPubActorType @AllowNull(false) diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 3fd359359..a2c2497fd 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts @@ -1,4 +1,3 @@ -import { values } from 'lodash' import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' import { AfterDestroy, @@ -283,7 +282,7 @@ export class UserModel extends Model>> { @AllowNull(false) @Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy')) - @Column(DataType.ENUM(...values(NSFW_POLICY_TYPES))) + @Column(DataType.ENUM(...Object.values(NSFW_POLICY_TYPES))) nsfwPolicy: NSFWPolicyType @AllowNull(false) diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 1195e47e9..af9614d30 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -1,4 +1,3 @@ -import { uniq } from 'lodash' import { FindOptions, Op, Order, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' import { AllowNull, @@ -17,6 +16,7 @@ import { import { exists } from '@server/helpers/custom-validators/misc' import { getServerActor } from '@server/models/application/application' import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' +import { uniqify } from '@shared/core-utils' import { VideoPrivacy } from '@shared/models' import { AttributesOnly } from '@shared/typescript-utils' import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' @@ -802,7 +802,7 @@ export class VideoCommentModel extends Model r.fileUrl) .map(u => new URL(u).host) -- cgit v1.2.3