X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Futils.ts;h=eaad555553527b98549e69580203f0357063b0ee;hb=e69219184b1a3262ec5e617d30337b6431c9840c;hp=7abcec5d727fe3f08ea7607d755cfe92a01fcc66;hpb=cf7a61b5a2b68fd966c4a355e37e84b048ed296b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 7abcec5d7..eaad55555 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -6,9 +6,11 @@ import { CONFIG } from '../initializers' import { UserModel } from '../models/account/user' import { ActorModel } from '../models/activitypub/actor' import { ApplicationModel } from '../models/application/application' -import { pseudoRandomBytesPromise, unlinkPromise } from './core-utils' +import { pseudoRandomBytesPromise, sha256, unlinkPromise } from './core-utils' import { logger } from './logger' import { isArray } from './custom-validators/misc' +import { join } from 'path' +import { Instance as ParseTorrent } from 'parse-torrent' const isCidr = require('is-cidr') @@ -181,6 +183,17 @@ async function getServerActor () { return Promise.resolve(serverActor) } +function generateVideoTmpPath (target: string | ParseTorrent) { + const id = typeof target === 'string' ? target : target.infoHash + + const hash = sha256(id) + return join(CONFIG.STORAGE.VIDEOS_DIR, hash + '-import.mp4') +} + +function getSecureTorrentName (originalName: string) { + return sha256(originalName) + '.torrent' +} + type SortType = { sortModel: any, sortValue: string } // --------------------------------------------------------------------------- @@ -191,9 +204,11 @@ export { generateRandomString, getFormattedObjects, isSignupAllowed, + getSecureTorrentName, isSignupAllowedForCurrentIP, computeResolutionsToTranscode, resetSequelizeInstance, getServerActor, - SortType + SortType, + generateVideoTmpPath }