Skip to content

Commit

Permalink
added downloads json device endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Nov 22, 2024
1 parent 025751c commit bb4489b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions routes/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,37 @@ router.get('/json', async function(req, res, next) {
}
});

router.get('/json/:device', async function (req, res, next) {
try {
const device = req.params.device;

if (!devices.includes(device)) {
return res.status(404).json({ error: 'Device not found' });
}

const latestDownloads = {};

for (const category of categories) {
const latestDownload = await Download.findOne({ device, category })
.sort({ releaseDate: -1 })
.exec();

if (latestDownload) {
latestDownloads[category] = {
version: latestDownload.version,
fileUrl: latestDownload.fileUrl,
fileSize: latestDownload.fileSize,
releaseDate: latestDownload.releaseDate,
downloadCount: latestDownload.downloadCount,
};
}
}

res.json(latestDownloads);
} catch (err) {
console.error(err);
next(err);
}
});

module.exports = router;

0 comments on commit bb4489b

Please sign in to comment.