X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Futils.ts;h=5a4fe4fdd5b27f13228b13539ab6e4d0e9bd96d6;hb=edacb640332eae37665551d35bf29160707336f0;hp=ad3b7949e586d6baeba36569b9f40a0faf9c9c72;hpb=610d0be13b3d01f653ef269271dd667a57c85ef2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index ad3b7949e..5a4fe4fdd 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -1,13 +1,13 @@ -import { ResultList } from '../../shared' -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 { Instance as ParseTorrent } from 'parse-torrent' +import { join } from 'path' +import { sha256 } from '@shared/extra-utils' +import { ResultList } from '@shared/models' import { CONFIG } from '../initializers/config' -import { isVideoFileExtnameValid } from './custom-validators/videos' +import { randomBytesPromise } from './core-utils' +import { logger } from './logger' -function deleteFileAsync (path: string) { +function deleteFileAndCatch (path: string) { remove(path) .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err })) } @@ -31,16 +31,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}`) } @@ -49,29 +44,6 @@ function getSecureTorrentName (originalName: string) { return sha256(originalName) + '.torrent' } -async function getServerCommit () { - try { - const tag = await execPromise2( - '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', - { stdio: [ 0, 1, 2 ] } - ) - - if (tag) return tag.replace(/^v/, '') - } catch (err) { - logger.debug('Cannot get version from git tags.', { err }) - } - - try { - const version = await execPromise('[ ! -d .git ] || git rev-parse --short HEAD') - - if (version) return version.toString().trim() - } catch (err) { - logger.debug('Cannot get version from git HEAD.', { err }) - } - - return '' -} - /** * From a filename like "ede4cba5-742b-46fa-a388-9a6eb3a3aeb3.mp4", returns * only the "ede4cba5-742b-46fa-a388-9a6eb3a3aeb3" part. If the filename does @@ -89,11 +61,10 @@ function getUUIDFromFilename (filename: string) { // --------------------------------------------------------------------------- export { - deleteFileAsync, + deleteFileAndCatch, generateRandomString, getFormattedObjects, getSecureTorrentName, - getServerCommit, generateVideoImportTmpPath, getUUIDFromFilename }