aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/helpers/custom-validators/users.ts5
-rw-r--r--server/helpers/custom-validators/videos.ts4
-rw-r--r--server/initializers/checker-after-init.ts4
-rw-r--r--server/lib/emailer.ts5
-rw-r--r--server/lib/hls.ts7
-rw-r--r--server/models/account/account-video-rate.ts3
-rw-r--r--server/models/actor/actor-follow.ts4
-rw-r--r--server/models/actor/actor.ts3
-rw-r--r--server/models/user/user.ts3
-rw-r--r--server/models/video/video-comment.ts4
-rw-r--r--server/tools/peertube-redundancy.ts5
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 @@
1import { values } from 'lodash'
2import validator from 'validator' 1import validator from 'validator'
3import { UserRole } from '@shared/models' 2import { UserRole } from '@shared/models'
4import { isEmailEnabled } from '../../initializers/config' 3import { isEmailEnabled } from '../../initializers/config'
@@ -44,9 +43,9 @@ function isUserEmailVerifiedValid (value: any) {
44 return isBooleanValid(value) 43 return isBooleanValid(value)
45} 44}
46 45
47const nsfwPolicies = values(NSFW_POLICY_TYPES) 46const nsfwPolicies = new Set(Object.values(NSFW_POLICY_TYPES))
48function isUserNSFWPolicyValid (value: any) { 47function isUserNSFWPolicyValid (value: any) {
49 return exists(value) && nsfwPolicies.includes(value) 48 return exists(value) && nsfwPolicies.has(value)
50} 49}
51 50
52function isUserP2PEnabledValid (value: any) { 51function 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 @@
1import { UploadFilesForCheck } from 'express' 1import { UploadFilesForCheck } from 'express'
2import { values } from 'lodash'
3import magnetUtil from 'magnet-uri' 2import magnetUtil from 'magnet-uri'
4import validator from 'validator' 3import validator from 'validator'
5import { VideoFilter, VideoInclude, VideoPrivacy, VideoRateType } from '@shared/models' 4import { 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
80const ratingTypes = new Set(Object.values(VIDEO_RATE_TYPES))
81function isVideoRatingTypeValid (value: string) { 81function 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
85function isVideoFileExtnameValid (value: string) { 85function 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 @@
1import config from 'config' 1import config from 'config'
2import { uniq } from 'lodash'
3import { URL } from 'url' 2import { URL } from 'url'
4import { getFFmpegVersion } from '@server/helpers/ffmpeg' 3import { getFFmpegVersion } from '@server/helpers/ffmpeg'
4import { uniqify } from '@shared/core-utils'
5import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' 5import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type'
6import { RecentlyAddedStrategy } from '../../shared/models/redundancy' 6import { RecentlyAddedStrategy } from '../../shared/models/redundancy'
7import { isProdInstance, parseSemVersion } from '../helpers/core-utils' 7import { 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'
2import { merge } from 'lodash' 2import { merge } from 'lodash'
3import { createTransport, Transporter } from 'nodemailer' 3import { createTransport, Transporter } from 'nodemailer'
4import { join } from 'path' 4import { join } from 'path'
5import { toArray } from '@server/helpers/custom-validators/misc' 5import { arrayify, root } from '@shared/core-utils'
6import { root } from '@shared/core-utils'
7import { EmailPayload } from '@shared/models' 6import { EmailPayload } from '@shared/models'
8import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model' 7import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model'
9import { isTestOrDevInstance } from '../helpers/core-utils' 8import { 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 @@
1import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra' 1import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra'
2import { flatten, uniq } from 'lodash' 2import { flatten } from 'lodash'
3import PQueue from 'p-queue' 3import PQueue from 'p-queue'
4import { basename, dirname, join } from 'path' 4import { basename, dirname, join } from 'path'
5import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models' 5import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models'
6import { uniqify } from '@shared/core-utils'
6import { sha256 } from '@shared/extra-utils' 7import { sha256 } from '@shared/extra-utils'
7import { VideoStorage } from '@shared/models' 8import { VideoStorage } from '@shared/models'
8import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamDimensionsInfo } from '../helpers/ffmpeg' 9import { 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 @@
1import { values } from 'lodash'
2import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize' 1import { FindOptions, Op, QueryTypes, Transaction } from 'sequelize'
3import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
4import { 3import {
@@ -45,7 +44,7 @@ import { AccountModel } from './account'
45export class AccountVideoRateModel extends Model<Partial<AttributesOnly<AccountVideoRateModel>>> { 44export 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 @@
1import { difference, values } from 'lodash' 1import { difference } from 'lodash'
2import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize' 2import { Attributes, FindOptions, Includeable, IncludeOptions, Op, QueryTypes, Transaction, WhereAttributeHash } from 'sequelize'
3import { 3import {
4 AfterCreate, 4 AfterCreate,
@@ -69,7 +69,7 @@ import { InstanceListFollowingQueryBuilder, ListFollowingOptions } from './sql/i
69export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowModel>>> { 69export 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 @@
1import { values } from 'lodash'
2import { literal, Op, QueryTypes, Transaction } from 'sequelize' 1import { literal, Op, QueryTypes, Transaction } from 'sequelize'
3import { 2import {
4 AllowNull, 3 AllowNull,
@@ -163,7 +162,7 @@ export const unusedActorAttributesForAPI = [
163export class ActorModel extends Model<Partial<AttributesOnly<ActorModel>>> { 162export 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 @@
1import { values } from 'lodash'
2import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' 1import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize'
3import { 2import {
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 @@
1import { uniq } from 'lodash'
2import { FindOptions, Op, Order, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' 1import { FindOptions, Op, Order, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
3import { 2import {
4 AllowNull, 3 AllowNull,
@@ -17,6 +16,7 @@ import {
17import { exists } from '@server/helpers/custom-validators/misc' 16import { exists } from '@server/helpers/custom-validators/misc'
18import { getServerActor } from '@server/models/application/application' 17import { getServerActor } from '@server/models/application/application'
19import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' 18import { MAccount, MAccountId, MUserAccountId } from '@server/types/models'
19import { uniqify } from '@shared/core-utils'
20import { VideoPrivacy } from '@shared/models' 20import { VideoPrivacy } from '@shared/models'
21import { AttributesOnly } from '@shared/typescript-utils' 21import { AttributesOnly } from '@shared/typescript-utils'
22import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' 22import { 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 @@
1import CliTable3 from 'cli-table3' 1import CliTable3 from 'cli-table3'
2import { Command, program } from 'commander' 2import { Command, program } from 'commander'
3import { uniq } from 'lodash'
4import { URL } from 'url' 3import { URL } from 'url'
5import validator from 'validator' 4import validator from 'validator'
5import { uniqify } from '@shared/core-utils'
6import { HttpStatusCode, VideoRedundanciesTarget } from '@shared/models' 6import { HttpStatusCode, VideoRedundanciesTarget } from '@shared/models'
7import { assignToken, buildServer, getServerCredentials } from './cli' 7import { assignToken, buildServer, getServerCredentials } from './cli'
8 8
9import bytes = require('bytes') 9import bytes = require('bytes')
10
11program 10program
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)