re-add beatsaver buttons
Some checks failed
Deploy Website / deploy (push) Has been cancelled

This commit is contained in:
Lee
2024-10-09 02:35:34 +01:00
parent 946b3c52dc
commit c9e102d3d6
3 changed files with 57 additions and 20 deletions

View File

@ -0,0 +1,37 @@
import BeatSaverMap from "@/common/database/types/beatsaver-map";
import { db } from "@/common/database/database";
import { beatsaverService } from "@ssr/common/service/impl/beatsaver";
/**
* Gets the map that match the query.
*
* @param query the query to search for
* @returns the map that match the query, or undefined if no map were found
*/
export async function lookupBeatSaverMap(query: string): Promise<BeatSaverMap | undefined> {
let map = await db.beatSaverMaps.get(query);
// The map is cached
if (map != undefined) {
return map;
}
const response = await beatsaverService.lookupMap(query);
// Map not found
if (response == undefined) {
return undefined;
}
const bsr = response.id;
if (bsr == undefined) {
return undefined;
}
// Save map the the db
await db.beatSaverMaps.add({
hash: query,
bsr: bsr,
fullData: response,
});
map = await db.beatSaverMaps.get(query);
return map;
}