X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Futils.ts;h=6c95a43b62afea04ac21c4636ce6eaecd572ff14;hb=ddd677e4fdef4544773f6f426b4853d494df615e;hp=ad3b7949e586d6baeba36569b9f40a0faf9c9c72;hpb=8dc8a34ee8428e7657414115d1c137592efa174d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index ad3b7949e..6c95a43b6 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -1,13 +1,12 @@ +import { remove } from 'fs-extra' +import { Instance as ParseTorrent } from 'parse-torrent' +import { join } from 'path' import { ResultList } from '../../shared' +import { CONFIG } from '../initializers/config' import { execPromise, execPromise2, randomBytesPromise, sha256 } from './core-utils' import { logger } from './logger' -import { join } from 'path' -import { Instance as ParseTorrent } from 'parse-torrent' -import { remove } from 'fs-extra' -import { CONFIG } from '../initializers/config' -import { isVideoFileExtnameValid } from './custom-validators/videos' -function deleteFileAsync (path: string) { +function deleteFileAndCatch (path: string) { remove(path) .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err })) } @@ -31,16 +30,11 @@ function getFormattedObjects> (objects: } as ResultList } -function generateVideoImportTmpPath (target: string | ParseTorrent, extensionArg?: string) { +function generateVideoImportTmpPath (target: string | ParseTorrent, extension = '.mp4') { const id = typeof target === 'string' ? target : target.infoHash - let extension = '.mp4' - if (extensionArg && isVideoFileExtnameValid(extensionArg)) { - extension = extensionArg - } - const hash = sha256(id) return join(CONFIG.STORAGE.TMP_DIR, `${hash}-import${extension}`) } @@ -89,7 +83,7 @@ function getUUIDFromFilename (filename: string) { // --------------------------------------------------------------------------- export { - deleteFileAsync, + deleteFileAndCatch, generateRandomString, getFormattedObjects, getSecureTorrentName,