From 0c9668f77901e7540e2c7045eb0f2974a4842a69 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 21 Apr 2023 14:55:10 +0200 Subject: Implement remote runner jobs in server Move ffmpeg functions to @shared --- server/helpers/core-utils.ts | 56 ++------------------------------------------ 1 file changed, 2 insertions(+), 54 deletions(-) (limited to 'server/helpers/core-utils.ts') diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index 73bd994c1..242c49e89 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts @@ -11,6 +11,7 @@ import { truncate } from 'lodash' import { pipeline } from 'stream' import { URL } from 'url' import { promisify } from 'util' +import { promisify1, promisify2, promisify3 } from '@shared/core-utils' const objectConverter = (oldObject: any, keyConverter: (e: string) => string, valueConverter: (e: any) => any) => { if (!oldObject || typeof oldObject !== 'object') { @@ -229,18 +230,6 @@ function execShell (command: string, options?: ExecOptions) { // --------------------------------------------------------------------------- -function isOdd (num: number) { - return (num % 2) !== 0 -} - -function toEven (num: number) { - if (isOdd(num)) return num + 1 - - return num -} - -// --------------------------------------------------------------------------- - function generateRSAKeyPairPromise (size: number) { return new Promise<{ publicKey: string, privateKey: string }>((res, rej) => { const options: RSAKeyPairOptions<'pem', 'pem'> = { @@ -286,40 +275,6 @@ function generateED25519KeyPairPromise () { // --------------------------------------------------------------------------- -function promisify0 (func: (cb: (err: any, result: A) => void) => void): () => Promise { - return function promisified (): Promise { - return new Promise((resolve: (arg: A) => void, reject: (err: any) => void) => { - func.apply(null, [ (err: any, res: A) => err ? reject(err) : resolve(res) ]) - }) - } -} - -// Thanks to https://gist.github.com/kumasento/617daa7e46f13ecdd9b2 -function promisify1 (func: (arg: T, cb: (err: any, result: A) => void) => void): (arg: T) => Promise { - return function promisified (arg: T): Promise { - return new Promise((resolve: (arg: A) => void, reject: (err: any) => void) => { - func.apply(null, [ arg, (err: any, res: A) => err ? reject(err) : resolve(res) ]) - }) - } -} - -function promisify2 (func: (arg1: T, arg2: U, cb: (err: any, result: A) => void) => void): (arg1: T, arg2: U) => Promise { - return function promisified (arg1: T, arg2: U): Promise { - return new Promise((resolve: (arg: A) => void, reject: (err: any) => void) => { - func.apply(null, [ arg1, arg2, (err: any, res: A) => err ? reject(err) : resolve(res) ]) - }) - } -} - -// eslint-disable-next-line max-len -function promisify3 (func: (arg1: T, arg2: U, arg3: V, cb: (err: any, result: A) => void) => void): (arg1: T, arg2: U, arg3: V) => Promise { - return function promisified (arg1: T, arg2: U, arg3: V): Promise { - return new Promise((resolve: (arg: A) => void, reject: (err: any) => void) => { - func.apply(null, [ arg1, arg2, arg3, (err: any, res: A) => err ? reject(err) : resolve(res) ]) - }) - } -} - const randomBytesPromise = promisify1(randomBytes) const scryptPromise = promisify3(scrypt) const execPromise2 = promisify2(exec) @@ -345,10 +300,6 @@ export { pageToStartAndCount, peertubeTruncate, - promisify0, - promisify1, - promisify2, - scryptPromise, randomBytesPromise, @@ -360,8 +311,5 @@ export { execPromise, pipelinePromise, - parseSemVersion, - - isOdd, - toEven + parseSemVersion } -- cgit v1.2.3