aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/core-utils')
-rw-r--r--shared/core-utils/common/array.ts (renamed from shared/core-utils/utils/array.ts)0
-rw-r--r--shared/core-utils/common/crypto.ts (renamed from shared/core-utils/crypto.ts)6
-rw-r--r--shared/core-utils/common/env.ts30
-rw-r--r--shared/core-utils/common/index.ts8
-rw-r--r--shared/core-utils/common/object.ts30
-rw-r--r--shared/core-utils/common/path.ts (renamed from shared/core-utils/path.ts)12
-rw-r--r--shared/core-utils/common/time.ts7
-rw-r--r--shared/core-utils/common/version.ts (renamed from shared/core-utils/common/miscs.ts)23
-rw-r--r--shared/core-utils/index.ts3
-rw-r--r--shared/core-utils/utils/index.ts2
-rw-r--r--shared/core-utils/utils/object.ts15
-rw-r--r--shared/core-utils/videos/index.ts1
-rw-r--r--shared/core-utils/videos/uuid.ts (renamed from shared/core-utils/uuid.ts)0
13 files changed, 94 insertions, 43 deletions
diff --git a/shared/core-utils/utils/array.ts b/shared/core-utils/common/array.ts
index 9e326a5aa..9e326a5aa 100644
--- a/shared/core-utils/utils/array.ts
+++ b/shared/core-utils/common/array.ts
diff --git a/shared/core-utils/crypto.ts b/shared/core-utils/common/crypto.ts
index d6d1150d0..1a583f1a0 100644
--- a/shared/core-utils/crypto.ts
+++ b/shared/core-utils/common/crypto.ts
@@ -8,7 +8,13 @@ function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
8 return createHash('sha1').update(str).digest(encoding) 8 return createHash('sha1').update(str).digest(encoding)
9} 9}
10 10
11// high excluded
12function randomInt (low: number, high: number) {
13 return Math.floor(Math.random() * (high - low) + low)
14}
15
11export { 16export {
17 randomInt,
12 sha256, 18 sha256,
13 sha1 19 sha1
14} 20}
diff --git a/shared/core-utils/common/env.ts b/shared/core-utils/common/env.ts
new file mode 100644
index 000000000..38c96b152
--- /dev/null
+++ b/shared/core-utils/common/env.ts
@@ -0,0 +1,30 @@
1function parallelTests () {
2 return process.env.MOCHA_PARALLEL === 'true'
3}
4
5function isGithubCI () {
6 return !!process.env.GITHUB_WORKSPACE
7}
8
9function areHttpImportTestsDisabled () {
10 const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true'
11
12 if (disabled) console.log('DISABLE_HTTP_IMPORT_TESTS env set to "true" so import tests are disabled')
13
14 return disabled
15}
16
17function areObjectStorageTestsDisabled () {
18 const disabled = process.env.ENABLE_OBJECT_STORAGE_TESTS !== 'true'
19
20 if (disabled) console.log('ENABLE_OBJECT_STORAGE_TESTS env is not set to "true" so object storage tests are disabled')
21
22 return disabled
23}
24
25export {
26 parallelTests,
27 isGithubCI,
28 areHttpImportTestsDisabled,
29 areObjectStorageTestsDisabled
30}
diff --git a/shared/core-utils/common/index.ts b/shared/core-utils/common/index.ts
index 5d3512148..f9ba10d5e 100644
--- a/shared/core-utils/common/index.ts
+++ b/shared/core-utils/common/index.ts
@@ -1,5 +1,11 @@
1export * from './array'
2export * from './crypto'
1export * from './date' 3export * from './date'
2export * from './miscs' 4export * from './env'
5export * from './object'
6export * from './path'
3export * from './regexp' 7export * from './regexp'
8export * from './time'
4export * from './promises' 9export * from './promises'
5export * from './url' 10export * from './url'
11export * from './version'
diff --git a/shared/core-utils/common/object.ts b/shared/core-utils/common/object.ts
new file mode 100644
index 000000000..88d6b7514
--- /dev/null
+++ b/shared/core-utils/common/object.ts
@@ -0,0 +1,30 @@
1function pick <O extends object, K extends keyof O> (object: O, keys: K[]): Pick<O, K> {
2 const result: any = {}
3
4 for (const key of keys) {
5 if (Object.prototype.hasOwnProperty.call(object, key)) {
6 result[key] = object[key]
7 }
8 }
9
10 return result
11}
12
13function sortObjectComparator (key: string, order: 'asc' | 'desc') {
14 return (a: any, b: any) => {
15 if (a[key] < b[key]) {
16 return order === 'asc' ? -1 : 1
17 }
18
19 if (a[key] > b[key]) {
20 return order === 'asc' ? 1 : -1
21 }
22
23 return 0
24 }
25}
26
27export {
28 pick,
29 sortObjectComparator
30}
diff --git a/shared/core-utils/path.ts b/shared/core-utils/common/path.ts
index b1a45d69b..ec507538b 100644
--- a/shared/core-utils/path.ts
+++ b/shared/core-utils/common/path.ts
@@ -7,6 +7,7 @@ function root () {
7 7
8 rootPath = __dirname 8 rootPath = __dirname
9 9
10 if (basename(rootPath) === 'common') rootPath = resolve(rootPath, '..')
10 if (basename(rootPath) === 'core-utils') rootPath = resolve(rootPath, '..') 11 if (basename(rootPath) === 'core-utils') rootPath = resolve(rootPath, '..')
11 if (basename(rootPath) === 'shared') rootPath = resolve(rootPath, '..') 12 if (basename(rootPath) === 'shared') rootPath = resolve(rootPath, '..')
12 if (basename(rootPath) === 'server') rootPath = resolve(rootPath, '..') 13 if (basename(rootPath) === 'server') rootPath = resolve(rootPath, '..')
@@ -27,8 +28,19 @@ function getLowercaseExtension (filename: string) {
27 return ext.toLowerCase() 28 return ext.toLowerCase()
28} 29}
29 30
31function buildAbsoluteFixturePath (path: string, customCIPath = false) {
32 if (isAbsolute(path)) return path
33
34 if (customCIPath && process.env.GITHUB_WORKSPACE) {
35 return join(process.env.GITHUB_WORKSPACE, 'fixtures', path)
36 }
37
38 return join(root(), 'server', 'tests', 'fixtures', path)
39}
40
30export { 41export {
31 root, 42 root,
32 buildPath, 43 buildPath,
44 buildAbsoluteFixturePath,
33 getLowercaseExtension 45 getLowercaseExtension
34} 46}
diff --git a/shared/core-utils/common/time.ts b/shared/core-utils/common/time.ts
new file mode 100644
index 000000000..2992609ca
--- /dev/null
+++ b/shared/core-utils/common/time.ts
@@ -0,0 +1,7 @@
1function wait (milliseconds: number) {
2 return new Promise(resolve => setTimeout(resolve, milliseconds))
3}
4
5export {
6 wait
7}
diff --git a/shared/core-utils/common/miscs.ts b/shared/core-utils/common/version.ts
index bc65dc338..8a64f8c4d 100644
--- a/shared/core-utils/common/miscs.ts
+++ b/shared/core-utils/common/version.ts
@@ -1,8 +1,3 @@
1// high excluded
2function randomInt (low: number, high: number) {
3 return Math.floor(Math.random() * (high - low) + low)
4}
5
6// Thanks https://stackoverflow.com/a/16187766 1// Thanks https://stackoverflow.com/a/16187766
7function compareSemVer (a: string, b: string) { 2function compareSemVer (a: string, b: string) {
8 const regExStrip0 = /(\.0+)+$/ 3 const regExStrip0 = /(\.0+)+$/
@@ -20,22 +15,6 @@ function compareSemVer (a: string, b: string) {
20 return segmentsA.length - segmentsB.length 15 return segmentsA.length - segmentsB.length
21} 16}
22 17
23function sortObjectComparator (key: string, order: 'asc' | 'desc') {
24 return (a: any, b: any) => {
25 if (a[key] < b[key]) {
26 return order === 'asc' ? -1 : 1
27 }
28
29 if (a[key] > b[key]) {
30 return order === 'asc' ? 1 : -1
31 }
32
33 return 0
34 }
35}
36
37export { 18export {
38 randomInt, 19 compareSemVer
39 compareSemVer,
40 sortObjectComparator
41} 20}
diff --git a/shared/core-utils/index.ts b/shared/core-utils/index.ts
index ee5cd4412..8daaa2d04 100644
--- a/shared/core-utils/index.ts
+++ b/shared/core-utils/index.ts
@@ -1,10 +1,7 @@
1export * from './abuse' 1export * from './abuse'
2export * from './common' 2export * from './common'
3export * from './i18n' 3export * from './i18n'
4export * from './path'
5export * from './plugins' 4export * from './plugins'
6export * from './renderer' 5export * from './renderer'
7export * from './users' 6export * from './users'
8export * from './utils'
9export * from './videos' 7export * from './videos'
10export * from './uuid'
diff --git a/shared/core-utils/utils/index.ts b/shared/core-utils/utils/index.ts
deleted file mode 100644
index 8d16365a8..000000000
--- a/shared/core-utils/utils/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
1export * from './array'
2export * from './object'
diff --git a/shared/core-utils/utils/object.ts b/shared/core-utils/utils/object.ts
deleted file mode 100644
index 9a8a98f9b..000000000
--- a/shared/core-utils/utils/object.ts
+++ /dev/null
@@ -1,15 +0,0 @@
1function pick <O extends object, K extends keyof O> (object: O, keys: K[]): Pick<O, K> {
2 const result: any = {}
3
4 for (const key of keys) {
5 if (Object.prototype.hasOwnProperty.call(object, key)) {
6 result[key] = object[key]
7 }
8 }
9
10 return result
11}
12
13export {
14 pick
15}
diff --git a/shared/core-utils/videos/index.ts b/shared/core-utils/videos/index.ts
index 620e3a716..8f6736d39 100644
--- a/shared/core-utils/videos/index.ts
+++ b/shared/core-utils/videos/index.ts
@@ -1,2 +1,3 @@
1export * from './bitrate' 1export * from './bitrate'
2export * from './privacy' 2export * from './privacy'
3export * from './uuid'
diff --git a/shared/core-utils/uuid.ts b/shared/core-utils/videos/uuid.ts
index f3c80e046..f3c80e046 100644
--- a/shared/core-utils/uuid.ts
+++ b/shared/core-utils/videos/uuid.ts