diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/helpers | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/follows.ts | 20 | ||||
-rw-r--r-- | server/helpers/custom-validators/servers.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-ownership.ts | 2 | ||||
-rw-r--r-- | server/helpers/database-utils.ts | 10 | ||||
-rw-r--r-- | server/helpers/express-utils.ts | 2 | ||||
-rw-r--r-- | server/helpers/youtube-dl.ts | 2 |
6 files changed, 26 insertions, 11 deletions
diff --git a/server/helpers/custom-validators/follows.ts b/server/helpers/custom-validators/follows.ts index fbef7ad87..8f65552c3 100644 --- a/server/helpers/custom-validators/follows.ts +++ b/server/helpers/custom-validators/follows.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { exists } from './misc' | 1 | import { exists, isArray } from './misc' |
2 | import { FollowState } from '@shared/models' | 2 | import { FollowState } from '@shared/models' |
3 | 3 | ||
4 | function isFollowStateValid (value: FollowState) { | 4 | function isFollowStateValid (value: FollowState) { |
@@ -7,8 +7,24 @@ function isFollowStateValid (value: FollowState) { | |||
7 | return value === 'pending' || value === 'accepted' | 7 | return value === 'pending' || value === 'accepted' |
8 | } | 8 | } |
9 | 9 | ||
10 | function isRemoteHandleValid (value: string) { | ||
11 | if (!exists(value)) return false | ||
12 | if (typeof value !== 'string') return false | ||
13 | |||
14 | return value.includes('@') | ||
15 | } | ||
16 | |||
17 | function isEachUniqueHandleValid (handles: string[]) { | ||
18 | return isArray(handles) && | ||
19 | handles.every(handle => { | ||
20 | return isRemoteHandleValid(handle) && handles.indexOf(handle) === handles.lastIndexOf(handle) | ||
21 | }) | ||
22 | } | ||
23 | |||
10 | // --------------------------------------------------------------------------- | 24 | // --------------------------------------------------------------------------- |
11 | 25 | ||
12 | export { | 26 | export { |
13 | isFollowStateValid | 27 | isFollowStateValid, |
28 | isRemoteHandleValid, | ||
29 | isEachUniqueHandleValid | ||
14 | } | 30 | } |
diff --git a/server/helpers/custom-validators/servers.ts b/server/helpers/custom-validators/servers.ts index adf1ea497..c0f8b6aeb 100644 --- a/server/helpers/custom-validators/servers.ts +++ b/server/helpers/custom-validators/servers.ts | |||
@@ -19,7 +19,6 @@ function isHostValid (host: string) { | |||
19 | 19 | ||
20 | function isEachUniqueHostValid (hosts: string[]) { | 20 | function isEachUniqueHostValid (hosts: string[]) { |
21 | return isArray(hosts) && | 21 | return isArray(hosts) && |
22 | hosts.length !== 0 && | ||
23 | hosts.every(host => { | 22 | hosts.every(host => { |
24 | return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host) | 23 | return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host) |
25 | }) | 24 | }) |
diff --git a/server/helpers/custom-validators/video-ownership.ts b/server/helpers/custom-validators/video-ownership.ts index 0e1c63bad..cf15b385a 100644 --- a/server/helpers/custom-validators/video-ownership.ts +++ b/server/helpers/custom-validators/video-ownership.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import { MUserId } from '@server/types/models' | 2 | import { MUserId } from '@server/types/models' |
3 | import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' | 3 | import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
5 | 5 | ||
6 | function checkUserCanTerminateOwnershipChange (user: MUserId, videoChangeOwnership: MVideoChangeOwnershipFull, res: Response) { | 6 | function checkUserCanTerminateOwnershipChange (user: MUserId, videoChangeOwnership: MVideoChangeOwnershipFull, res: Response) { |
7 | if (videoChangeOwnership.NextOwner.userId === user.id) { | 7 | if (videoChangeOwnership.NextOwner.userId === user.id) { |
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index b5dc70c17..cbd7aa401 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts | |||
@@ -6,7 +6,7 @@ import { sequelizeTypescript } from '@server/initializers/database' | |||
6 | import { logger } from './logger' | 6 | import { logger } from './logger' |
7 | 7 | ||
8 | function retryTransactionWrapper <T, A, B, C, D> ( | 8 | function retryTransactionWrapper <T, A, B, C, D> ( |
9 | functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T> | Bluebird<T>, | 9 | functionToRetry: (arg1: A, arg2: B, arg3: C, arg4: D) => Promise<T>, |
10 | arg1: A, | 10 | arg1: A, |
11 | arg2: B, | 11 | arg2: B, |
12 | arg3: C, | 12 | arg3: C, |
@@ -14,20 +14,20 @@ function retryTransactionWrapper <T, A, B, C, D> ( | |||
14 | ): Promise<T> | 14 | ): Promise<T> |
15 | 15 | ||
16 | function retryTransactionWrapper <T, A, B, C> ( | 16 | function retryTransactionWrapper <T, A, B, C> ( |
17 | functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T> | Bluebird<T>, | 17 | functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T>, |
18 | arg1: A, | 18 | arg1: A, |
19 | arg2: B, | 19 | arg2: B, |
20 | arg3: C | 20 | arg3: C |
21 | ): Promise<T> | 21 | ): Promise<T> |
22 | 22 | ||
23 | function retryTransactionWrapper <T, A, B> ( | 23 | function retryTransactionWrapper <T, A, B> ( |
24 | functionToRetry: (arg1: A, arg2: B) => Promise<T> | Bluebird<T>, | 24 | functionToRetry: (arg1: A, arg2: B) => Promise<T>, |
25 | arg1: A, | 25 | arg1: A, |
26 | arg2: B | 26 | arg2: B |
27 | ): Promise<T> | 27 | ): Promise<T> |
28 | 28 | ||
29 | function retryTransactionWrapper <T, A> ( | 29 | function retryTransactionWrapper <T, A> ( |
30 | functionToRetry: (arg1: A) => Promise<T> | Bluebird<T>, | 30 | functionToRetry: (arg1: A) => Promise<T>, |
31 | arg1: A | 31 | arg1: A |
32 | ): Promise<T> | 32 | ): Promise<T> |
33 | 33 | ||
@@ -36,7 +36,7 @@ function retryTransactionWrapper <T> ( | |||
36 | ): Promise<T> | 36 | ): Promise<T> |
37 | 37 | ||
38 | function retryTransactionWrapper <T> ( | 38 | function retryTransactionWrapper <T> ( |
39 | functionToRetry: (...args: any[]) => Promise<T> | Bluebird<T>, | 39 | functionToRetry: (...args: any[]) => Promise<T>, |
40 | ...args: any[] | 40 | ...args: any[] |
41 | ): Promise<T> { | 41 | ): Promise<T> { |
42 | return transactionRetryer<T>(callback => { | 42 | return transactionRetryer<T>(callback => { |
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts index 0ff113274..c299b70f1 100644 --- a/server/helpers/express-utils.ts +++ b/server/helpers/express-utils.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as multer from 'multer' | 2 | import * as multer from 'multer' |
3 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
5 | import { REMOTE_SCHEME } from '../initializers/constants' | 5 | import { REMOTE_SCHEME } from '../initializers/constants' |
6 | import { getLowercaseExtension } from './core-utils' | 6 | import { getLowercaseExtension } from './core-utils' |
diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts index fdd361390..3c80e7d41 100644 --- a/server/helpers/youtube-dl.ts +++ b/server/helpers/youtube-dl.ts | |||
@@ -3,7 +3,7 @@ import { ensureDir, move, pathExists, remove, writeFile } from 'fs-extra' | |||
3 | import got from 'got' | 3 | import got from 'got' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import { CONFIG } from '@server/initializers/config' | 5 | import { CONFIG } from '@server/initializers/config' |
6 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | 6 | import { HttpStatusCode } from '../../shared/models/http/http-error-codes' |
7 | import { VideoResolution } from '../../shared/models/videos' | 7 | import { VideoResolution } from '../../shared/models/videos' |
8 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES } from '../initializers/constants' | 8 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES } from '../initializers/constants' |
9 | import { peertubeTruncate, pipelinePromise, root } from './core-utils' | 9 | import { peertubeTruncate, pipelinePromise, root } from './core-utils' |