diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 8 | ||||
-rw-r--r-- | server/helpers/custom-validators/user-registration.ts | 25 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-captions.ts | 9 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-imports.ts | 9 | ||||
-rw-r--r-- | server/helpers/decache.ts | 2 | ||||
-rw-r--r-- | server/helpers/memoize.ts | 12 | ||||
-rw-r--r-- | server/helpers/youtube-dl/youtube-dl-cli.ts | 12 |
7 files changed, 66 insertions, 11 deletions
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 3dc5504e3..b3ab3ac64 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -103,7 +103,13 @@ function checkMimetypeRegex (fileMimeType: string, mimeTypeRegex: string) { | |||
103 | // --------------------------------------------------------------------------- | 103 | // --------------------------------------------------------------------------- |
104 | 104 | ||
105 | function toCompleteUUID (value: string) { | 105 | function toCompleteUUID (value: string) { |
106 | if (isShortUUID(value)) return shortToUUID(value) | 106 | if (isShortUUID(value)) { |
107 | try { | ||
108 | return shortToUUID(value) | ||
109 | } catch { | ||
110 | return null | ||
111 | } | ||
112 | } | ||
107 | 113 | ||
108 | return value | 114 | return value |
109 | } | 115 | } |
diff --git a/server/helpers/custom-validators/user-registration.ts b/server/helpers/custom-validators/user-registration.ts new file mode 100644 index 000000000..9da0bb08a --- /dev/null +++ b/server/helpers/custom-validators/user-registration.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import validator from 'validator' | ||
2 | import { CONSTRAINTS_FIELDS, USER_REGISTRATION_STATES } from '../../initializers/constants' | ||
3 | import { exists } from './misc' | ||
4 | |||
5 | const USER_REGISTRATIONS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USER_REGISTRATIONS | ||
6 | |||
7 | function isRegistrationStateValid (value: string) { | ||
8 | return exists(value) && USER_REGISTRATION_STATES[value] !== undefined | ||
9 | } | ||
10 | |||
11 | function isRegistrationModerationResponseValid (value: string) { | ||
12 | return exists(value) && validator.isLength(value, USER_REGISTRATIONS_CONSTRAINTS_FIELDS.MODERATOR_MESSAGE) | ||
13 | } | ||
14 | |||
15 | function isRegistrationReasonValid (value: string) { | ||
16 | return exists(value) && validator.isLength(value, USER_REGISTRATIONS_CONSTRAINTS_FIELDS.REASON_MESSAGE) | ||
17 | } | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | isRegistrationStateValid, | ||
23 | isRegistrationModerationResponseValid, | ||
24 | isRegistrationReasonValid | ||
25 | } | ||
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index 59ba005fe..d5b09ea03 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts | |||
@@ -8,10 +8,11 @@ function isVideoCaptionLanguageValid (value: any) { | |||
8 | return exists(value) && VIDEO_LANGUAGES[value] !== undefined | 8 | return exists(value) && VIDEO_LANGUAGES[value] !== undefined |
9 | } | 9 | } |
10 | 10 | ||
11 | const videoCaptionTypesRegex = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT) | 11 | // MacOS sends application/octet-stream |
12 | .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream | 12 | const videoCaptionTypesRegex = [ ...Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT), 'application/octet-stream' ] |
13 | .map(m => `(${m})`) | 13 | .map(m => `(${m})`) |
14 | .join('|') | 14 | .join('|') |
15 | |||
15 | function isVideoCaptionFile (files: UploadFilesForCheck, field: string) { | 16 | function isVideoCaptionFile (files: UploadFilesForCheck, field: string) { |
16 | return isFileValid({ | 17 | return isFileValid({ |
17 | files, | 18 | files, |
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts index af93aea56..da8962cb6 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts | |||
@@ -22,10 +22,11 @@ function isVideoImportStateValid (value: any) { | |||
22 | return exists(value) && VIDEO_IMPORT_STATES[value] !== undefined | 22 | return exists(value) && VIDEO_IMPORT_STATES[value] !== undefined |
23 | } | 23 | } |
24 | 24 | ||
25 | const videoTorrentImportRegex = Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT) | 25 | // MacOS sends application/octet-stream |
26 | .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream | 26 | const videoTorrentImportRegex = [ ...Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT), 'application/octet-stream' ] |
27 | .map(m => `(${m})`) | 27 | .map(m => `(${m})`) |
28 | .join('|') | 28 | .join('|') |
29 | |||
29 | function isVideoImportTorrentFile (files: UploadFilesForCheck) { | 30 | function isVideoImportTorrentFile (files: UploadFilesForCheck) { |
30 | return isFileValid({ | 31 | return isFileValid({ |
31 | files, | 32 | files, |
diff --git a/server/helpers/decache.ts b/server/helpers/decache.ts index e31973b7a..08ab545e4 100644 --- a/server/helpers/decache.ts +++ b/server/helpers/decache.ts | |||
@@ -68,7 +68,7 @@ function searchCache (moduleName: string, callback: (current: NodeModule) => voi | |||
68 | }; | 68 | }; |
69 | 69 | ||
70 | function removeCachedPath (pluginPath: string) { | 70 | function removeCachedPath (pluginPath: string) { |
71 | const pathCache = (module.constructor as any)._pathCache | 71 | const pathCache = (module.constructor as any)._pathCache as { [ id: string ]: string[] } |
72 | 72 | ||
73 | Object.keys(pathCache).forEach(function (cacheKey) { | 73 | Object.keys(pathCache).forEach(function (cacheKey) { |
74 | if (cacheKey.includes(pluginPath)) { | 74 | if (cacheKey.includes(pluginPath)) { |
diff --git a/server/helpers/memoize.ts b/server/helpers/memoize.ts new file mode 100644 index 000000000..aa20e7d73 --- /dev/null +++ b/server/helpers/memoize.ts | |||
@@ -0,0 +1,12 @@ | |||
1 | import memoizee from 'memoizee' | ||
2 | |||
3 | export function Memoize (config?: memoizee.Options<any>) { | ||
4 | return function (_target, _key, descriptor: PropertyDescriptor) { | ||
5 | const oldFunction = descriptor.value | ||
6 | const newFunction = memoizee(oldFunction, config) | ||
7 | |||
8 | descriptor.value = function () { | ||
9 | return newFunction.apply(this, arguments) | ||
10 | } | ||
11 | } | ||
12 | } | ||
diff --git a/server/helpers/youtube-dl/youtube-dl-cli.ts b/server/helpers/youtube-dl/youtube-dl-cli.ts index a2f630953..765038cea 100644 --- a/server/helpers/youtube-dl/youtube-dl-cli.ts +++ b/server/helpers/youtube-dl/youtube-dl-cli.ts | |||
@@ -6,6 +6,7 @@ import { VideoResolution } from '@shared/models' | |||
6 | import { logger, loggerTagsFactory } from '../logger' | 6 | import { logger, loggerTagsFactory } from '../logger' |
7 | import { getProxy, isProxyEnabled } from '../proxy' | 7 | import { getProxy, isProxyEnabled } from '../proxy' |
8 | import { isBinaryResponse, peertubeGot } from '../requests' | 8 | import { isBinaryResponse, peertubeGot } from '../requests' |
9 | import { OptionsOfBufferResponseBody } from 'got/dist/source' | ||
9 | 10 | ||
10 | const lTags = loggerTagsFactory('youtube-dl') | 11 | const lTags = loggerTagsFactory('youtube-dl') |
11 | 12 | ||
@@ -28,7 +29,16 @@ export class YoutubeDLCLI { | |||
28 | 29 | ||
29 | logger.info('Updating youtubeDL binary from %s.', url, lTags()) | 30 | logger.info('Updating youtubeDL binary from %s.', url, lTags()) |
30 | 31 | ||
31 | const gotOptions = { context: { bodyKBLimit: 20_000 }, responseType: 'buffer' as 'buffer' } | 32 | const gotOptions: OptionsOfBufferResponseBody = { |
33 | context: { bodyKBLimit: 20_000 }, | ||
34 | responseType: 'buffer' as 'buffer' | ||
35 | } | ||
36 | |||
37 | if (process.env.YOUTUBE_DL_DOWNLOAD_BEARER_TOKEN) { | ||
38 | gotOptions.headers = { | ||
39 | authorization: 'Bearer ' + process.env.YOUTUBE_DL_DOWNLOAD_BEARER_TOKEN | ||
40 | } | ||
41 | } | ||
32 | 42 | ||
33 | try { | 43 | try { |
34 | let gotResult = await peertubeGot(url, gotOptions) | 44 | let gotResult = await peertubeGot(url, gotOptions) |