This repository has been archived on 2023-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
Files
scoresaber-reloaded/src/network/queues/beatmaps/api-queue.js

24 lines
809 B
JavaScript
Raw Normal View History

2023-10-17 23:38:18 +01:00
import { default as createQueue, PRIORITY } from "../http-queue";
import { substituteVars } from "../../../utils/format";
2023-10-17 21:42:37 +01:00
2023-10-17 23:38:18 +01:00
const BEATMAPS_API_URL = "https://api.beatsaver.com/";
const SONG_BY_HASH_URL = BEATMAPS_API_URL + "/maps/hash/${hash}";
const SONG_BY_KEY_URL = BEATMAPS_API_URL + "/maps/id/${key}";
2023-10-17 21:42:37 +01:00
export default (options = {}) => {
const queue = createQueue(options);
2023-10-17 23:38:18 +01:00
const { fetchJson, fetchHtml, ...queueToReturn } = queue;
2023-10-17 21:42:37 +01:00
2023-10-17 23:38:18 +01:00
const byHash = async (hash, priority = PRIORITY.FG_LOW, options = {}) =>
fetchJson(substituteVars(SONG_BY_HASH_URL, { hash }), options, priority);
const byKey = async (key, priority = PRIORITY.FG_LOW, options = {}) =>
fetchJson(substituteVars(SONG_BY_KEY_URL, { key }), options, priority);
2023-10-17 21:42:37 +01:00
return {
byHash,
byKey,
...queueToReturn,
2023-10-17 23:38:18 +01:00
};
};