diff options
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r-- | server/helpers/webtorrent.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index 813ebc236..83b46e085 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | import * as bencode from 'bencode' | 1 | import { decode, encode } from 'bencode' |
2 | import * as createTorrent from 'create-torrent' | 2 | import createTorrent from 'create-torrent' |
3 | import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra' | 3 | import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra' |
4 | import * as magnetUtil from 'magnet-uri' | 4 | import magnetUtil from 'magnet-uri' |
5 | import * as parseTorrent from 'parse-torrent' | 5 | import parseTorrent from 'parse-torrent' |
6 | import { dirname, join } from 'path' | 6 | import { dirname, join } from 'path' |
7 | import * as WebTorrent from 'webtorrent' | 7 | import { pipeline } from 'stream' |
8 | import WebTorrent, { Instance, TorrentFile } from 'webtorrent' | ||
8 | import { isArray } from '@server/helpers/custom-validators/misc' | 9 | import { isArray } from '@server/helpers/custom-validators/misc' |
9 | import { WEBSERVER } from '@server/initializers/constants' | 10 | import { WEBSERVER } from '@server/initializers/constants' |
10 | import { generateTorrentFileName } from '@server/lib/paths' | 11 | import { generateTorrentFileName } from '@server/lib/paths' |
@@ -17,7 +18,6 @@ import { promisify2 } from './core-utils' | |||
17 | import { logger } from './logger' | 18 | import { logger } from './logger' |
18 | import { generateVideoImportTmpPath } from './utils' | 19 | import { generateVideoImportTmpPath } from './utils' |
19 | import { extractVideo } from './video' | 20 | import { extractVideo } from './video' |
20 | import { pipeline } from 'stream' | ||
21 | 21 | ||
22 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) | 22 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) |
23 | 23 | ||
@@ -33,7 +33,7 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName | |||
33 | 33 | ||
34 | return new Promise<string>((res, rej) => { | 34 | return new Promise<string>((res, rej) => { |
35 | const webtorrent = new WebTorrent() | 35 | const webtorrent = new WebTorrent() |
36 | let file: WebTorrent.TorrentFile | 36 | let file: TorrentFile |
37 | 37 | ||
38 | const torrentId = target.magnetUri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName) | 38 | const torrentId = target.magnetUri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName) |
39 | 39 | ||
@@ -126,7 +126,7 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi | |||
126 | const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) | 126 | const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) |
127 | 127 | ||
128 | const torrentContent = await readFile(oldTorrentPath) | 128 | const torrentContent = await readFile(oldTorrentPath) |
129 | const decoded = bencode.decode(torrentContent) | 129 | const decoded = decode(torrentContent) |
130 | 130 | ||
131 | decoded['announce-list'] = buildAnnounceList() | 131 | decoded['announce-list'] = buildAnnounceList() |
132 | decoded.announce = decoded['announce-list'][0][0] | 132 | decoded.announce = decoded['announce-list'][0][0] |
@@ -138,7 +138,7 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi | |||
138 | 138 | ||
139 | logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath) | 139 | logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath) |
140 | 140 | ||
141 | await writeFile(newTorrentPath, bencode.encode(decoded)) | 141 | await writeFile(newTorrentPath, encode(decoded)) |
142 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) | 142 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) |
143 | 143 | ||
144 | videoFile.torrentFilename = newTorrentFilename | 144 | videoFile.torrentFilename = newTorrentFilename |
@@ -180,7 +180,7 @@ export { | |||
180 | // --------------------------------------------------------------------------- | 180 | // --------------------------------------------------------------------------- |
181 | 181 | ||
182 | function safeWebtorrentDestroy ( | 182 | function safeWebtorrentDestroy ( |
183 | webtorrent: WebTorrent.Instance, | 183 | webtorrent: Instance, |
184 | torrentId: string, | 184 | torrentId: string, |
185 | downloadedFile?: { directoryPath: string, filepath: string }, | 185 | downloadedFile?: { directoryPath: string, filepath: string }, |
186 | torrentName?: string | 186 | torrentName?: string |