diff options
Diffstat (limited to '174bg/discord-bot/source/controllers')
| -rw-r--r-- | 174bg/discord-bot/source/controllers/uex.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/174bg/discord-bot/source/controllers/uex.js b/174bg/discord-bot/source/controllers/uex.js index 615b517..827013a 100644 --- a/174bg/discord-bot/source/controllers/uex.js +++ b/174bg/discord-bot/source/controllers/uex.js @@ -1,24 +1,34 @@ import { get } from "./http.js"; +import { cached } from "../utilities/cache.js"; export async function categories() { - return await get("https://api.uexcorp.uk/2.0/categories"); + return await cached("uex", "categories", 60 * 60 * 1000 * 24, () => + get("https://api.uexcorp.uk/2.0/categories"), + ); } export async function items(id_category) { let items = []; if (!id_category) { - const { data: categories } = await get("https://api.uexcorp.uk/2.0/categories"); + const { data: allCategories } = await categories(); - for (const category of categories) { - const { data: categoryItems } = await get(`https://api.uexcorp.uk/2.0/items?id_category=${category.id}`); + for (const category of allCategories) { + const { data: categoryItems } = await cached( + "uex", + `items:${category.id}`, + 60 * 60 * 1000 * 24, + () => get(`https://api.uexcorp.uk/2.0/items?id_category=${category.id}`), + ); if (!categoryItems) continue; items = items.concat(categoryItems); } } else { - const { data } = await get(`https://api.uexcorp.uk/2.0/items?category=${id_category}`); + const { data } = await cached("uex", `items:${id_category}`, 60 * 60 * 1000 * 24, () => + get(`https://api.uexcorp.uk/2.0/items?category=${id_category}`), + ); items = data; } |
