From 990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Aug 2018 09:54:36 +0200 Subject: Import torrents with webtorrent --- server/helpers/utils.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'server/helpers/utils.ts') diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index f4cc5547d..2ad87951e 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -6,11 +6,12 @@ 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 * as crypto from "crypto" import { join } from "path" +import { Instance as ParseTorrent } from 'parse-torrent' const isCidr = require('is-cidr') @@ -183,13 +184,18 @@ async function getServerActor () { return Promise.resolve(serverActor) } -function generateVideoTmpPath (id: string) { - const hash = crypto.createHash('sha256').update(id).digest('hex') +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') } -type SortType = { sortModel: any, sortValue: string } +function getSecureTorrentName (originalName: string) { + return sha256(originalName) + '.torrent' +} +type SortType = { sortModel: any, sortValue: string } // --------------------------------------------------------------------------- @@ -199,6 +205,7 @@ export { generateRandomString, getFormattedObjects, isSignupAllowed, + getSecureTorrentName, isSignupAllowedForCurrentIP, computeResolutionsToTranscode, resetSequelizeInstance, -- cgit v1.2.3