aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-07 09:54:36 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commit990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66 (patch)
tree8aaa0638798bfa14813f4d6ed5247242313b9ce6 /server/helpers/utils.ts
parentce33919c24e7402d92d81f3cd8e545df52d98240 (diff)
downloadPeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.tar.gz
PeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.tar.zst
PeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.zip
Import torrents with webtorrent
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r--server/helpers/utils.ts15
1 files changed, 11 insertions, 4 deletions
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'
6import { UserModel } from '../models/account/user' 6import { UserModel } from '../models/account/user'
7import { ActorModel } from '../models/activitypub/actor' 7import { ActorModel } from '../models/activitypub/actor'
8import { ApplicationModel } from '../models/application/application' 8import { ApplicationModel } from '../models/application/application'
9import { pseudoRandomBytesPromise, unlinkPromise } from './core-utils' 9import { pseudoRandomBytesPromise, sha256, unlinkPromise } from './core-utils'
10import { logger } from './logger' 10import { logger } from './logger'
11import { isArray } from './custom-validators/misc' 11import { isArray } from './custom-validators/misc'
12import * as crypto from "crypto" 12import * as crypto from "crypto"
13import { join } from "path" 13import { join } from "path"
14import { Instance as ParseTorrent } from 'parse-torrent'
14 15
15const isCidr = require('is-cidr') 16const isCidr = require('is-cidr')
16 17
@@ -183,13 +184,18 @@ async function getServerActor () {
183 return Promise.resolve(serverActor) 184 return Promise.resolve(serverActor)
184} 185}
185 186
186function generateVideoTmpPath (id: string) { 187function generateVideoTmpPath (target: string | ParseTorrent) {
187 const hash = crypto.createHash('sha256').update(id).digest('hex') 188 const id = typeof target === 'string' ? target : target.infoHash
189
190 const hash = sha256(id)
188 return join(CONFIG.STORAGE.VIDEOS_DIR, hash + '-import.mp4') 191 return join(CONFIG.STORAGE.VIDEOS_DIR, hash + '-import.mp4')
189} 192}
190 193
191type SortType = { sortModel: any, sortValue: string } 194function getSecureTorrentName (originalName: string) {
195 return sha256(originalName) + '.torrent'
196}
192 197
198type SortType = { sortModel: any, sortValue: string }
193 199
194// --------------------------------------------------------------------------- 200// ---------------------------------------------------------------------------
195 201
@@ -199,6 +205,7 @@ export {
199 generateRandomString, 205 generateRandomString,
200 getFormattedObjects, 206 getFormattedObjects,
201 isSignupAllowed, 207 isSignupAllowed,
208 getSecureTorrentName,
202 isSignupAllowedForCurrentIP, 209 isSignupAllowedForCurrentIP,
203 computeResolutionsToTranscode, 210 computeResolutionsToTranscode,
204 resetSequelizeInstance, 211 resetSequelizeInstance,