hydra/src/main/services/steam-250.ts

34 lines
913 B
TypeScript
Raw Normal View History

2024-04-21 08:26:29 +03:00
import axios from "axios";
import { JSDOM } from "jsdom";
import { shuffle } from "lodash-es";
export const requestSteam250 = async (path: string) => {
return axios.get(`https://steam250.com${path}`).then((response) => {
const { window } = new JSDOM(response.data);
const { document } = window;
2024-04-25 22:54:38 +03:00
return Array.from(document.querySelectorAll(".appline .title a"))
.filter(($title) => Boolean(($title as HTMLAnchorElement).href))
.map(($title) => {
const steamGameUrl = ($title as HTMLAnchorElement).href;
2024-04-21 08:26:29 +03:00
return {
title: $title.textContent,
objectID: steamGameUrl.split("/").pop(),
};
2024-04-25 22:54:38 +03:00
});
2024-04-21 08:26:29 +03:00
});
};
const steam250Paths = [
"/hidden_gems",
`/${new Date().getFullYear()}`,
"/top250",
"/most_played",
];
export const getRandomSteam250List = async () => {
const [path] = shuffle(steam250Paths);
return requestSteam250(path);
};