BL star cache
This commit is contained in:
parent
a05915672b
commit
7fcec62869
41
pages/api/beatleader/stars.js
Normal file
41
pages/api/beatleader/stars.js
Normal file
@ -0,0 +1,41 @@
|
||||
import fetch from "node-fetch";
|
||||
import BLMapStarCache from "../../../src/caches/BLMapStarCache";
|
||||
import WebsiteTypes from "../../../src/consts/LeaderboardType";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const mapHash = req.query.hash.replace("custom_level_", "").toLowerCase();
|
||||
const difficulty = req.query.difficulty;
|
||||
const characteristic = req.query.characteristic;
|
||||
|
||||
if (BLMapStarCache.has(mapHash)) {
|
||||
return res.json({
|
||||
status: "OK",
|
||||
message: "Cache hit for " + mapHash,
|
||||
stars: BLMapStarCache.get(mapHash),
|
||||
});
|
||||
}
|
||||
|
||||
const data = await fetch(
|
||||
WebsiteTypes.BeatLeader.ApiUrl.MapData.replace("%h", mapHash)
|
||||
.replace("%d", difficulty.replace("+", "Plus"))
|
||||
.replace("%m", characteristic),
|
||||
{
|
||||
headers: {
|
||||
"X-Requested-With": "BeatSaber Overlay",
|
||||
},
|
||||
}
|
||||
);
|
||||
if (data.status === 404) {
|
||||
return res.json({
|
||||
status: 404,
|
||||
message: "Unknown hash",
|
||||
});
|
||||
}
|
||||
const json = await data.json();
|
||||
BLMapStarCache.set(mapHash, json.difficulty.stars);
|
||||
return res.json({
|
||||
status: "OK",
|
||||
message: "Cache miss for " + mapHash,
|
||||
stars: json.difficulty.stars,
|
||||
});
|
||||
}
|
3
src/caches/BLMapStarCache.js
Normal file
3
src/caches/BLMapStarCache.js
Normal file
@ -0,0 +1,3 @@
|
||||
const CACHE = new Map();
|
||||
|
||||
module.exports = CACHE;
|
@ -20,7 +20,7 @@ export default class ScoreStats extends Component {
|
||||
|
||||
render() {
|
||||
const data = this.props.data;
|
||||
let currentPP = Utils.calculatePP(
|
||||
const currentPP = Utils.calculatePP(
|
||||
data.mapStarCount,
|
||||
data.percentage.replace("%", ""),
|
||||
data.websiteType
|
||||
|
@ -16,17 +16,10 @@ const WebsiteTypes = {
|
||||
},
|
||||
async getMapStarCount(mapHash, mapDiff, characteristic) {
|
||||
const data = await fetch(
|
||||
this.ApiUrl.MapData.replace("%h", mapHash)
|
||||
.replace("%d", mapDiff.replace("+", "Plus"))
|
||||
.replace("%m", characteristic),
|
||||
{
|
||||
headers: {
|
||||
"X-Requested-With": "BeatSaber Overlay",
|
||||
},
|
||||
}
|
||||
`/api/beatleader/stars?hash=${mapHash}&difficulty=${mapDiff}&characteristic=${characteristic}`
|
||||
);
|
||||
const json = await data.json();
|
||||
return json.difficulty.stars || undefined;
|
||||
return json.stars || undefined;
|
||||
},
|
||||
curve(acc, stars) {
|
||||
var l = 1 - (0.03 * (stars - 3.0)) / 11.0;
|
||||
|
Reference in New Issue
Block a user