diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/helpers/custom-validators/users.ts | 5 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 4 | ||||
-rw-r--r-- | server/initializers/checker-after-init.ts | 4 | ||||
-rw-r--r-- | server/lib/emailer.ts | 5 | ||||
-rw-r--r-- | server/lib/hls.ts | 7 | ||||
-rw-r--r-- | server/models/account/account-video-rate.ts | 3 | ||||
-rw-r--r-- | server/models/actor/actor-follow.ts | 4 | ||||
-rw-r--r-- | server/models/actor/actor.ts | 3 | ||||
-rw-r--r-- | server/models/user/user.ts | 3 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 4 | ||||
-rw-r--r-- | server/tools/peertube-redundancy.ts | 5 |
11 files changed, 21 insertions, 26 deletions
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 @@ | |||
1 | import { values } from 'lodash' | ||
2 | import validator from 'validator' | 1 | import validator from 'validator' |
3 | import { UserRole } from '@shared/models' | 2 | import { UserRole } from '@shared/models' |
4 | import { isEmailEnabled } from '../../initializers/config' | 3 | import { isEmailEnabled } from '../../initializers/config' |
@@ -44,9 +43,9 @@ function isUserEmailVerifiedValid (value: any) { | |||
44 | return isBooleanValid(value) | 43 | return isBooleanValid(value) |
45 | } | 44 | } |
46 | 45 | ||
47 | const nsfwPolicies = values(NSFW_POLICY_TYPES) | 46 | const nsfwPolicies = new Set(Object.values(NSFW_POLICY_TYPES)) |
48 | function isUserNSFWPolicyValid (value: any) { | 47 | function isUserNSFWPolicyValid (value: any) { |
49 | return exists(value) && nsfwPolicies.includes(value) | 48 | return exists(value) && nsfwPolicies.has(value) |
50 | } | 49 | } |
51 | 50 | ||
52 | function isUserP2PEnabledValid (value: any) { | 51 | 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 @@ | |||
1 | import { UploadFilesForCheck } from 'express' | 1 | import { UploadFilesForCheck } from 'express' |
2 | import { values } from 'lodash' | ||
3 | import magnetUtil from 'magnet-uri' | 2 | import magnetUtil from 'magnet-uri' |
4 | import validator from 'validator' | 3 | import validator from 'validator' |
5 | import { VideoFilter, VideoInclude, VideoPrivacy, VideoRateType } from '@shared/models' | 4 | import { VideoFilter, VideoInclude, VideoPrivacy, VideoRateType } from '@shared/models' |
@@ -78,8 +77,9 @@ function isVideoViewsValid (value: string) { | |||
78 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS) | 77 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS) |
79 | } | 78 | } |
80 | 79 | ||
80 | const ratingTypes = new Set(Object.values(VIDEO_RATE_TYPES)) | ||
81 | function isVideoRatingTypeValid (value: string) { | 81 | function isVideoRatingTypeValid (value: string) { |
82 | return value === 'none' || values(VIDEO_RATE_TYPES).includes(value as VideoRateType) | 82 | return value === 'none' || ratingTypes.has(value as VideoRateType) |
83 | } | 83 | } |
84 | 84 | ||
85 | function isVideoFileExtnameValid (value: string) { | 85 | 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 @@ | |||
1 | import config from 'config' | 1 | import config from 'config' |
2 | import { uniq } from 'lodash' | ||
3 | import { URL } from 'url' | 2 | import { URL } from 'url' |
4 | import { getFFmpegVersion } from '@server/helpers/ffmpeg' | 3 | import { getFFmpegVersion } from '@server/helpers/ffmpeg' |
4 | import { uniqify } from '@shared/core-utils' | ||
5 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' | 5 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' |
6 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' | 6 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' |
7 | import { isProdInstance, parseSemVersion } from '../helpers/core-utils' | 7 | import { isProdInstance, parseSemVersion } from '../helpers/core-utils' |
@@ -141,7 +141,7 @@ function checkLocalRedundancyConfig () { | |||
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | const filtered = uniq(redundancyVideos.map(r => r.strategy)) | 144 | const filtered = uniqify(redundancyVideos.map(r => r.strategy)) |
145 | if (filtered.length !== redundancyVideos.length) { | 145 | if (filtered.length !== redundancyVideos.length) { |
146 | throw new Error('Redundancy video entries should have unique strategies') | 146 | throw new Error('Redundancy video entries should have unique strategies') |
147 | } | 147 | } |
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' | |||
2 | import { merge } from 'lodash' | 2 | import { merge } from 'lodash' |
3 | import { createTransport, Transporter } from 'nodemailer' | 3 | import { createTransport, Transporter } from 'nodemailer' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import { toArray } from '@server/helpers/custom-validators/misc' | 5 | import { arrayify, root } from '@shared/core-utils' |
6 | import { root } from '@shared/core-utils' | ||
7 | import { EmailPayload } from '@shared/models' | 6 | import { EmailPayload } from '@shared/models' |
8 | import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model' | 7 | import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model' |
9 | import { isTestOrDevInstance } from '../helpers/core-utils' | 8 | import { isTestOrDevInstance } from '../helpers/core-utils' |
@@ -159,7 +158,7 @@ class Emailer { | |||
159 | subjectPrefix: CONFIG.EMAIL.SUBJECT.PREFIX | 158 | subjectPrefix: CONFIG.EMAIL.SUBJECT.PREFIX |
160 | }) | 159 | }) |
161 | 160 | ||
162 | const toEmails = toArray(options.to) | 161 | const toEmails = arrayify(options.to) |
163 | 162 | ||
164 | for (const to of toEmails) { | 163 | for (const to of toEmails) { |
165 | const baseOptions: SendEmailDefaultOptions = { | 164 | 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 @@ | |||
1 | import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra' | 1 | import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra' |
2 | import { flatten, uniq } from 'lodash' | 2 | import { flatten } from 'lodash' |
3 | import PQueue from 'p-queue' | 3 | import PQueue from 'p-queue' |
4 | import { basename, dirname, join } from 'path' | 4 | import { basename, dirname, join } from 'path' |
5 | import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models' | 5 | import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models' |
6 | import { uniqify } from '@shared/core-utils' | ||
6 | import { sha256 } from '@shared/extra-utils' | 7 | import { sha256 } from '@shared/extra-utils' |
7 | import { VideoStorage } from '@shared/models' | 8 | import { VideoStorage } from '@shared/models' |
8 | import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamDimensionsInfo } from '../helpers/ffmpeg' | 9 | import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamDimensionsInfo } from '../helpers/ffmpeg' |
@@ -182,7 +183,7 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, | |||
182 | const subPlaylistUrls = await fetchUniqUrls(playlistUrl) | 183 | const subPlaylistUrls = await fetchUniqUrls(playlistUrl) |
183 | 184 | ||
184 | const subRequests = subPlaylistUrls.map(u => fetchUniqUrls(u)) | 185 | const subRequests = subPlaylistUrls.map(u => fetchUniqUrls(u)) |
185 | const fileUrls = uniq(flatten(await Promise.all(subRequests))) | 186 | const fileUrls = uniqify(flatten(await Promise.all(subRequests))) |
186 | 187 | ||
187 | logger.debug('Will download %d HLS files.', fileUrls.length, { fileUrls }) | 188 | logger.debug('Will download %d HLS files.', fileUrls.length, { fileUrls }) |
188 | 189 | ||
@@ -227,7 +228,7 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, | |||
227 | return `${dirname(playlistUrl)}/${url}` | 228 | return `${dirname(playlistUrl)}/${url}` |
228 | }) | 229 | }) |
229 | 230 | ||
230 | return uniq(urls) | 231 | return uniqify(urls) |
231 | } | 232 | } |
232 | } | 233 | } |
233 | 234 | ||
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 @@ | |||
1 | import { values } from 'lodash' | ||
2 | import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize' | 1 | import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize' |
3 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { | 3 | import { |
@@ -45,7 +44,7 @@ import { AccountModel } from './account' | |||
45 | export class AccountVideoRateModel extends Model<Partial<AttributesOnly<AccountVideoRateModel>>> { | 44 | export class AccountVideoRateModel extends Model<Partial<AttributesOnly<AccountVideoRateModel>>> { |
46 | 45 | ||
47 | @AllowNull(false) | 46 | @AllowNull(false) |
48 | @Column(DataType.ENUM(...values(VIDEO_RATE_TYPES))) | 47 | @Column(DataType.ENUM(...Object.values(VIDEO_RATE_TYPES))) |
49 | type: VideoRateType | 48 | type: VideoRateType |
50 | 49 | ||
51 | @AllowNull(false) | 50 | @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 @@ | |||
1 | import { difference, values } from 'lodash' | 1 | import { difference } from 'lodash' |
2 | import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize' | 2 | import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize' |
3 | import { | 3 | import { |
4 | AfterCreate, | 4 | AfterCreate, |
@@ -69,7 +69,7 @@ import { InstanceListFollowingQueryBuilder, ListFollowingOptions } from './sql/i | |||
69 | export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowModel>>> { | 69 | export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowModel>>> { |
70 | 70 | ||
71 | @AllowNull(false) | 71 | @AllowNull(false) |
72 | @Column(DataType.ENUM(...values(FOLLOW_STATES))) | 72 | @Column(DataType.ENUM(...Object.values(FOLLOW_STATES))) |
73 | state: FollowState | 73 | state: FollowState |
74 | 74 | ||
75 | @AllowNull(false) | 75 | @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 @@ | |||
1 | import { values } from 'lodash' | ||
2 | import { literal, Op, QueryTypes, Transaction } from 'sequelize' | 1 | import { literal, Op, QueryTypes, Transaction } from 'sequelize' |
3 | import { | 2 | import { |
4 | AllowNull, | 3 | AllowNull, |
@@ -163,7 +162,7 @@ export const unusedActorAttributesForAPI = [ | |||
163 | export class ActorModel extends Model<Partial<AttributesOnly<ActorModel>>> { | 162 | export class ActorModel extends Model<Partial<AttributesOnly<ActorModel>>> { |
164 | 163 | ||
165 | @AllowNull(false) | 164 | @AllowNull(false) |
166 | @Column(DataType.ENUM(...values(ACTIVITY_PUB_ACTOR_TYPES))) | 165 | @Column(DataType.ENUM(...Object.values(ACTIVITY_PUB_ACTOR_TYPES))) |
167 | type: ActivityPubActorType | 166 | type: ActivityPubActorType |
168 | 167 | ||
169 | @AllowNull(false) | 168 | @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 @@ | |||
1 | import { values } from 'lodash' | ||
2 | import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' | 1 | import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' |
3 | import { | 2 | import { |
4 | AfterDestroy, | 3 | AfterDestroy, |
@@ -283,7 +282,7 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> { | |||
283 | 282 | ||
284 | @AllowNull(false) | 283 | @AllowNull(false) |
285 | @Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy')) | 284 | @Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy')) |
286 | @Column(DataType.ENUM(...values(NSFW_POLICY_TYPES))) | 285 | @Column(DataType.ENUM(...Object.values(NSFW_POLICY_TYPES))) |
287 | nsfwPolicy: NSFWPolicyType | 286 | nsfwPolicy: NSFWPolicyType |
288 | 287 | ||
289 | @AllowNull(false) | 288 | @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 @@ | |||
1 | import { uniq } from 'lodash' | ||
2 | import { FindOptions, Op, Order, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' | 1 | import { FindOptions, Op, Order, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' |
3 | import { | 2 | import { |
4 | AllowNull, | 3 | AllowNull, |
@@ -17,6 +16,7 @@ import { | |||
17 | import { exists } from '@server/helpers/custom-validators/misc' | 16 | import { exists } from '@server/helpers/custom-validators/misc' |
18 | import { getServerActor } from '@server/models/application/application' | 17 | import { getServerActor } from '@server/models/application/application' |
19 | import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' | 18 | import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' |
19 | import { uniqify } from '@shared/core-utils' | ||
20 | import { VideoPrivacy } from '@shared/models' | 20 | import { VideoPrivacy } from '@shared/models' |
21 | import { AttributesOnly } from '@shared/typescript-utils' | 21 | import { AttributesOnly } from '@shared/typescript-utils' |
22 | import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' | 22 | import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' |
@@ -802,7 +802,7 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment | |||
802 | ) | 802 | ) |
803 | } | 803 | } |
804 | 804 | ||
805 | return uniq(result) | 805 | return uniqify(result) |
806 | } | 806 | } |
807 | 807 | ||
808 | toFormattedJSON (this: MCommentFormattable) { | 808 | toFormattedJSON (this: MCommentFormattable) { |
diff --git a/server/tools/peertube-redundancy.ts b/server/tools/peertube-redundancy.ts index 2c62a3c19..4bb9fbc5a 100644 --- a/server/tools/peertube-redundancy.ts +++ b/server/tools/peertube-redundancy.ts | |||
@@ -1,13 +1,12 @@ | |||
1 | import CliTable3 from 'cli-table3' | 1 | import CliTable3 from 'cli-table3' |
2 | import { Command, program } from 'commander' | 2 | import { Command, program } from 'commander' |
3 | import { uniq } from 'lodash' | ||
4 | import { URL } from 'url' | 3 | import { URL } from 'url' |
5 | import validator from 'validator' | 4 | import validator from 'validator' |
5 | import { uniqify } from '@shared/core-utils' | ||
6 | import { HttpStatusCode, VideoRedundanciesTarget } from '@shared/models' | 6 | import { HttpStatusCode, VideoRedundanciesTarget } from '@shared/models' |
7 | import { assignToken, buildServer, getServerCredentials } from './cli' | 7 | import { assignToken, buildServer, getServerCredentials } from './cli' |
8 | 8 | ||
9 | import bytes = require('bytes') | 9 | import bytes = require('bytes') |
10 | |||
11 | program | 10 | program |
12 | .name('redundancy') | 11 | .name('redundancy') |
13 | .usage('[command] [options]') | 12 | .usage('[command] [options]') |
@@ -77,7 +76,7 @@ async function listRedundanciesCLI (target: VideoRedundanciesTarget) { | |||
77 | totalSize = bytes(tmp) | 76 | totalSize = bytes(tmp) |
78 | } | 77 | } |
79 | 78 | ||
80 | const instances = uniq( | 79 | const instances = uniqify( |
81 | webtorrentFiles.concat(streamingPlaylists) | 80 | webtorrentFiles.concat(streamingPlaylists) |
82 | .map(r => r.fileUrl) | 81 | .map(r => r.fileUrl) |
83 | .map(u => new URL(u).host) | 82 | .map(u => new URL(u).host) |