Skip to content

Commit

Permalink
Fix again
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Nov 22, 2024
1 parent 795ec7f commit c449e2b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions routes/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@ router.get('/json', async function(req, res, next) {
router.get('/json/:device', async function (req, res, next) {
try {
const device = req.params.device;

const devices = ['gloves', 'orbit', 'handle', 'chromadeck', 'duo', 'desktop']; // Example devices
const devices = ['gloves', 'orbit', 'handle', 'chromadeck', 'duo', 'desktop'];
const categories = ['firmware', 'editor', 'emulator'];

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 })
Expand All @@ -140,6 +139,19 @@ router.get('/json/:device', async function (req, res, next) {
}
}

// If badge=true, return Shields.io-compatible JSON
if (req.query.badge === 'true') {
const firmwareVersion = latestDownloads.firmware?.version || 'unknown';

return res.json({
schemaVersion: 1,
label: device,
message: firmwareVersion,
color: 'blue',
});
}

// Otherwise, return the full device JSON
res.json(latestDownloads);
} catch (err) {
console.error(err);
Expand Down

0 comments on commit c449e2b

Please sign in to comment.