From 0628157fe9662fdb2b6fa658b8b53fe684c013ce Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 29 Dec 2021 14:44:58 +0100 Subject: Move uuid stuff in extra utils Since it requires an external dependency --- shared/core-utils/common/object.ts | 5 ++++ shared/core-utils/videos/bitrate.ts | 2 +- shared/core-utils/videos/index.ts | 1 - shared/core-utils/videos/uuid.ts | 32 ------------------------- shared/extra-utils/index.ts | 1 + shared/extra-utils/uuid.ts | 32 +++++++++++++++++++++++++ shared/server-commands/videos/videos-command.ts | 3 ++- 7 files changed, 41 insertions(+), 35 deletions(-) delete mode 100644 shared/core-utils/videos/uuid.ts create mode 100644 shared/extra-utils/uuid.ts (limited to 'shared') 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 (object: O, keys: K[]): Pick return result } +function getKeys (object: O, keys: K[]): K[] { + return (Object.keys(object) as K[]).filter(k => keys.includes(k)) +} + function sortObjectComparator (key: string, order: 'asc' | 'desc') { return (a: any, b: any) => { if (a[key] < b[key]) { @@ -26,5 +30,6 @@ function sortObjectComparator (key: string, order: 'asc' | 'desc') { export { pick, + getKeys, sortObjectComparator } 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 @@ -import { VideoResolution } from "@shared/models" +import { VideoResolution } from '@shared/models' type BitPerPixel = { [ id in VideoResolution ]: number } 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 @@ export * from './bitrate' export * from './privacy' -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 @@ -import short, { uuid } from 'short-uuid' - -const translator = short() - -function buildUUID () { - return uuid() -} - -function uuidToShort (uuid: string) { - if (!uuid) return uuid - - return translator.fromUUID(uuid) -} - -function shortToUUID (shortUUID: string) { - if (!shortUUID) return shortUUID - - return translator.toUUID(shortUUID) -} - -function isShortUUID (value: string) { - if (!value) return false - - return value.length === translator.maxLength -} - -export { - buildUUID, - uuidToShort, - shortToUUID, - isShortUUID -} 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 @@ export * from './crypto' export * from './ffprobe' export * from './file' +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 @@ +import short, { uuid } from 'short-uuid' + +const translator = short() + +function buildUUID () { + return uuid() +} + +function uuidToShort (uuid: string) { + if (!uuid) return uuid + + return translator.fromUUID(uuid) +} + +function shortToUUID (shortUUID: string) { + if (!shortUUID) return shortUUID + + return translator.toUUID(shortUUID) +} + +function isShortUUID (value: string) { + if (!value) return false + + return value.length === translator.maxLength +} + +export { + buildUUID, + uuidToShort, + shortToUUID, + isShortUUID +} diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts index ead57b9aa..21753ddc4 100644 --- a/shared/server-commands/videos/videos-command.ts +++ b/shared/server-commands/videos/videos-command.ts @@ -5,7 +5,8 @@ import { createReadStream, stat } from 'fs-extra' import got, { Response as GotResponse } from 'got' import { omit } from 'lodash' import validator from 'validator' -import { buildAbsoluteFixturePath, buildUUID, pick, wait } from '@shared/core-utils' +import { buildAbsoluteFixturePath, pick, wait } from '@shared/core-utils' +import { buildUUID } from '@shared/extra-utils' import { HttpStatusCode, ResultList, -- cgit v1.2.3