Skip to content

Commit

Permalink
Update main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
o0shojo0o committed Oct 7, 2024
1 parent ceeef77 commit ed71e78
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ app.get('/api/Statistics', async (req, res) => {
app.get('/api/LastVersion', async (req, res) => {
const sourceIP = tools.getIPFromRequest(req);
const rawUrl = tools.getRawURLFromRequest(req);
const uuid = req.query.uuid || '';
const releases = (await cache.getOrSet('Releases', () => { return gitRepo.getGitReleases() }, 600)) ?? [];
let lastReleaseData = {};

Expand All @@ -157,14 +158,15 @@ app.get('/api/LastVersion', async (req, res) => {
delete lastReleaseData[key];
}

log.info('{apiPath}: Version {version} successfully delivered', { apiPath: 'LastVersion', version: lastReleaseData.version, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, });
log.info('{apiPath}: Version {version} successfully delivered', { apiPath: 'LastVersion', version: lastReleaseData.version, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, uuid: uuid, });

res.send(lastReleaseData);
});

app.get('/api/LastRelease', async (req, res) => {
const sourceIP = tools.getIPFromRequest(req);
const rawUrl = tools.getRawURLFromRequest(req);
const uuid = req.query.uuid || '';
const releases = (await cache.getOrSet('Releases', () => { return gitRepo.getGitReleases() }, 600)) ?? [];
let lastReleaseData = {};

Expand All @@ -173,7 +175,7 @@ app.get('/api/LastRelease', async (req, res) => {
lastReleaseData = releases.filter(x => x.prerelease == false)[0];
}

log.info('{apiPath}: Version {version} successfully delivered', { apiPath: 'LastRelease', version: lastReleaseData.version, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, });
log.info('{apiPath}: Version {version} successfully delivered', { apiPath: 'LastRelease', version: lastReleaseData.version, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, uuid: uuid, });


res.send(lastReleaseData);
Expand All @@ -182,29 +184,31 @@ app.get('/api/LastRelease', async (req, res) => {
app.get('/api/OfficialReleases', async (req, res) => {
const sourceIP = tools.getIPFromRequest(req);
const rawUrl = tools.getRawURLFromRequest(req);
const uuid = req.query.uuid || '';
const releasesArray = (await cache.getOrSet('Releases', () => { return gitRepo.getGitReleases() }, 600)) ?? [];
let data = { releases: [] };

if (releasesArray.length > 0) {
data.releases = releasesArray.map(x => x.version).filter(x => x != '');
}

log.info('{apiPath}: Version {versions} successfully delivered', { apiPath: 'OfficialReleases', versions: data.releases.map(value => value).join(', '), sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, });
log.info('{apiPath}: Version {versions} successfully delivered', { apiPath: 'OfficialReleases', versions: data.releases.map(value => value).join(', '), sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, uuid: uuid, });

res.send(data);
});

app.get('/api/Releases', async (req, res) => {
const sourceIP = tools.getIPFromRequest(req);
const rawUrl = tools.getRawURLFromRequest(req);
const uuid = req.query.uuid || '';
let releases = await cache.getOrSet('Releases', () => { return gitRepo.getGitReleases() }, 600) ?? [];

if (releases.length > 0) {
// No pre-release and the latest 4 releases
releases = releases.filter(x => x.prerelease == false).slice(0, 4);
}

log.info('{apiPath}: Versions {versions} successfully delivered', { apiPath: 'Releases', versions: releases.map(value => value.version).join(', '), sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, });
log.info('{apiPath}: Versions {versions} successfully delivered', { apiPath: 'Releases', versions: releases.map(value => value.version).join(', '), sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, uuid: uuid });

res.send(releases);
});
Expand All @@ -214,9 +218,10 @@ app.post('/api/SaveBitmap', saveBitmapLimiter, async (req, res) => {
const rawUrl = tools.getRawURLFromRequest(req);
const geoipData = await geoip.lookup(sourceIP);
const client = tools.getClientFromRequest(req);
const uuid = req.query.uuid || '';

if (!req.body) {
log.error('{apiPath}: No body found', { apiPath: 'SaveBitmap', sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, geoip: geoipData, client, });
log.error('{apiPath}: No body found', { apiPath: 'SaveBitmap', sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, geoip: geoipData, client, uuid: uuid, });
res.status(400).send('Not valid body');
return;
}
Expand Down

0 comments on commit ed71e78

Please sign in to comment.