diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-07 09:54:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-08 09:30:31 +0200 |
commit | 990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66 (patch) | |
tree | 8aaa0638798bfa14813f4d6ed5247242313b9ce6 /server/helpers/utils.ts | |
parent | ce33919c24e7402d92d81f3cd8e545df52d98240 (diff) | |
download | PeerTube-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.ts | 15 |
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' | |||
6 | import { UserModel } from '../models/account/user' | 6 | import { UserModel } from '../models/account/user' |
7 | import { ActorModel } from '../models/activitypub/actor' | 7 | import { ActorModel } from '../models/activitypub/actor' |
8 | import { ApplicationModel } from '../models/application/application' | 8 | import { ApplicationModel } from '../models/application/application' |
9 | import { pseudoRandomBytesPromise, unlinkPromise } from './core-utils' | 9 | import { pseudoRandomBytesPromise, sha256, unlinkPromise } from './core-utils' |
10 | import { logger } from './logger' | 10 | import { logger } from './logger' |
11 | import { isArray } from './custom-validators/misc' | 11 | import { isArray } from './custom-validators/misc' |
12 | import * as crypto from "crypto" | 12 | import * as crypto from "crypto" |
13 | import { join } from "path" | 13 | import { join } from "path" |
14 | import { Instance as ParseTorrent } from 'parse-torrent' | ||
14 | 15 | ||
15 | const isCidr = require('is-cidr') | 16 | const 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 | ||
186 | function generateVideoTmpPath (id: string) { | 187 | function 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 | ||
191 | type SortType = { sortModel: any, sortValue: string } | 194 | function getSecureTorrentName (originalName: string) { |
195 | return sha256(originalName) + '.torrent' | ||
196 | } | ||
192 | 197 | ||
198 | type 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, |