diff --git a/server/routes/api/torrents.ts b/server/routes/api/torrents.ts index 65ecd337..0e3a2ea1 100644 --- a/server/routes/api/torrents.ts +++ b/server/routes/api/torrents.ts @@ -541,7 +541,9 @@ router.get('/:hash/contents/:indices/data', (req, res) => { if (!selectedTorrent) return res.status(404).json({error: 'Torrent not found.'}); return req.services?.clientGatewayService?.getTorrentContents(hash).then((contents) => { - if (!contents) return res.status(404).json({error: 'Torrent contents not found'}); + if (!contents || contents.length < 1) { + return res.status(404).json({error: 'Torrent contents not found'}); + } let indices: Array; if (!stringIndices || stringIndices === 'all') { @@ -557,6 +559,10 @@ router.get('/:hash/contents/:indices/data', (req, res) => { }) .filter((filePath) => isAllowedPath(filePath)); + if (filePathsToDownload.length < 1) { + return res.status(403).json(accessDeniedError()); + } + if (filePathsToDownload.length === 1) { const file = filePathsToDownload[0]; if (!fs.existsSync(file)) return res.status(404).json({error: 'File not found.'});