diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-12 20:04:58 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-12 20:37:51 +0200 |
commit | 2186386cca113506791583cb07d6ccacba7af4e0 (patch) | |
tree | 3c214c0b5fbd64332624267fa6e51fd4a9cf6474 /server/helpers/utils.ts | |
parent | 6ccdf3a23ecec5ba2eeaf487fd1fafdc7606b4bf (diff) | |
download | PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.tar.gz PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.tar.zst PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.zip |
Add concept of video state, and add ability to wait transcoding before
publishing a video
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r-- | server/helpers/utils.ts | 22 |
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 @@ | |||
1 | import { Model } from 'sequelize-typescript' | 1 | import { Model } from 'sequelize-typescript' |
2 | import * as ipaddr from 'ipaddr.js' | 2 | import * as ipaddr from 'ipaddr.js' |
3 | const isCidr = require('is-cidr') | ||
4 | import { ResultList } from '../../shared' | 3 | import { ResultList } from '../../shared' |
5 | import { VideoResolution } from '../../shared/models/videos' | 4 | import { VideoResolution } from '../../shared/models/videos' |
6 | import { CONFIG } from '../initializers' | 5 | import { CONFIG } from '../initializers' |
@@ -10,6 +9,8 @@ import { ApplicationModel } from '../models/application/application' | |||
10 | import { pseudoRandomBytesPromise } from './core-utils' | 9 | import { pseudoRandomBytesPromise } from './core-utils' |
11 | import { logger } from './logger' | 10 | import { logger } from './logger' |
12 | 11 | ||
12 | const isCidr = require('is-cidr') | ||
13 | |||
13 | async function generateRandomString (size: number) { | 14 | async 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 | ||
19 | interface FormattableToJSON { | 20 | interface FormattableToJSON { |
20 | toFormattedJSON () | 21 | toFormattedJSON (args?: any) |
21 | } | 22 | } |
22 | 23 | ||
23 | function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number) { | 24 | function 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 | ||
38 | async function isSignupAllowed () { | 37 | async 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 | } |