From 253cd4a1032fb26c9f470fcf8153625c38e938dd Mon Sep 17 00:00:00 2001 From: Liam <67254223+RealFascinated@users.noreply.github.com> Date: Thu, 20 Oct 2022 18:27:43 +0100 Subject: [PATCH] More api fixes --- pages/api/beatleader/stars.js | 9 +++++---- pages/api/beatsaver/art/[hash].js | 4 ++-- pages/api/beatsaver/map.js | 5 ++++- pages/overlay.js | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pages/api/beatleader/stars.js b/pages/api/beatleader/stars.js index bdfb170..34b9d12 100644 --- a/pages/api/beatleader/stars.js +++ b/pages/api/beatleader/stars.js @@ -12,25 +12,26 @@ const KEY = "BL_MAP_STAR_"; */ export default async function handler(req, res) { const mapHash = req.query.hash.replace("custom_level_", "").toLowerCase(); - const difficulty = req.query.difficulty; + const difficulty = req.query.difficulty.replace(" ", ""); const characteristic = req.query.characteristic; const exists = await RedisUtils.exists(`${KEY}${mapHash}`); if (exists) { const data = await RedisUtils.getValue( - `${KEY}${difficulty}-${characteristic}-${mapHash}` + `${KEY}${difficulty}-${characteristic}-${mapHash}`.replace(" ", "") ); res.setHeader("Cache-Status", "hit"); return res.status(200).json({ status: "OK", stars: Number.parseFloat(data), + difficulty: difficulty, }); } const data = await fetch( WebsiteTypes.BeatLeader.ApiUrl.MapData.replace("%h", mapHash) - .replace("%d", difficulty.replace("+", "Plus")) + .replace("%d", difficulty) .replace("%m", characteristic), { headers: { @@ -46,7 +47,7 @@ export default async function handler(req, res) { } const json = await data.json(); RedisUtils.setValue( - `${KEY}${difficulty}-${characteristic}-${mapHash}`, + `${KEY}${difficulty}-${characteristic}-${mapHash}`.replace(" ", ""), json.difficulty.stars ); res.setHeader("Cache-Status", "miss"); diff --git a/pages/api/beatsaver/art/[hash].js b/pages/api/beatsaver/art/[hash].js index c81a9cc..0ab0f93 100644 --- a/pages/api/beatsaver/art/[hash].js +++ b/pages/api/beatsaver/art/[hash].js @@ -14,7 +14,7 @@ export default async function handler(req, res) { const mapHash = req.query.hash.replace("custom_level_", "").toLowerCase(); const ext = req.query.ext || "jpg"; - const exists = await RedisUtils.exists(`${KEY}${mapHash}`); + const exists = await RedisUtils.exists(`${KEY}${mapHash}`.replace(" ", "")); if (exists) { const data = await RedisUtils.getValue(`${KEY}${mapHash}`); const buffer = Buffer.from(data, "base64"); @@ -38,7 +38,7 @@ export default async function handler(req, res) { buffer = await sharp(buffer).resize(150, 150).toBuffer(); const bytes = buffer.toString("base64"); - await RedisUtils.setValue(`${KEY}${mapHash}`, bytes); + await RedisUtils.setValue(`${KEY}${mapHash}`.replace(" ", ""), bytes); res.setHeader("Cache-Status", "miss"); res.setHeader("Content-Type", "image/" + ext); res.status(200).send(buffer); diff --git a/pages/api/beatsaver/map.js b/pages/api/beatsaver/map.js index 1a9b20c..2fc7216 100644 --- a/pages/api/beatsaver/map.js +++ b/pages/api/beatsaver/map.js @@ -6,7 +6,10 @@ export default async function handler(req, res) { const mapData = await Utils.getMapData(mapHash.replace("custom_level_", "")); if (mapData === undefined) { // Check if a map hash was provided - return res.status(200).json({ error: true, message: "Unknown map" }); + return res.status(404).json({ + status: 404, + message: "Unknown Map Hash", + }); } const data = { // The maps data from the provided map hash diff --git a/pages/overlay.js b/pages/overlay.js index f54fd61..186b654 100644 --- a/pages/overlay.js +++ b/pages/overlay.js @@ -271,7 +271,7 @@ export default class Overlay extends Component { let mapHash = levelId.replace("custom_level_", ""); const mapStars = await LeaderboardType.BeatLeader.getMapStarCount( mapHash, - difficulty, + difficulty.replace("+", "Plus"), characteristic ); this.setState({ mapStarCount: mapStars });