diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/helpers/webtorrent.ts | 9 | ||||
-rw-r--r-- | server/tests/shared/streaming-playlists.ts | 2 |
2 files changed, 8 insertions, 3 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 @@ | |||
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)) |
diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts index 8ee04d921..824c3dcef 100644 --- a/server/tests/shared/streaming-playlists.ts +++ b/server/tests/shared/streaming-playlists.ts | |||
@@ -113,7 +113,7 @@ async function completeCheckHlsPlaylist (options: { | |||
113 | 113 | ||
114 | expect(file.magnetUri).to.have.lengthOf.above(2) | 114 | expect(file.magnetUri).to.have.lengthOf.above(2) |
115 | expect(file.torrentUrl).to.match( | 115 | expect(file.torrentUrl).to.match( |
116 | new RegExp(`http://${server.host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}-hls.torrent`) | 116 | new RegExp(`${server.url}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}-hls.torrent`) |
117 | ) | 117 | ) |
118 | 118 | ||
119 | if (objectStorageBaseUrl) { | 119 | if (objectStorageBaseUrl) { |