添加帖子详情请求限流

close #233
This commit is contained in:
BTMuli
2026-03-26 06:00:42 +08:00
parent 8a0543d627
commit 38111b6abd
2 changed files with 106 additions and 2 deletions

View File

@@ -50,6 +50,7 @@ import postReq from "@req/postReq.js";
import useAppStore from "@store/app.js";
import TGLogger from "@utils/TGLogger.js";
import TGNotify from "@utils/TGNotify.js";
import { postDetailRateLimiter } from "@utils/rateLimiter.js";
import { storeToRefs } from "pinia";
import { ref, shallowRef, watch } from "vue";
@@ -216,8 +217,13 @@ async function tryAuto(skip: boolean = false): Promise<void> {
}
}
if (likeCnt < 5 || viewCnt < 3) {
await TGLogger.Script(`[米游币任务]正在浏览帖子${post.post.post_id}`);
const detailResp = await postReq.post(post.post.post_id, ckPost);
const currentCount = postDetailRateLimiter.getRequestCount();
await TGLogger.Script(
`[米游币任务]正在浏览帖子${post.post.post_id} (当前 1 分钟内请求数:${currentCount}/10)`,
);
const detailResp = await postDetailRateLimiter.execute(() =>
postReq.post(post.post.post_id, ckPost),
);
if ("retcode" in detailResp) {
await TGLogger.Script(
`[米游币任务]获取帖子${post.post.post_id}失败:${detailResp.retcode} ${detailResp.message}`,