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/extra-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/extra-utils')
-rw-r--r-- | shared/extra-utils/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/uuid.ts | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 373d27cb4..e2e161a7b 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './crypto' | 1 | export * from './crypto' |
2 | export * from './ffprobe' | 2 | export * from './ffprobe' |
3 | export * from './file' | 3 | export * from './file' |
4 | export * from './uuid' | ||
diff --git a/shared/extra-utils/uuid.ts b/shared/extra-utils/uuid.ts new file mode 100644 index 000000000..f3c80e046 --- /dev/null +++ b/shared/extra-utils/uuid.ts | |||
@@ -0,0 +1,32 @@ | |||
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 | } | ||