aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/core-utils.ts8
-rw-r--r--server/helpers/utils.ts27
2 files changed, 31 insertions, 4 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 2ec7e6515..3118dc500 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -11,7 +11,9 @@ import {
11 rename, 11 rename,
12 unlink, 12 unlink,
13 writeFile, 13 writeFile,
14 access 14 access,
15 stat,
16 Stats
15} from 'fs' 17} from 'fs'
16import * as mkdirp from 'mkdirp' 18import * as mkdirp from 'mkdirp'
17import * as bcrypt from 'bcrypt' 19import * as bcrypt from 'bcrypt'
@@ -92,6 +94,7 @@ const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt)
92const bcryptHashPromise = promisify2<any, string|number, string>(bcrypt.hash) 94const bcryptHashPromise = promisify2<any, string|number, string>(bcrypt.hash)
93const createTorrentPromise = promisify2<string, any, any>(createTorrent) 95const createTorrentPromise = promisify2<string, any, any>(createTorrent)
94const rimrafPromise = promisify1WithVoid<string>(rimraf) 96const rimrafPromise = promisify1WithVoid<string>(rimraf)
97const statPromise = promisify1<string, Stats>(stat)
95 98
96// --------------------------------------------------------------------------- 99// ---------------------------------------------------------------------------
97 100
@@ -115,5 +118,6 @@ export {
115 bcryptGenSaltPromise, 118 bcryptGenSaltPromise,
116 bcryptHashPromise, 119 bcryptHashPromise,
117 createTorrentPromise, 120 createTorrentPromise,
118 rimrafPromise 121 rimrafPromise,
122 statPromise
119} 123}
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'
4import { pseudoRandomBytesPromise } from './core-utils' 4import { pseudoRandomBytesPromise } from './core-utils'
5import { CONFIG, database as db } from '../initializers' 5import { CONFIG, database as db } from '../initializers'
6import { ResultList } from '../../shared' 6import { ResultList } from '../../shared'
7import { VideoResolution } from '../../shared/models/videos/video-resolution.enum'
7 8
8function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { 9function 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
16interface FormatableToJSON { 17interface FormattableToJSON {
17 toFormattedJSON () 18 toFormattedJSON ()
18} 19}
19 20
20function getFormattedObjects<U, T extends FormatableToJSON> (objects: T[], objectsTotal: number) { 21function 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
51function 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
50type SortType = { sortModel: any, sortValue: string } 72type 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}