aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-17 15:36:03 +0200
committerChocobozzz <me@florianbigard.com>2022-08-17 15:36:03 +0200
commit690bb8f9f3413147a4f71d5ff0a3cd8170a94ce3 (patch)
treeb16b8536acd2098aba8c1d6fe13a336dd6aa01a9
parentbbd5aa7ead5f1554a0872963f957effc26d8c630 (diff)
downloadPeerTube-690bb8f9f3413147a4f71d5ff0a3cd8170a94ce3.tar.gz
PeerTube-690bb8f9f3413147a4f71d5ff0a3cd8170a94ce3.tar.zst
PeerTube-690bb8f9f3413147a4f71d5ff0a3cd8170a94ce3.zip
Prefer using Object.values
-rw-r--r--client/src/app/helpers/utils/object.ts4
-rw-r--r--client/src/app/shared/shared-search/advanced-search.model.ts12
-rw-r--r--client/src/app/shared/shared-video-miniature/video-filters.model.ts6
-rwxr-xr-xscripts/i18n/create-custom-files.ts15
-rwxr-xr-xscripts/prune-storage.ts6
-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
-rw-r--r--shared/core-utils/common/array.ts6
17 files changed, 48 insertions, 48 deletions
diff --git a/client/src/app/helpers/utils/object.ts b/client/src/app/helpers/utils/object.ts
index 1ca4a23ac..69b2b18c0 100644
--- a/client/src/app/helpers/utils/object.ts
+++ b/client/src/app/helpers/utils/object.ts
@@ -18,7 +18,7 @@ function sortBy (obj: any[], key1: string, key2?: string) {
18 }) 18 })
19} 19}
20 20
21function intoArray (value: any) { 21function splitIntoArray (value: any) {
22 if (!value) return undefined 22 if (!value) return undefined
23 if (Array.isArray(value)) return value 23 if (Array.isArray(value)) return value
24 24
@@ -42,6 +42,6 @@ export {
42 sortBy, 42 sortBy,
43 immutableAssign, 43 immutableAssign,
44 removeElementFromArray, 44 removeElementFromArray,
45 intoArray, 45 splitIntoArray,
46 toBoolean 46 toBoolean
47} 47}
diff --git a/client/src/app/shared/shared-search/advanced-search.model.ts b/client/src/app/shared/shared-search/advanced-search.model.ts
index ea9baa27f..e8bb00fd3 100644
--- a/client/src/app/shared/shared-search/advanced-search.model.ts
+++ b/client/src/app/shared/shared-search/advanced-search.model.ts
@@ -1,4 +1,4 @@
1import { intoArray } from '@app/helpers' 1import { splitIntoArray } from '@app/helpers'
2import { 2import {
3 BooleanBothQuery, 3 BooleanBothQuery,
4 BooleanQuery, 4 BooleanQuery,
@@ -76,8 +76,8 @@ export class AdvancedSearch {
76 this.categoryOneOf = options.categoryOneOf || undefined 76 this.categoryOneOf = options.categoryOneOf || undefined
77 this.licenceOneOf = options.licenceOneOf || undefined 77 this.licenceOneOf = options.licenceOneOf || undefined
78 this.languageOneOf = options.languageOneOf || undefined 78 this.languageOneOf = options.languageOneOf || undefined
79 this.tagsOneOf = intoArray(options.tagsOneOf) 79 this.tagsOneOf = splitIntoArray(options.tagsOneOf)
80 this.tagsAllOf = intoArray(options.tagsAllOf) 80 this.tagsAllOf = splitIntoArray(options.tagsAllOf)
81 this.durationMin = options.durationMin ? parseInt(options.durationMin, 10) : undefined 81 this.durationMin = options.durationMin ? parseInt(options.durationMin, 10) : undefined
82 this.durationMax = options.durationMax ? parseInt(options.durationMax, 10) : undefined 82 this.durationMax = options.durationMax ? parseInt(options.durationMax, 10) : undefined
83 83
@@ -152,9 +152,9 @@ export class AdvancedSearch {
152 originallyPublishedStartDate: this.originallyPublishedStartDate, 152 originallyPublishedStartDate: this.originallyPublishedStartDate,
153 originallyPublishedEndDate: this.originallyPublishedEndDate, 153 originallyPublishedEndDate: this.originallyPublishedEndDate,
154 nsfw: this.nsfw, 154 nsfw: this.nsfw,
155 categoryOneOf: intoArray(this.categoryOneOf), 155 categoryOneOf: splitIntoArray(this.categoryOneOf),
156 licenceOneOf: intoArray(this.licenceOneOf), 156 licenceOneOf: splitIntoArray(this.licenceOneOf),
157 languageOneOf: intoArray(this.languageOneOf), 157 languageOneOf: splitIntoArray(this.languageOneOf),
158 tagsOneOf: this.tagsOneOf, 158 tagsOneOf: this.tagsOneOf,
159 tagsAllOf: this.tagsAllOf, 159 tagsAllOf: this.tagsAllOf,
160 durationMin: this.durationMin, 160 durationMin: this.durationMin,
diff --git a/client/src/app/shared/shared-video-miniature/video-filters.model.ts b/client/src/app/shared/shared-video-miniature/video-filters.model.ts
index 8ad2fcd5d..73a30ca08 100644
--- a/client/src/app/shared/shared-video-miniature/video-filters.model.ts
+++ b/client/src/app/shared/shared-video-miniature/video-filters.model.ts
@@ -1,4 +1,4 @@
1import { intoArray, toBoolean } from '@app/helpers' 1import { splitIntoArray, toBoolean } from '@app/helpers'
2import { getAllPrivacies } from '@shared/core-utils' 2import { getAllPrivacies } from '@shared/core-utils'
3import { AttributesOnly } from '@shared/typescript-utils' 3import { AttributesOnly } from '@shared/typescript-utils'
4import { BooleanBothQuery, NSFWPolicyType, VideoInclude, VideoPrivacy, VideoSortField } from '@shared/models' 4import { BooleanBothQuery, NSFWPolicyType, VideoInclude, VideoPrivacy, VideoSortField } from '@shared/models'
@@ -94,8 +94,8 @@ export class VideoFilters {
94 94
95 if (obj.nsfw !== undefined) this.nsfw = obj.nsfw 95 if (obj.nsfw !== undefined) this.nsfw = obj.nsfw
96 96
97 if (obj.languageOneOf !== undefined) this.languageOneOf = intoArray(obj.languageOneOf) 97 if (obj.languageOneOf !== undefined) this.languageOneOf = splitIntoArray(obj.languageOneOf)
98 if (obj.categoryOneOf !== undefined) this.categoryOneOf = intoArray(obj.categoryOneOf) 98 if (obj.categoryOneOf !== undefined) this.categoryOneOf = splitIntoArray(obj.categoryOneOf)
99 99
100 if (obj.scope !== undefined) this.scope = obj.scope 100 if (obj.scope !== undefined) this.scope = obj.scope
101 if (obj.allVideos !== undefined) this.allVideos = toBoolean(obj.allVideos) 101 if (obj.allVideos !== undefined) this.allVideos = toBoolean(obj.allVideos)
diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts
index e52909c43..8179cb43f 100755
--- a/scripts/i18n/create-custom-files.ts
+++ b/scripts/i18n/create-custom-files.ts
@@ -1,5 +1,4 @@
1import { writeJSON } from 'fs-extra' 1import { writeJSON } from 'fs-extra'
2import { values } from 'lodash'
3import { join } from 'path' 2import { join } from 'path'
4import { root } from '@shared/core-utils' 3import { root } from '@shared/core-utils'
5import { 4import {
@@ -65,13 +64,13 @@ Object.assign(playerKeys, videojs)
65 64
66// Server keys 65// Server keys
67const serverKeys: any = {} 66const serverKeys: any = {}
68values(VIDEO_CATEGORIES) 67Object.values(VIDEO_CATEGORIES)
69 .concat(values(VIDEO_LICENCES)) 68 .concat(Object.values(VIDEO_LICENCES))
70 .concat(values(VIDEO_PRIVACIES)) 69 .concat(Object.values(VIDEO_PRIVACIES))
71 .concat(values(VIDEO_STATES)) 70 .concat(Object.values(VIDEO_STATES))
72 .concat(values(VIDEO_IMPORT_STATES)) 71 .concat(Object.values(VIDEO_IMPORT_STATES))
73 .concat(values(VIDEO_PLAYLIST_PRIVACIES)) 72 .concat(Object.values(VIDEO_PLAYLIST_PRIVACIES))
74 .concat(values(VIDEO_PLAYLIST_TYPES)) 73 .concat(Object.values(VIDEO_PLAYLIST_TYPES))
75 .concat([ 74 .concat([
76 'This video does not exist.', 75 'This video does not exist.',
77 'We cannot fetch the video. Please try again later.', 76 'We cannot fetch the video. Please try again later.',
diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts
index bb1e8e024..3012bdb94 100755
--- a/scripts/prune-storage.ts
+++ b/scripts/prune-storage.ts
@@ -1,11 +1,11 @@
1import { map } from 'bluebird' 1import { map } from 'bluebird'
2import { readdir, remove, stat } from 'fs-extra' 2import { readdir, remove, stat } from 'fs-extra'
3import { uniq, values } from 'lodash'
4import { basename, join } from 'path' 3import { basename, join } from 'path'
5import { get, start } from 'prompt' 4import { get, start } from 'prompt'
6import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' 5import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
7import { VideoFileModel } from '@server/models/video/video-file' 6import { VideoFileModel } from '@server/models/video/video-file'
8import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' 7import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
8import { uniqify } from '@shared/core-utils'
9import { ThumbnailType } from '@shared/models' 9import { ThumbnailType } from '@shared/models'
10import { getUUIDFromFilename } from '../server/helpers/utils' 10import { getUUIDFromFilename } from '../server/helpers/utils'
11import { CONFIG } from '../server/initializers/config' 11import { CONFIG } from '../server/initializers/config'
@@ -23,9 +23,9 @@ run()
23 }) 23 })
24 24
25async function run () { 25async function run () {
26 const dirs = values(CONFIG.STORAGE) 26 const dirs = Object.values(CONFIG.STORAGE)
27 27
28 if (uniq(dirs).length !== dirs.length) { 28 if (uniqify(dirs).length !== dirs.length) {
29 console.error('Cannot prune storage because you put multiple storage keys in the same directory.') 29 console.error('Cannot prune storage because you put multiple storage keys in the same directory.')
30 process.exit(0) 30 process.exit(0)
31 } 31 }
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)
diff --git a/shared/core-utils/common/array.ts b/shared/core-utils/common/array.ts
index 95393c731..e1b422165 100644
--- a/shared/core-utils/common/array.ts
+++ b/shared/core-utils/common/array.ts
@@ -15,7 +15,13 @@ function arrayify <T> (element: T | T[]) {
15 return [ element ] 15 return [ element ]
16} 16}
17 17
18// Avoid conflict with other uniq() functions
19function uniqify <T> (elements: T[]) {
20 return Array.from(new Set(elements))
21}
22
18export { 23export {
24 uniqify,
19 findCommonElement, 25 findCommonElement,
20 arrayify 26 arrayify
21} 27}