diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-29 14:44:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-29 14:44:58 +0100 |
commit | 0628157fe9662fdb2b6fa658b8b53fe684c013ce (patch) | |
tree | 52bf9dc16d9e30cb716a6df76ce12fd7d34cff7f /shared/core-utils | |
parent | fb3c9e2bf5b45d6d283cea4d55cc0d49eb58e3cb (diff) | |
download | PeerTube-0628157fe9662fdb2b6fa658b8b53fe684c013ce.tar.gz PeerTube-0628157fe9662fdb2b6fa658b8b53fe684c013ce.tar.zst PeerTube-0628157fe9662fdb2b6fa658b8b53fe684c013ce.zip |
Move uuid stuff in extra utils
Since it requires an external dependency
Diffstat (limited to 'shared/core-utils')
-rw-r--r-- | shared/core-utils/common/object.ts | 5 | ||||
-rw-r--r-- | shared/core-utils/videos/bitrate.ts | 2 | ||||
-rw-r--r-- | shared/core-utils/videos/index.ts | 1 | ||||
-rw-r--r-- | shared/core-utils/videos/uuid.ts | 32 |
4 files changed, 6 insertions, 34 deletions
diff --git a/shared/core-utils/common/object.ts b/shared/core-utils/common/object.ts index 88d6b7514..49d209819 100644 --- a/shared/core-utils/common/object.ts +++ b/shared/core-utils/common/object.ts | |||
@@ -10,6 +10,10 @@ function pick <O extends object, K extends keyof O> (object: O, keys: K[]): Pick | |||
10 | return result | 10 | return result |
11 | } | 11 | } |
12 | 12 | ||
13 | function getKeys <O extends object, K extends keyof O> (object: O, keys: K[]): K[] { | ||
14 | return (Object.keys(object) as K[]).filter(k => keys.includes(k)) | ||
15 | } | ||
16 | |||
13 | function sortObjectComparator (key: string, order: 'asc' | 'desc') { | 17 | function sortObjectComparator (key: string, order: 'asc' | 'desc') { |
14 | return (a: any, b: any) => { | 18 | return (a: any, b: any) => { |
15 | if (a[key] < b[key]) { | 19 | if (a[key] < b[key]) { |
@@ -26,5 +30,6 @@ function sortObjectComparator (key: string, order: 'asc' | 'desc') { | |||
26 | 30 | ||
27 | export { | 31 | export { |
28 | pick, | 32 | pick, |
33 | getKeys, | ||
29 | sortObjectComparator | 34 | sortObjectComparator |
30 | } | 35 | } |
diff --git a/shared/core-utils/videos/bitrate.ts b/shared/core-utils/videos/bitrate.ts index c1891188f..30d22df09 100644 --- a/shared/core-utils/videos/bitrate.ts +++ b/shared/core-utils/videos/bitrate.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { VideoResolution } from "@shared/models" | 1 | import { VideoResolution } from '@shared/models' |
2 | 2 | ||
3 | type BitPerPixel = { [ id in VideoResolution ]: number } | 3 | type BitPerPixel = { [ id in VideoResolution ]: number } |
4 | 4 | ||
diff --git a/shared/core-utils/videos/index.ts b/shared/core-utils/videos/index.ts index 8f6736d39..620e3a716 100644 --- a/shared/core-utils/videos/index.ts +++ b/shared/core-utils/videos/index.ts | |||
@@ -1,3 +1,2 @@ | |||
1 | export * from './bitrate' | 1 | export * from './bitrate' |
2 | export * from './privacy' | 2 | export * from './privacy' |
3 | export * from './uuid' | ||
diff --git a/shared/core-utils/videos/uuid.ts b/shared/core-utils/videos/uuid.ts deleted file mode 100644 index f3c80e046..000000000 --- a/shared/core-utils/videos/uuid.ts +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | import short, { uuid } from 'short-uuid' | ||
2 | |||
3 | const translator = short() | ||
4 | |||
5 | function buildUUID () { | ||
6 | return uuid() | ||
7 | } | ||
8 | |||
9 | function uuidToShort (uuid: string) { | ||
10 | if (!uuid) return uuid | ||
11 | |||
12 | return translator.fromUUID(uuid) | ||
13 | } | ||
14 | |||
15 | function shortToUUID (shortUUID: string) { | ||
16 | if (!shortUUID) return shortUUID | ||
17 | |||
18 | return translator.toUUID(shortUUID) | ||
19 | } | ||
20 | |||
21 | function isShortUUID (value: string) { | ||
22 | if (!value) return false | ||
23 | |||
24 | return value.length === translator.maxLength | ||
25 | } | ||
26 | |||
27 | export { | ||
28 | buildUUID, | ||
29 | uuidToShort, | ||
30 | shortToUUID, | ||
31 | isShortUUID | ||
32 | } | ||