diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/core-utils.ts | 5 | ||||
-rw-r--r-- | server/helpers/utils.ts | 3 | ||||
-rw-r--r-- | server/helpers/webtorrent.ts | 9 |
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 | ||
6 | import * as bcrypt from 'bcrypt' | 6 | import * as bcrypt from 'bcrypt' |
7 | import * as createTorrent from 'create-torrent' | 7 | import * as createTorrent from 'create-torrent' |
8 | import { pseudoRandomBytes } from 'crypto' | 8 | import { createHash, pseudoRandomBytes } from 'crypto' |
9 | import { copyFile, readdir, readFile, rename, stat, Stats, unlink, writeFile } from 'fs' | 9 | import { copyFile, readdir, readFile, rename, stat, Stats, unlink, writeFile } from 'fs' |
10 | import * as mkdirp from 'mkdirp' | 10 | import * as mkdirp from 'mkdirp' |
11 | import { isAbsolute, join } from 'path' | 11 | import { isAbsolute, join } from 'path' |
@@ -13,7 +13,6 @@ import * as pem from 'pem' | |||
13 | import * as rimraf from 'rimraf' | 13 | import * as rimraf from 'rimraf' |
14 | import { URL } from 'url' | 14 | import { URL } from 'url' |
15 | import { truncate } from 'lodash' | 15 | import { truncate } from 'lodash' |
16 | import * as crypto from 'crypto' | ||
17 | 16 | ||
18 | function sanitizeUrl (url: string) { | 17 | function 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 | ||
99 | function sha256 (str: string) { | 98 | function sha256 (str: string) { |
100 | return crypto.createHash('sha256').update(str).digest('hex') | 99 | return createHash('sha256').update(str).digest('hex') |
101 | } | 100 | } |
102 | 101 | ||
103 | function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> { | 102 | function 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' | |||
9 | import { pseudoRandomBytesPromise, sha256, 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 { join } from 'path' |
13 | import { join } from "path" | ||
14 | import { Instance as ParseTorrent } from 'parse-torrent' | 13 | import { Instance as ParseTorrent } from 'parse-torrent' |
15 | 14 | ||
16 | const isCidr = require('is-cidr') | 15 | const 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' | |||
2 | import { generateVideoTmpPath } from './utils' | 2 | import { generateVideoTmpPath } from './utils' |
3 | import * as WebTorrent from 'webtorrent' | 3 | import * as WebTorrent from 'webtorrent' |
4 | import { createWriteStream } from 'fs' | 4 | import { createWriteStream } from 'fs' |
5 | import { Instance as ParseTorrent } from 'parse-torrent' | ||
6 | import { CONFIG } from '../initializers' | 5 | import { CONFIG } from '../initializers' |
7 | import { join } from 'path' | 6 | import { 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 | }) |