aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-15 09:22:57 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit30ff39e7f07898ebb716c938123825c678b4e5af (patch)
tree338b55203ee757a0e5e3f2e449536b925c677556 /server
parentb2195fafc292d6761c25fe51ca4e0328ab403424 (diff)
downloadPeerTube-30ff39e7f07898ebb716c938123825c678b4e5af.tar.gz
PeerTube-30ff39e7f07898ebb716c938123825c678b4e5af.tar.zst
PeerTube-30ff39e7f07898ebb716c938123825c678b4e5af.zip
Move createTorrent in webtorrent utils
Diffstat (limited to 'server')
-rw-r--r--server/helpers/core-utils.ts3
-rw-r--r--server/helpers/webtorrent.ts5
-rw-r--r--server/models/video/video.ts3
3 files changed, 7 insertions, 4 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 64818d036..9771351e1 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -3,7 +3,6 @@
3 Useful to avoid circular dependencies. 3 Useful to avoid circular dependencies.
4*/ 4*/
5 5
6import * as createTorrent from 'create-torrent'
7import { createHash, HexBase64Latin1Encoding, pseudoRandomBytes } from 'crypto' 6import { createHash, HexBase64Latin1Encoding, pseudoRandomBytes } from 'crypto'
8import { isAbsolute, join } from 'path' 7import { isAbsolute, join } from 'path'
9import * as pem from 'pem' 8import * as pem from 'pem'
@@ -257,7 +256,6 @@ function promisify2WithVoid<T, U> (func: (arg1: T, arg2: U, cb: (err: any) => vo
257const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) 256const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes)
258const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey) 257const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey)
259const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey) 258const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey)
260const createTorrentPromise = promisify2<string, any, any>(createTorrent)
261const execPromise2 = promisify2<string, any, string>(exec) 259const execPromise2 = promisify2<string, any, string>(exec)
262const execPromise = promisify1<string, string>(exec) 260const execPromise = promisify1<string, string>(exec)
263 261
@@ -288,7 +286,6 @@ export {
288 pseudoRandomBytesPromise, 286 pseudoRandomBytesPromise,
289 createPrivateKey, 287 createPrivateKey,
290 getPublicKey, 288 getPublicKey,
291 createTorrentPromise,
292 execPromise2, 289 execPromise2,
293 execPromise 290 execPromise
294} 291}
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index 14dfe0d28..d2a22e8f0 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -4,6 +4,8 @@ import * as WebTorrent from 'webtorrent'
4import { createWriteStream, ensureDir, remove } from 'fs-extra' 4import { createWriteStream, ensureDir, remove } from 'fs-extra'
5import { CONFIG } from '../initializers/config' 5import { CONFIG } from '../initializers/config'
6import { dirname, join } from 'path' 6import { dirname, join } from 'path'
7import * as createTorrent from 'create-torrent'
8import { promisify2 } from './core-utils'
7 9
8async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) { 10async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) {
9 const id = target.magnetUri || target.torrentName 11 const id = target.magnetUri || target.torrentName
@@ -57,9 +59,12 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
57 }) 59 })
58} 60}
59 61
62const createTorrentPromise = promisify2<string, any, any>(createTorrent)
63
60// --------------------------------------------------------------------------- 64// ---------------------------------------------------------------------------
61 65
62export { 66export {
67 createTorrentPromise,
63 downloadWebTorrentVideo 68 downloadWebTorrentVideo
64} 69}
65 70
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 92d07b5bc..ec3d5ddb0 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -40,7 +40,7 @@ import { UserRight, VideoPrivacy, VideoState } from '../../../shared'
40import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 40import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
41import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' 41import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
42import { VideoFilter } from '../../../shared/models/videos/video-query.type' 42import { VideoFilter } from '../../../shared/models/videos/video-query.type'
43import { createTorrentPromise, peertubeTruncate } from '../../helpers/core-utils' 43import { peertubeTruncate } from '../../helpers/core-utils'
44import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 44import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
45import { isArray, isBooleanValid } from '../../helpers/custom-validators/misc' 45import { isArray, isBooleanValid } from '../../helpers/custom-validators/misc'
46import { 46import {
@@ -117,6 +117,7 @@ import { VideoPlaylistElementModel } from './video-playlist-element'
117import { CONFIG } from '../../initializers/config' 117import { CONFIG } from '../../initializers/config'
118import { ThumbnailModel } from './thumbnail' 118import { ThumbnailModel } from './thumbnail'
119import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 119import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
120import { createTorrentPromise } from '../../helpers/webtorrent'
120 121
121// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation 122// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
122const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ 123const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [