mirror of
https://github.com/zoriya/flood.git
synced 2026-06-05 03:39:24 +00:00
server: torrents: handle no content and access denied cases in download
This commit is contained in:
@@ -541,7 +541,9 @@ router.get('/:hash/contents/:indices/data', (req, res) => {
|
|||||||
if (!selectedTorrent) return res.status(404).json({error: 'Torrent not found.'});
|
if (!selectedTorrent) return res.status(404).json({error: 'Torrent not found.'});
|
||||||
|
|
||||||
return req.services?.clientGatewayService?.getTorrentContents(hash).then((contents) => {
|
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<number>;
|
let indices: Array<number>;
|
||||||
if (!stringIndices || stringIndices === 'all') {
|
if (!stringIndices || stringIndices === 'all') {
|
||||||
@@ -557,6 +559,10 @@ router.get('/:hash/contents/:indices/data', (req, res) => {
|
|||||||
})
|
})
|
||||||
.filter((filePath) => isAllowedPath(filePath));
|
.filter((filePath) => isAllowedPath(filePath));
|
||||||
|
|
||||||
|
if (filePathsToDownload.length < 1) {
|
||||||
|
return res.status(403).json(accessDeniedError());
|
||||||
|
}
|
||||||
|
|
||||||
if (filePathsToDownload.length === 1) {
|
if (filePathsToDownload.length === 1) {
|
||||||
const file = filePathsToDownload[0];
|
const file = filePathsToDownload[0];
|
||||||
if (!fs.existsSync(file)) return res.status(404).json({error: 'File not found.'});
|
if (!fs.existsSync(file)) return res.status(404).json({error: 'File not found.'});
|
||||||
|
|||||||
Reference in New Issue
Block a user