mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-20 09:43:57 +00:00
chore: merge with main
This commit is contained in:
@@ -1,23 +1,31 @@
|
||||
import axios from "axios";
|
||||
import { JSDOM } from "jsdom";
|
||||
import { shuffle } from "lodash-es";
|
||||
|
||||
export interface Steam250Game {
|
||||
title: string;
|
||||
objectID: string;
|
||||
}
|
||||
|
||||
export const requestSteam250 = async (path: string) => {
|
||||
return axios.get(`https://steam250.com${path}`).then((response) => {
|
||||
const { window } = new JSDOM(response.data);
|
||||
const { document } = window;
|
||||
return axios
|
||||
.get(`https://steam250.com${path}`)
|
||||
.then((response) => {
|
||||
const { window } = new JSDOM(response.data);
|
||||
const { document } = window;
|
||||
|
||||
return Array.from(document.querySelectorAll(".appline .title a"))
|
||||
.filter(($title) => Boolean(($title as HTMLAnchorElement).href))
|
||||
.map(($title) => {
|
||||
const steamGameUrl = ($title as HTMLAnchorElement).href;
|
||||
return Array.from(document.querySelectorAll(".appline .title a"))
|
||||
.map(($title) => {
|
||||
const steamGameUrl = ($title as HTMLAnchorElement).href;
|
||||
if (!steamGameUrl) return null;
|
||||
|
||||
return {
|
||||
title: $title.textContent!,
|
||||
objectID: steamGameUrl.split("/").pop()!,
|
||||
};
|
||||
});
|
||||
});
|
||||
return {
|
||||
title: $title.textContent,
|
||||
objectID: steamGameUrl.split("/").pop(),
|
||||
} as Steam250Game;
|
||||
})
|
||||
.filter((game) => game != null);
|
||||
})
|
||||
.catch((_) => [] as Steam250Game[]);
|
||||
};
|
||||
|
||||
const steam250Paths = [
|
||||
@@ -27,7 +35,15 @@ const steam250Paths = [
|
||||
"/most_played",
|
||||
];
|
||||
|
||||
export const getRandomSteam250List = async () => {
|
||||
const [path] = shuffle(steam250Paths);
|
||||
return requestSteam250(path);
|
||||
export const getSteam250List = async () => {
|
||||
const gamesList = (
|
||||
await Promise.all(steam250Paths.map((path) => requestSteam250(path)))
|
||||
).flat();
|
||||
|
||||
const gamesMap: Map<string, Steam250Game> = gamesList.reduce((map, item) => {
|
||||
map.set(item.objectID, item);
|
||||
return map;
|
||||
}, new Map());
|
||||
|
||||
return [...gamesMap.values()];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user