diff options
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r-- | server/helpers/utils.ts | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index ce07ceff9..b74442ab0 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -4,6 +4,7 @@ import * as Promise from 'bluebird' | |||
4 | import { pseudoRandomBytesPromise } from './core-utils' | 4 | import { pseudoRandomBytesPromise } from './core-utils' |
5 | import { CONFIG, database as db } from '../initializers' | 5 | import { CONFIG, database as db } from '../initializers' |
6 | import { ResultList } from '../../shared' | 6 | import { ResultList } from '../../shared' |
7 | import { VideoResolution } from '../../shared/models/videos/video-resolution.enum' | ||
7 | 8 | ||
8 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { | 9 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { |
9 | res.type('json').status(400).end() | 10 | res.type('json').status(400).end() |
@@ -13,11 +14,11 @@ function generateRandomString (size: number) { | |||
13 | return pseudoRandomBytesPromise(size).then(raw => raw.toString('hex')) | 14 | return pseudoRandomBytesPromise(size).then(raw => raw.toString('hex')) |
14 | } | 15 | } |
15 | 16 | ||
16 | interface FormatableToJSON { | 17 | interface FormattableToJSON { |
17 | toFormattedJSON () | 18 | toFormattedJSON () |
18 | } | 19 | } |
19 | 20 | ||
20 | function getFormattedObjects<U, T extends FormatableToJSON> (objects: T[], objectsTotal: number) { | 21 | function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number) { |
21 | const formattedObjects: U[] = [] | 22 | const formattedObjects: U[] = [] |
22 | 23 | ||
23 | objects.forEach(object => { | 24 | objects.forEach(object => { |
@@ -47,6 +48,27 @@ function isSignupAllowed () { | |||
47 | }) | 48 | }) |
48 | } | 49 | } |
49 | 50 | ||
51 | function computeResolutionsToTranscode (videoFileHeight: number) { | ||
52 | const resolutionsEnabled: number[] = [] | ||
53 | const configResolutions = CONFIG.TRANSCODING.RESOLUTIONS | ||
54 | |||
55 | const resolutions = [ | ||
56 | VideoResolution.H_240P, | ||
57 | VideoResolution.H_360P, | ||
58 | VideoResolution.H_480P, | ||
59 | VideoResolution.H_720P, | ||
60 | VideoResolution.H_1080P | ||
61 | ] | ||
62 | |||
63 | for (const resolution of resolutions) { | ||
64 | if (configResolutions[resolution.toString()] === true && videoFileHeight >= resolution) { | ||
65 | resolutionsEnabled.push(resolution) | ||
66 | } | ||
67 | } | ||
68 | |||
69 | return resolutionsEnabled | ||
70 | } | ||
71 | |||
50 | type SortType = { sortModel: any, sortValue: string } | 72 | type SortType = { sortModel: any, sortValue: string } |
51 | 73 | ||
52 | // --------------------------------------------------------------------------- | 74 | // --------------------------------------------------------------------------- |
@@ -56,5 +78,6 @@ export { | |||
56 | generateRandomString, | 78 | generateRandomString, |
57 | getFormattedObjects, | 79 | getFormattedObjects, |
58 | isSignupAllowed, | 80 | isSignupAllowed, |
81 | computeResolutionsToTranscode, | ||
59 | SortType | 82 | SortType |
60 | } | 83 | } |