aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/core-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/core-utils.ts')
-rw-r--r--server/helpers/core-utils.ts47
1 files changed, 1 insertions, 46 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 2cbf0f8fe..531ccfba9 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -6,9 +6,8 @@
6*/ 6*/
7 7
8import { exec, ExecOptions } from 'child_process' 8import { exec, ExecOptions } from 'child_process'
9import { BinaryToTextEncoding, createHash, randomBytes } from 'crypto' 9import { randomBytes } from 'crypto'
10import { truncate } from 'lodash' 10import { truncate } from 'lodash'
11import { basename, extname, isAbsolute, join, resolve } from 'path'
12import { createPrivateKey as createPrivateKey_1, getPublicKey as getPublicKey_1 } from 'pem' 11import { createPrivateKey as createPrivateKey_1, getPublicKey as getPublicKey_1 } from 'pem'
13import { pipeline } from 'stream' 12import { pipeline } from 'stream'
14import { URL } from 'url' 13import { URL } from 'url'
@@ -159,34 +158,6 @@ function getAppNumber () {
159 158
160// --------------------------------------------------------------------------- 159// ---------------------------------------------------------------------------
161 160
162let rootPath: string
163
164function root () {
165 if (rootPath) return rootPath
166
167 rootPath = __dirname
168
169 if (basename(rootPath) === 'helpers') rootPath = resolve(rootPath, '..')
170 if (basename(rootPath) === 'server') rootPath = resolve(rootPath, '..')
171 if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..')
172
173 return rootPath
174}
175
176function buildPath (path: string) {
177 if (isAbsolute(path)) return path
178
179 return join(root(), path)
180}
181
182function getLowercaseExtension (filename: string) {
183 const ext = extname(filename) || ''
184
185 return ext.toLowerCase()
186}
187
188// ---------------------------------------------------------------------------
189
190// Consistent with .length, lodash truncate function is not 161// Consistent with .length, lodash truncate function is not
191function peertubeTruncate (str: string, options: { length: number, separator?: RegExp, omission?: string }) { 162function peertubeTruncate (str: string, options: { length: number, separator?: RegExp, omission?: string }) {
192 const truncatedStr = truncate(str, options) 163 const truncatedStr = truncate(str, options)
@@ -221,16 +192,6 @@ function parseSemVersion (s: string) {
221 192
222// --------------------------------------------------------------------------- 193// ---------------------------------------------------------------------------
223 194
224function sha256 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
225 return createHash('sha256').update(str).digest(encoding)
226}
227
228function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
229 return createHash('sha1').update(str).digest(encoding)
230}
231
232// ---------------------------------------------------------------------------
233
234function execShell (command: string, options?: ExecOptions) { 195function execShell (command: string, options?: ExecOptions) {
235 return new Promise<{ err?: Error, stdout: string, stderr: string }>((res, rej) => { 196 return new Promise<{ err?: Error, stdout: string, stderr: string }>((res, rej) => {
236 exec(command, options, (err, stdout, stderr) => { 197 exec(command, options, (err, stdout, stderr) => {
@@ -298,9 +259,6 @@ export {
298 objectConverter, 259 objectConverter,
299 mapToJSON, 260 mapToJSON,
300 261
301 root,
302 buildPath,
303 getLowercaseExtension,
304 sanitizeUrl, 262 sanitizeUrl,
305 sanitizeHost, 263 sanitizeHost,
306 264
@@ -309,9 +267,6 @@ export {
309 pageToStartAndCount, 267 pageToStartAndCount,
310 peertubeTruncate, 268 peertubeTruncate,
311 269
312 sha256,
313 sha1,
314
315 promisify0, 270 promisify0,
316 promisify1, 271 promisify1,
317 promisify2, 272 promisify2,