aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-07 15:17:17 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commit3e17515e2996b79e23f569c296051a91af3fcbe4 (patch)
treed1c06c394a9f4b1d8646625612c2d5d3e02e9191 /server/helpers
parent187501f8b8e334f043ae1e9af3c9d4f45ea0e6c1 (diff)
downloadPeerTube-3e17515e2996b79e23f569c296051a91af3fcbe4.tar.gz
PeerTube-3e17515e2996b79e23f569c296051a91af3fcbe4.tar.zst
PeerTube-3e17515e2996b79e23f569c296051a91af3fcbe4.zip
Add torrent tests
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/core-utils.ts5
-rw-r--r--server/helpers/utils.ts3
-rw-r--r--server/helpers/webtorrent.ts9
3 files changed, 8 insertions, 9 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 25eb6454a..3b38da66c 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -5,7 +5,7 @@
5 5
6import * as bcrypt from 'bcrypt' 6import * as bcrypt from 'bcrypt'
7import * as createTorrent from 'create-torrent' 7import * as createTorrent from 'create-torrent'
8import { pseudoRandomBytes } from 'crypto' 8import { createHash, pseudoRandomBytes } from 'crypto'
9import { copyFile, readdir, readFile, rename, stat, Stats, unlink, writeFile } from 'fs' 9import { copyFile, readdir, readFile, rename, stat, Stats, unlink, writeFile } from 'fs'
10import * as mkdirp from 'mkdirp' 10import * as mkdirp from 'mkdirp'
11import { isAbsolute, join } from 'path' 11import { isAbsolute, join } from 'path'
@@ -13,7 +13,6 @@ import * as pem from 'pem'
13import * as rimraf from 'rimraf' 13import * as rimraf from 'rimraf'
14import { URL } from 'url' 14import { URL } from 'url'
15import { truncate } from 'lodash' 15import { truncate } from 'lodash'
16import * as crypto from 'crypto'
17 16
18function sanitizeUrl (url: string) { 17function sanitizeUrl (url: string) {
19 const urlObject = new URL(url) 18 const urlObject = new URL(url)
@@ -97,7 +96,7 @@ function peertubeTruncate (str: string, maxLength: number) {
97} 96}
98 97
99function sha256 (str: string) { 98function sha256 (str: string) {
100 return crypto.createHash('sha256').update(str).digest('hex') 99 return createHash('sha256').update(str).digest('hex')
101} 100}
102 101
103function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> { 102function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 2ad87951e..eaad55555 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -9,8 +9,7 @@ import { ApplicationModel } from '../models/application/application'
9import { pseudoRandomBytesPromise, sha256, 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 { join } from 'path'
13import { join } from "path"
14import { Instance as ParseTorrent } from 'parse-torrent' 13import { Instance as ParseTorrent } from 'parse-torrent'
15 14
16const isCidr = require('is-cidr') 15const isCidr = require('is-cidr')
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index 04b3ac71b..121cd0b41 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -2,7 +2,6 @@ import { logger } from './logger'
2import { generateVideoTmpPath } from './utils' 2import { generateVideoTmpPath } from './utils'
3import * as WebTorrent from 'webtorrent' 3import * as WebTorrent from 'webtorrent'
4import { createWriteStream } from 'fs' 4import { createWriteStream } from 'fs'
5import { Instance as ParseTorrent } from 'parse-torrent'
6import { CONFIG } from '../initializers' 5import { CONFIG } from '../initializers'
7import { join } from 'path' 6import { join } from 'path'
8 7
@@ -20,10 +19,12 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: stri
20 if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId)) 19 if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId))
21 20
22 const file = torrent.files[ 0 ] 21 const file = torrent.files[ 0 ]
23 file.createReadStream().pipe(createWriteStream(path))
24 })
25 22
26 torrent.on('done', () => res(path)) 23 const writeStream = createWriteStream(path)
24 writeStream.on('finish', () => res(path))
25
26 file.createReadStream().pipe(writeStream)
27 })
27 28
28 torrent.on('error', err => rej(err)) 29 torrent.on('error', err => rej(err))
29 }) 30 })