From f304a1580b5ce7b6c5f9e25cd3ddc63ca8d8c6a1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 17 Dec 2021 13:58:07 +0100 Subject: [PATCH] Fix build --- .../shared/shared-video-miniature/video-filters.model.ts | 3 ++- client/tsconfig.json | 2 ++ server/helpers/peertube-crypto.ts | 2 +- server/helpers/utils.ts | 2 +- server/helpers/webtorrent.ts | 2 +- server/lib/auth/oauth.ts | 2 +- server/lib/client-html.ts | 2 +- server/lib/hls.ts | 2 +- server/models/video/video-streaming-playlist.ts | 4 ++-- server/tests/shared/streaming-playlists.ts | 2 +- server/tests/shared/tracker.ts | 2 +- server/tools/peertube-import-videos.ts | 3 +-- shared/core-utils/common/index.ts | 2 +- shared/core-utils/common/random.ts | 8 ++++++++ shared/{core-utils/common => extra-utils}/crypto.ts | 0 shared/extra-utils/index.ts | 1 + 16 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 shared/core-utils/common/random.ts rename shared/{core-utils/common => extra-utils}/crypto.ts (100%) diff --git a/client/src/app/shared/shared-video-miniature/video-filters.model.ts b/client/src/app/shared/shared-video-miniature/video-filters.model.ts index 982880b0e..8ad2fcd5d 100644 --- a/client/src/app/shared/shared-video-miniature/video-filters.model.ts +++ b/client/src/app/shared/shared-video-miniature/video-filters.model.ts @@ -1,5 +1,6 @@ import { intoArray, toBoolean } from '@app/helpers' -import { AttributesOnly, getAllPrivacies } from '@shared/core-utils' +import { getAllPrivacies } from '@shared/core-utils' +import { AttributesOnly } from '@shared/typescript-utils' import { BooleanBothQuery, NSFWPolicyType, VideoInclude, VideoPrivacy, VideoSortField } from '@shared/models' type VideoFiltersKeys = { diff --git a/client/tsconfig.json b/client/tsconfig.json index d68b3058e..41814d036 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -35,6 +35,8 @@ "@shared/models": [ "../shared/models" ], "@shared/core-utils": [ "../shared/core-utils" ], "@shared/core-utils/*": [ "../shared/core-utils/*" ], + "@shared/typescript-utils": [ "../shared/typescript-utils" ], + "@shared/typescript-utils/*": [ "../shared/typescript-utils/*" ], "@root-helpers/*": [ "src/root-helpers/*" ], "fs": [ "src/shims/noop.ts" ], "http": [ "src/shims/http.ts" ], diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 66a353204..b8f7c782a 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -2,9 +2,9 @@ import { compare, genSalt, hash } from 'bcrypt' import { createSign, createVerify } from 'crypto' import { Request } from 'express' import { cloneDeep } from 'lodash' +import { sha256 } from '@shared/extra-utils' import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' import { MActor } from '../types/models' -import { sha256 } from '@shared/core-utils/common/crypto' import { createPrivateKey, getPublicKey, promisify1, promisify2 } from './core-utils' import { jsonld } from './custom-jsonld-signature' import { logger } from './logger' diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index d6a3dae95..bd85eaa56 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -1,9 +1,9 @@ import { remove } from 'fs-extra' import { Instance as ParseTorrent } from 'parse-torrent' import { join } from 'path' +import { sha256 } from '@shared/extra-utils' import { ResultList } from '../../shared' import { CONFIG } from '../initializers/config' -import { sha256 } from '@shared/core-utils/common/crypto' import { execPromise, execPromise2, randomBytesPromise } from './core-utils' import { logger } from './logger' diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index 03663d73c..68d532c48 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts @@ -13,9 +13,9 @@ import { VideoPathManager } from '@server/lib/video-path-manager' import { MVideo } from '@server/types/models/video/video' import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file' import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist' +import { sha1 } from '@shared/extra-utils' import { CONFIG } from '../initializers/config' import { promisify2 } from './core-utils' -import { sha1 } from '@shared/core-utils/common/crypto' import { logger } from './logger' import { generateVideoImportTmpPath } from './utils' import { extractVideo } from './video' diff --git a/server/lib/auth/oauth.ts b/server/lib/auth/oauth.ts index dc0022852..2bf7a6361 100644 --- a/server/lib/auth/oauth.ts +++ b/server/lib/auth/oauth.ts @@ -8,9 +8,9 @@ import { UnauthorizedClientError, UnsupportedGrantTypeError } from 'oauth2-server' -import { sha1 } from '@shared/core-utils/common/crypto' import { randomBytesPromise } from '@server/helpers/core-utils' import { MOAuthClient } from '@server/types/models' +import { sha1 } from '@shared/extra-utils' import { OAUTH_LIFETIME } from '../../initializers/constants' import { BypassLogin, getClient, getRefreshToken, getUser, revokeToken, saveToken } from './oauth-model' diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 91708839b..e7e439bfe 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -4,12 +4,12 @@ import { join } from 'path' import validator from 'validator' import { toCompleteUUID } from '@server/helpers/custom-validators/misc' import { escapeHTML } from '@shared/core-utils/renderer' +import { sha256 } from '@shared/extra-utils' import { HTMLServerConfig } from '@shared/models' import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' import { HttpStatusCode } from '../../shared/models/http/http-error-codes' import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' import { isTestInstance } from '../helpers/core-utils' -import { sha256 } from '@shared/core-utils/common/crypto' import { logger } from '../helpers/logger' import { mdToPlainText } from '../helpers/markdown' import { CONFIG } from '../initializers/config' diff --git a/server/lib/hls.ts b/server/lib/hls.ts index e4904be5f..1574ff27b 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -2,7 +2,7 @@ import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, import { flatten, uniq } from 'lodash' import { basename, dirname, join } from 'path' import { MStreamingPlaylistFilesVideo, MVideo, MVideoUUID } from '@server/types/models' -import { sha256 } from '@shared/core-utils/common/crypto' +import { sha256 } from '@shared/extra-utils' import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamSize } from '../helpers/ffprobe-utils' import { logger } from '../helpers/logger' import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 7b410f8ee..9957ffee3 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts @@ -18,10 +18,10 @@ import { import { getHLSPublicFileUrl } from '@server/lib/object-storage' import { VideoFileModel } from '@server/models/video/video-file' import { MStreamingPlaylist, MVideo } from '@server/types/models' -import { AttributesOnly } from '@shared/typescript-utils' +import { sha1 } from '@shared/extra-utils' import { VideoStorage } from '@shared/models' +import { AttributesOnly } from '@shared/typescript-utils' import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' -import { sha1 } from '@shared/core-utils/common/crypto' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { isArrayOf } from '../../helpers/custom-validators/misc' import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts index 738dc90e1..7ca707f2e 100644 --- a/server/tests/shared/streaming-playlists.ts +++ b/server/tests/shared/streaming-playlists.ts @@ -1,7 +1,7 @@ import { expect } from 'chai' import { basename } from 'path' import { removeFragmentedMP4Ext } from '@shared/core-utils' -import { sha256 } from '@shared/core-utils/common/crypto' +import { sha256 } from '@shared/extra-utils' import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' import { PeerTubeServer } from '@shared/server-commands' diff --git a/server/tests/shared/tracker.ts b/server/tests/shared/tracker.ts index 699895d5f..9c1f0246a 100644 --- a/server/tests/shared/tracker.ts +++ b/server/tests/shared/tracker.ts @@ -1,5 +1,5 @@ import { expect } from 'chai' -import { sha1 } from '@shared/core-utils' +import { sha1 } from '@shared/extra-utils' import { makeGetRequest } from '@shared/server-commands' async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) { diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 8314551f6..44c42bad6 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -5,7 +5,7 @@ import { program } from 'commander' import { accessSync, constants } from 'fs' import { remove } from 'fs-extra' import { join } from 'path' -import { sha256 } from '@shared/core-utils/crypto' +import { sha256, wait } from '@shared/core-utils' import { doRequestAndSaveToFile } from '../helpers/requests' import { assignToken, @@ -15,7 +15,6 @@ import { getLogger, getServerCredentials } from './cli' -import { wait } from '@shared/server-commands' import { YoutubeDLCLI, YoutubeDLInfo, YoutubeDLInfoBuilder } from '@server/helpers/youtube-dl' import prompt = require('prompt') diff --git a/shared/core-utils/common/index.ts b/shared/core-utils/common/index.ts index f9ba10d5e..720977ead 100644 --- a/shared/core-utils/common/index.ts +++ b/shared/core-utils/common/index.ts @@ -1,5 +1,5 @@ export * from './array' -export * from './crypto' +export * from './random' export * from './date' export * from './env' export * from './object' diff --git a/shared/core-utils/common/random.ts b/shared/core-utils/common/random.ts new file mode 100644 index 000000000..705735d09 --- /dev/null +++ b/shared/core-utils/common/random.ts @@ -0,0 +1,8 @@ +// high excluded +function randomInt (low: number, high: number) { + return Math.floor(Math.random() * (high - low) + low) +} + +export { + randomInt +} diff --git a/shared/core-utils/common/crypto.ts b/shared/extra-utils/crypto.ts similarity index 100% rename from shared/core-utils/common/crypto.ts rename to shared/extra-utils/crypto.ts diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 38303cf1f..373d27cb4 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -1,2 +1,3 @@ +export * from './crypto' export * from './ffprobe' export * from './file'