Skip to content

Commit ac185ba

Browse files
committed
限制请求速率防止429
1 parent a073811 commit ac185ba

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/components/PlayedGames.astro

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ import type { MyPlayedGame, PlayedGame } from "../utils/steamApi.ts";
33
import * as steamApi from "../utils/steamApi.ts";
44
import GameCard from "../components//GameCard.astro";
55
import apps from "../../public/assets/app.json";
6+
import { delay } from "../utils/utils";
67
78
// const appList: { applist: { apps: { appid: string; name: string }[] } } =
89
// await steamApi.getAppList();
910
// const apps = appList.applist.apps;
1011
11-
let playedGames: MyPlayedGame[] = (await steamApi.playedGames()).map(
12-
(game) => ({
12+
const appidList = await steamApi.playedGames();
13+
let debugNum = 0;
14+
let playedGames: MyPlayedGame[] = [];
15+
for (const game of appidList) {
16+
console.log(debugNum++);
17+
await delay(500);
18+
playedGames.push({
1319
...game,
1420
name:
1521
apps.find(
1622
(app: { appid: number; name: string }) =>
1723
app.appid.toString() == game.appid
1824
)?.name || "",
1925
imgurl: steamApi.imageUrl(game.appid.toString()),
20-
})
21-
);
26+
});
27+
}
28+
2229
//TODO
2330
// const otherGames = [{
2431
// name:'Escape from Tarkov',

src/utils/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import {
44
type CollectionEntry,
55
} from "astro:content";
66

7+
/**
8+
* 延时
9+
*/
10+
export const delay = (ms: number): Promise<void> => {
11+
return new Promise((resolve) => setTimeout(resolve, ms));
12+
};
13+
714
/**
815
* 计算字符串中单词个数与汉字个数之和
916
*/

0 commit comments

Comments
 (0)