diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/helpers/webtorrent.ts | 21 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-import.ts | 2 |
2 files changed, 20 insertions, 3 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index 121cd0b41..6f2adb3cb 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -4,6 +4,7 @@ import * as WebTorrent from 'webtorrent' | |||
4 | import { createWriteStream } from 'fs' | 4 | import { createWriteStream } from 'fs' |
5 | import { CONFIG } from '../initializers' | 5 | import { CONFIG } from '../initializers' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { unlinkPromise } from './core-utils' | ||
7 | 8 | ||
8 | function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: string }) { | 9 | function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: string }) { |
9 | const id = target.magnetUri || target.torrentName | 10 | const id = target.magnetUri || target.torrentName |
@@ -15,13 +16,29 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: stri | |||
15 | const webtorrent = new WebTorrent() | 16 | const webtorrent = new WebTorrent() |
16 | 17 | ||
17 | const torrentId = target.magnetUri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName) | 18 | const torrentId = target.magnetUri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName) |
18 | const torrent = webtorrent.add(torrentId, torrent => { | 19 | |
20 | const options = { path: CONFIG.STORAGE.VIDEOS_DIR } | ||
21 | const torrent = webtorrent.add(torrentId, options, torrent => { | ||
19 | if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId)) | 22 | if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId)) |
20 | 23 | ||
21 | const file = torrent.files[ 0 ] | 24 | const file = torrent.files[ 0 ] |
22 | 25 | ||
23 | const writeStream = createWriteStream(path) | 26 | const writeStream = createWriteStream(path) |
24 | writeStream.on('finish', () => res(path)) | 27 | writeStream.on('finish', () => { |
28 | webtorrent.destroy(async err => { | ||
29 | if (err) return rej(err) | ||
30 | |||
31 | if (target.torrentName) { | ||
32 | unlinkPromise(torrentId) | ||
33 | .catch(err => logger.error('Cannot remove torrent %s in webtorrent download.', torrentId, { err })) | ||
34 | } | ||
35 | |||
36 | unlinkPromise(join(CONFIG.STORAGE.VIDEOS_DIR, file.name)) | ||
37 | .catch(err => logger.error('Cannot remove torrent file %s in webtorrent download.', file.name, { err })) | ||
38 | |||
39 | res(path) | ||
40 | }) | ||
41 | }) | ||
25 | 42 | ||
26 | file.createReadStream().pipe(writeStream) | 43 | file.createReadStream().pipe(writeStream) |
27 | }) | 44 | }) |
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index 2d19b82a4..d6984ef92 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts | |||
@@ -190,7 +190,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide | |||
190 | videoImport.state = VideoImportState.SUCCESS | 190 | videoImport.state = VideoImportState.SUCCESS |
191 | const videoImportUpdated = await videoImport.save({ transaction: t }) | 191 | const videoImportUpdated = await videoImport.save({ transaction: t }) |
192 | 192 | ||
193 | logger.info('Video %s imported.', videoImport.targetUrl) | 193 | logger.info('Video %s imported.', video.uuid) |
194 | 194 | ||
195 | videoImportUpdated.Video = videoUpdated | 195 | videoImportUpdated.Video = videoUpdated |
196 | return videoImportUpdated | 196 | return videoImportUpdated |