Skip to content

Commit

Permalink
Only get map info by calling tm.io if user is authenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
Bux42 committed Jul 22, 2024
1 parent 5cf6791 commit 3fb1b83
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions server/src/routes/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ router.get('/:mapUID', async (req: Request, res: Response, next: Function) => {
router.get('/:mapUID/info', async (req: Request, res: Response) => {
let mapData = {};

// fetch tm.io data
try {
const tmxRes = await axios.get(`https://trackmania.io/api/map/${req.params.mapUID}`, {
withCredentials: true,
headers: { 'User-Agent': 'TMDojo API - https://github.com/Bux42/TMDojo' },
});
if (!req.user) {
// Only call tm.io if user is authenticated
res.status(401).send();
} else {
// fetch tm.io data
try {
const tmxRes = await axios.get(`https://trackmania.io/api/map/${req.params.mapUID}`, {
withCredentials: true,
headers: { 'User-Agent': 'TMDojo API - https://github.com/Bux42/TMDojo' },
});

const tmioData = tmxRes.data;
mapData = { ...mapData, ...tmioData };
} catch (error) {
req.log.error(`mapsRouter: tm.io request failed with error ${error.toString()}`);
const tmioData = tmxRes.data;
mapData = { ...mapData, ...tmioData };
} catch (error) {
req.log.error(`mapsRouter: tm.io request failed with error ${error.toString()}`);
}
res.send(mapData);
}

res.send(mapData);
});

/**
Expand Down

0 comments on commit 3fb1b83

Please sign in to comment.