diff options
author | lutangar <johan.dufour@gmail.com> | 2021-11-02 19:11:20 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-12-16 10:08:43 +0100 |
commit | 06aad80165d09a8863ab8103149a8ff518b10641 (patch) | |
tree | a97fa31f3ade29ff807ca1b77704eb47085ab99d /server/helpers/core-utils.ts | |
parent | 854f533c12bd2b88c70f9d5aeab770059e9a6861 (diff) | |
download | PeerTube-06aad80165d09a8863ab8103149a8ff518b10641.tar.gz PeerTube-06aad80165d09a8863ab8103149a8ff518b10641.tar.zst PeerTube-06aad80165d09a8863ab8103149a8ff518b10641.zip |
chore(refactor): remove shared folder dependencies to the server
Many files from the `shared` folder were importing files from the `server` folder.
When attempting to use Typescript project references to describe dependencies,
it highlighted a circular dependency beetween `shared` <-> `server`.
The Typescript project forbid such usages.
Using project references greatly improve performance by rebuilding only
the updated project and not all source files.
> see https://www.typescriptlang.org/docs/handbook/project-references.html
Diffstat (limited to 'server/helpers/core-utils.ts')
-rw-r--r-- | server/helpers/core-utils.ts | 47 |
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 | ||
8 | import { exec, ExecOptions } from 'child_process' | 8 | import { exec, ExecOptions } from 'child_process' |
9 | import { BinaryToTextEncoding, createHash, randomBytes } from 'crypto' | 9 | import { randomBytes } from 'crypto' |
10 | import { truncate } from 'lodash' | 10 | import { truncate } from 'lodash' |
11 | import { basename, extname, isAbsolute, join, resolve } from 'path' | ||
12 | import { createPrivateKey as createPrivateKey_1, getPublicKey as getPublicKey_1 } from 'pem' | 11 | import { createPrivateKey as createPrivateKey_1, getPublicKey as getPublicKey_1 } from 'pem' |
13 | import { pipeline } from 'stream' | 12 | import { pipeline } from 'stream' |
14 | import { URL } from 'url' | 13 | import { URL } from 'url' |
@@ -159,34 +158,6 @@ function getAppNumber () { | |||
159 | 158 | ||
160 | // --------------------------------------------------------------------------- | 159 | // --------------------------------------------------------------------------- |
161 | 160 | ||
162 | let rootPath: string | ||
163 | |||
164 | function 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 | |||
176 | function buildPath (path: string) { | ||
177 | if (isAbsolute(path)) return path | ||
178 | |||
179 | return join(root(), path) | ||
180 | } | ||
181 | |||
182 | function 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 |
191 | function peertubeTruncate (str: string, options: { length: number, separator?: RegExp, omission?: string }) { | 162 | function 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 | ||
224 | function sha256 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') { | ||
225 | return createHash('sha256').update(str).digest(encoding) | ||
226 | } | ||
227 | |||
228 | function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') { | ||
229 | return createHash('sha1').update(str).digest(encoding) | ||
230 | } | ||
231 | |||
232 | // --------------------------------------------------------------------------- | ||
233 | |||
234 | function execShell (command: string, options?: ExecOptions) { | 195 | function 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, |