aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r--server/helpers/utils.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index e4556fa12..8fa861281 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -1,6 +1,5 @@
1import { Model } from 'sequelize-typescript' 1import { Model } from 'sequelize-typescript'
2import * as ipaddr from 'ipaddr.js' 2import * as ipaddr from 'ipaddr.js'
3const isCidr = require('is-cidr')
4import { ResultList } from '../../shared' 3import { ResultList } from '../../shared'
5import { VideoResolution } from '../../shared/models/videos' 4import { VideoResolution } from '../../shared/models/videos'
6import { CONFIG } from '../initializers' 5import { CONFIG } from '../initializers'
@@ -10,6 +9,8 @@ import { ApplicationModel } from '../models/application/application'
10import { pseudoRandomBytesPromise } from './core-utils' 9import { pseudoRandomBytesPromise } from './core-utils'
11import { logger } from './logger' 10import { logger } from './logger'
12 11
12const isCidr = require('is-cidr')
13
13async function generateRandomString (size: number) { 14async function generateRandomString (size: number) {
14 const raw = await pseudoRandomBytesPromise(size) 15 const raw = await pseudoRandomBytesPromise(size)
15 16
@@ -17,22 +18,20 @@ async function generateRandomString (size: number) {
17} 18}
18 19
19interface FormattableToJSON { 20interface FormattableToJSON {
20 toFormattedJSON () 21 toFormattedJSON (args?: any)
21} 22}
22 23
23function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number) { 24function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number, formattedArg?: any) {
24 const formattedObjects: U[] = [] 25 const formattedObjects: U[] = []
25 26
26 objects.forEach(object => { 27 objects.forEach(object => {
27 formattedObjects.push(object.toFormattedJSON()) 28 formattedObjects.push(object.toFormattedJSON(formattedArg))
28 }) 29 })
29 30
30 const res: ResultList<U> = { 31 return {
31 total: objectsTotal, 32 total: objectsTotal,
32 data: formattedObjects 33 data: formattedObjects
33 } 34 } as ResultList<U>
34
35 return res
36} 35}
37 36
38async function isSignupAllowed () { 37async function isSignupAllowed () {
@@ -87,16 +86,17 @@ function computeResolutionsToTranscode (videoFileHeight: number) {
87 const resolutionsEnabled: number[] = [] 86 const resolutionsEnabled: number[] = []
88 const configResolutions = CONFIG.TRANSCODING.RESOLUTIONS 87 const configResolutions = CONFIG.TRANSCODING.RESOLUTIONS
89 88
89 // Put in the order we want to proceed jobs
90 const resolutions = [ 90 const resolutions = [
91 VideoResolution.H_240P,
92 VideoResolution.H_360P,
93 VideoResolution.H_480P, 91 VideoResolution.H_480P,
92 VideoResolution.H_360P,
94 VideoResolution.H_720P, 93 VideoResolution.H_720P,
94 VideoResolution.H_240P,
95 VideoResolution.H_1080P 95 VideoResolution.H_1080P
96 ] 96 ]
97 97
98 for (const resolution of resolutions) { 98 for (const resolution of resolutions) {
99 if (configResolutions[resolution + 'p'] === true && videoFileHeight > resolution) { 99 if (configResolutions[ resolution + 'p' ] === true && videoFileHeight > resolution) {
100 resolutionsEnabled.push(resolution) 100 resolutionsEnabled.push(resolution)
101 } 101 }
102 } 102 }