aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/webtorrent.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-27 14:32:44 +0200
committerChocobozzz <me@florianbigard.com>2021-08-27 15:12:22 +0200
commit41fb13c330de629df2d23379209e79c7af0f2e9a (patch)
tree73bc5a90566406b3910f142beae2a879c1e4265d /server/helpers/webtorrent.ts
parent40e7ed0714f96c01e16de3ac971a4b28116294e1 (diff)
downloadPeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.gz
PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.zst
PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.zip
esModuleInterop to true
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r--server/helpers/webtorrent.ts20
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 @@
1import * as bencode from 'bencode' 1import { decode, encode } from 'bencode'
2import * as createTorrent from 'create-torrent' 2import createTorrent from 'create-torrent'
3import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra' 3import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra'
4import * as magnetUtil from 'magnet-uri' 4import magnetUtil from 'magnet-uri'
5import * as parseTorrent from 'parse-torrent' 5import parseTorrent from 'parse-torrent'
6import { dirname, join } from 'path' 6import { dirname, join } from 'path'
7import * as WebTorrent from 'webtorrent' 7import { pipeline } from 'stream'
8import WebTorrent, { Instance, TorrentFile } from 'webtorrent'
8import { isArray } from '@server/helpers/custom-validators/misc' 9import { isArray } from '@server/helpers/custom-validators/misc'
9import { WEBSERVER } from '@server/initializers/constants' 10import { WEBSERVER } from '@server/initializers/constants'
10import { generateTorrentFileName } from '@server/lib/paths' 11import { generateTorrentFileName } from '@server/lib/paths'
@@ -17,7 +18,6 @@ import { promisify2 } from './core-utils'
17import { logger } from './logger' 18import { logger } from './logger'
18import { generateVideoImportTmpPath } from './utils' 19import { generateVideoImportTmpPath } from './utils'
19import { extractVideo } from './video' 20import { extractVideo } from './video'
20import { pipeline } from 'stream'
21 21
22const createTorrentPromise = promisify2<string, any, any>(createTorrent) 22const 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
182function safeWebtorrentDestroy ( 182function 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