diff options
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r-- | server/helpers/webtorrent.ts | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index 88bdb16b6..a3c93e6fe 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { decode, encode } from 'bencode' | 1 | import { decode, encode } from 'bencode' |
2 | import createTorrent from 'create-torrent' | 2 | import createTorrent from 'create-torrent' |
3 | import { createWriteStream, ensureDir, readFile, remove, writeFile } from 'fs-extra' | 3 | import { createWriteStream, ensureDir, pathExists, readFile, remove, writeFile } from 'fs-extra' |
4 | import magnetUtil from 'magnet-uri' | 4 | import magnetUtil from 'magnet-uri' |
5 | import parseTorrent from 'parse-torrent' | 5 | import parseTorrent from 'parse-torrent' |
6 | import { dirname, join } from 'path' | 6 | import { 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)) |
@@ -164,7 +169,10 @@ function generateMagnetUri ( | |||
164 | ) { | 169 | ) { |
165 | const xs = videoFile.getTorrentUrl() | 170 | const xs = videoFile.getTorrentUrl() |
166 | const announce = trackerUrls | 171 | const announce = trackerUrls |
167 | let urlList = [ videoFile.getFileUrl(video) ] | 172 | |
173 | let urlList = video.hasPrivateStaticPath() | ||
174 | ? [] | ||
175 | : [ videoFile.getFileUrl(video) ] | ||
168 | 176 | ||
169 | const redundancies = videoFile.RedundancyVideos | 177 | const redundancies = videoFile.RedundancyVideos |
170 | if (isArray(redundancies)) urlList = urlList.concat(redundancies.map(r => r.fileUrl)) | 178 | if (isArray(redundancies)) urlList = urlList.concat(redundancies.map(r => r.fileUrl)) |
@@ -240,6 +248,8 @@ function buildAnnounceList () { | |||
240 | } | 248 | } |
241 | 249 | ||
242 | function buildUrlList (video: MVideo, videoFile: MVideoFile) { | 250 | function buildUrlList (video: MVideo, videoFile: MVideoFile) { |
251 | if (video.hasPrivateStaticPath()) return [] | ||
252 | |||
243 | return [ videoFile.getFileUrl(video) ] | 253 | return [ videoFile.getFileUrl(video) ] |
244 | } | 254 | } |
245 | 255 | ||