Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ export const deleteReplay = async (replay: any) => {
dbCache.set('maps', cachedMaps);
}
};

export const getMapNameByUId = async (mapUId: string) => {
const cachedMaps = await getMapsCache();
const mapCacheMatch = cachedMaps.find((map: any) => map.mapUId === mapUId);

if (mapCacheMatch) {
return mapCacheMatch.mapName;
}
return null;
};
12 changes: 3 additions & 9 deletions server/src/routes/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import { Request, Response } from 'express';
import * as express from 'express';

import axios from 'axios';

import * as db from '../lib/db';
import * as artefacts from '../lib/artefacts';
import { getMapNameByUId } from '../cache';

const router = express.Router();
/**
Expand Down Expand Up @@ -56,13 +55,8 @@ router.get('/:mapUID/info', async (req: Request, res: Response) => {

// 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 };
const mapName = await getMapNameByUId(req.params.mapUID);
mapData = { name: mapName };
} catch (error) {
req.log.error(`mapsRouter: tm.io request failed with error ${error.toString()}`);
}
Expand Down