aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/webtorrent.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r--server/helpers/webtorrent.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index b458e86d2..a3c93e6fe 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -1,6 +1,6 @@
1import { decode, encode } from 'bencode' 1import { decode, encode } from 'bencode'
2import createTorrent from 'create-torrent' 2import createTorrent from 'create-torrent'
3import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra' 3import { createWriteStream, ensureDir, pathExists, readFile, remove, writeFile } from 'fs-extra'
4import magnetUtil from 'magnet-uri' 4import magnetUtil from 'magnet-uri'
5import parseTorrent from 'parse-torrent' 5import parseTorrent from 'parse-torrent'
6import { dirname, join } from 'path' 6import { dirname, join } from 'path'
@@ -134,6 +134,11 @@ async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlayli
134 134
135 const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) 135 const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
136 136
137 if (!await pathExists(oldTorrentPath)) {
138 logger.info('Do not update torrent metadata %s of video %s because the file does not exist anymore.', video.uuid, oldTorrentPath)
139 return
140 }
141
137 const torrentContent = await readFile(oldTorrentPath) 142 const torrentContent = await readFile(oldTorrentPath)
138 const decoded = decode(torrentContent) 143 const decoded = decode(torrentContent)
139 144
@@ -151,7 +156,7 @@ async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlayli
151 logger.info('Updating torrent metadata %s -> %s.', oldTorrentPath, newTorrentPath) 156 logger.info('Updating torrent metadata %s -> %s.', oldTorrentPath, newTorrentPath)
152 157
153 await writeFile(newTorrentPath, encode(decoded)) 158 await writeFile(newTorrentPath, encode(decoded))
154 await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) 159 await remove(oldTorrentPath)
155 160
156 videoFile.torrentFilename = newTorrentFilename 161 videoFile.torrentFilename = newTorrentFilename
157 videoFile.infoHash = sha1(encode(decoded.info)) 162 videoFile.infoHash = sha1(encode(decoded.info))