2024-04-18 10:46:06 +03:00
|
|
|
import axios from "axios";
|
|
|
|
import { JSDOM } from "jsdom";
|
2024-04-28 00:40:05 +03:00
|
|
|
|
|
|
|
export interface Steam250Game {
|
|
|
|
title: string;
|
|
|
|
objectID: string;
|
|
|
|
}
|
2024-04-18 10:46:06 +03:00
|
|
|
|
2024-04-19 00:26:17 +03:00
|
|
|
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-28 01:54:37 +03:00
|
|
|
return Array.from(document.querySelectorAll(".appline .title a"))
|
|
|
|
.map(($title: HTMLAnchorElement) => {
|
2024-04-19 00:26:17 +03:00
|
|
|
const steamGameUrl = $title.href;
|
|
|
|
if (!steamGameUrl) return null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: $title.textContent,
|
|
|
|
objectID: steamGameUrl.split("/").pop(),
|
2024-04-28 01:54:37 +03:00
|
|
|
} as Steam250Game;
|
|
|
|
})
|
|
|
|
.filter((game) => game != null);
|
2024-04-18 10:46:06 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const steam250Paths = [
|
|
|
|
"/hidden_gems",
|
|
|
|
`/${new Date().getFullYear()}`,
|
|
|
|
"/top250",
|
|
|
|
"/most_played",
|
|
|
|
];
|
|
|
|
|
2024-04-28 00:40:05 +03:00
|
|
|
export const getSteam250List = async () => {
|
|
|
|
const gamesPromises = steam250Paths.map((path) => requestSteam250(path));
|
|
|
|
const gamesList = (await Promise.all(gamesPromises)).flat();
|
2024-04-28 02:42:28 +03:00
|
|
|
|
|
|
|
const gamesMap = gamesList.reduce((map, item) => {
|
|
|
|
map.set(item.objectID, item);
|
|
|
|
return map;
|
|
|
|
}, new Map<string, Steam250Game>());
|
|
|
|
|
|
|
|
return [...gamesMap.values()];
|
2024-04-18 10:46:06 +03:00
|
|
|
};
|