Skip to content

Commit def652f

Browse files
committed
ff游戏时长获取与游戏列表更新时间
1 parent cd7b6ec commit def652f

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/components/PlayedGames.astro

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
import * as steamApi from "../utils/steamApi.ts";
3+
import * as myApi from "../utils/myApi.ts";
4+
import * as utils from "../utils/utils.ts";
35
import GameCard from "../components//GameCard.astro";
4-
import apps from "../../public/assets/app.json";
6+
// import apps from "../../public/assets/app.json";
57
import orderGames from "../../public/assets/orderGames.json";
68
import { delay } from "../utils/utils";
79
import { ENABLE_REQUEST } from "astro:env/server";
@@ -47,12 +49,23 @@ orderGames.forEach(({ imgurl }) => {
4749
}
4850
});
4951
52+
orderGames.forEach(async (game) => {
53+
if (game.name === "Final Fantasy XIV") {
54+
game.playtime_forever = await myApi.getFfPlayTime();
55+
}
56+
});
57+
5058
playedGames = playedGames
5159
.concat(orderGames)
5260
.sort((a, b) => b.playtime_forever - a.playtime_forever);
61+
62+
const updateTime = utils.getBeijingDateTime();
5363
---
5464

5565
<div>
66+
<div>
67+
<span>上次更新(北京时间):{updateTime}</span>
68+
</div>
5669
{
5770
playedGames.map((game) => {
5871
const { name, playtime_forever, imgurl } = game;

src/utils/myApi.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import get from "axios";
2+
const API_URL = "https://ff.llma.dev";
3+
// 自个搭的阴间服务,有兴趣可以直接问我
4+
export const getFfPlayTime = async () => {
5+
const path = "/llmaget/ff_info";
6+
const res = await get(`${API_URL}${path}`);
7+
return res.data.data.play_time;
8+
};

src/utils/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ switch (PATH_MODULE) {
9494
}
9595
}
9696

97+
export const getBeijingDateTime = () => {
98+
const beijingTime = new Date().toLocaleString("zh-CN", {
99+
timeZone: "Asia/Shanghai",
100+
});
101+
return beijingTime;
102+
};
103+
97104
/**
98105
* 彩笔监视器:
99106
* 以一种难绷的方式打印元素

0 commit comments

Comments
 (0)