mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-22 21:59:49 +08:00
♻️ 迁移postReq
This commit is contained in:
@@ -69,6 +69,7 @@ import TItemBox, { TItemBoxData } from "@comp/app/t-itemBox.vue";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import postReq from "@req/postReq.js";
|
||||
import useHomeStore from "@store/home.js";
|
||||
import TGHttps from "@utils/TGHttps.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { createPost, createTGWindow } from "@utils/TGWindow.js";
|
||||
import { stamp2LastTime } from "@utils/toolFunc.js";
|
||||
@@ -133,20 +134,29 @@ async function loadCover(): Promise<void> {
|
||||
cover.value = poolCover.value[postId];
|
||||
return;
|
||||
}
|
||||
const resp = await postReq.post(postId, {});
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.error(`[PhPoolCard][${resp.retcode}] ${resp.message}`);
|
||||
await TGLogger.Error(`[PhPoolCard][${resp.retcode}] ${resp.message}`);
|
||||
let resp: TGApp.BBS.Post.FullResp | undefined;
|
||||
try {
|
||||
resp = await postReq.post(postId, {});
|
||||
if (resp.retcode !== 0) {
|
||||
showSnackbar.error(`[PhPoolCard][${resp.retcode}] ${resp.message}`);
|
||||
await TGLogger.Warn(`[PhPoolCard][${resp.retcode}] ${resp.message}`);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
const errMsg = TGHttps.getErrMsg(e);
|
||||
showSnackbar.error(`获取帖子封面失败:${errMsg}`);
|
||||
await TGLogger.Error(`[PhPoolCard] 获取帖子封面异常`);
|
||||
await TGLogger.Error(`[PhPoolCard] ${e}`);
|
||||
return;
|
||||
}
|
||||
let coverGet;
|
||||
if (resp.cover) coverGet = resp.cover.url;
|
||||
else if (resp.post.cover && resp.post.cover !== "") coverGet = resp.post.cover;
|
||||
else if (resp.post.images.length > 0) coverGet = resp.post.images[0];
|
||||
if (resp.data.cover) coverGet = resp.data.cover.url;
|
||||
else if (resp.data.post.cover && resp.data.post.cover !== "") coverGet = resp.data.post.cover;
|
||||
else if (resp.data.post.images.length > 0) coverGet = resp.data.post.images[0];
|
||||
else coverGet = "";
|
||||
cover.value = coverGet;
|
||||
if (!poolCover.value) poolCover.value = { [postId]: resp.post.cover };
|
||||
else poolCover.value[postId] = resp.post.cover;
|
||||
if (!poolCover.value) poolCover.value = { [postId]: resp.data.post.cover };
|
||||
else poolCover.value[postId] = resp.data.post.cover;
|
||||
}
|
||||
|
||||
function handlePosition(): void {
|
||||
|
||||
@@ -245,18 +245,26 @@ async function tryAuto(skip: boolean = false): Promise<void> {
|
||||
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}`,
|
||||
let detailResp: TGApp.BBS.Post.FullResp | undefined;
|
||||
try {
|
||||
detailResp = await postDetailRateLimiter.execute(() =>
|
||||
postReq.post(post.post.post_id, ckPost),
|
||||
);
|
||||
if (detailResp.retcode !== 0) {
|
||||
await TGLogger.Script(
|
||||
`[米游币任务]获取帖子${post.post.post_id}失败:${detailResp.retcode} ${detailResp.message}`,
|
||||
"warn",
|
||||
);
|
||||
continue;
|
||||
}
|
||||
} catch (e) {
|
||||
const errMsg = TGHttps.getErrMsg(e);
|
||||
await TGLogger.Script(`[米游币任务]获取帖子${post.post.post_id}异常:${errMsg}`, "error");
|
||||
continue;
|
||||
}
|
||||
viewCnt++;
|
||||
if (likeCnt < 5) {
|
||||
const isLike = (detailResp.self_operation?.upvote_type ?? 0) > 0;
|
||||
const isLike = (detailResp.data.self_operation?.upvote_type ?? 0) > 0;
|
||||
if (isLike) {
|
||||
await TGLogger.Script(`[米游币任务]帖子${post.post.post_id}已点赞,跳过`);
|
||||
continue;
|
||||
|
||||
@@ -76,6 +76,7 @@ import showSnackbar from "@comp/func/snackbar.js";
|
||||
import bbsEnum from "@enum/bbs.js";
|
||||
import postReq from "@req/postReq.js";
|
||||
import { emit } from "@tauri-apps/api/event";
|
||||
import TGHttps from "@utils/TGHttps.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { computed, ref, shallowRef, watch } from "vue";
|
||||
|
||||
@@ -171,31 +172,41 @@ async function reloadReply(): Promise<void> {
|
||||
|
||||
async function loadReply(): Promise<void> {
|
||||
loading.value = true;
|
||||
const resp = await postReq.reply.main(
|
||||
props.postId,
|
||||
props.gid,
|
||||
isHot.value,
|
||||
lastId.value,
|
||||
onlyLz.value,
|
||||
replyOrder.value,
|
||||
);
|
||||
console.debug("[VpBtnReply] Load Reply Response:", resp);
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
await TGLogger.Warn(`[VpBtnReply] Load Reply Error: ${resp.retcode} - ${resp.message}`);
|
||||
let resp: TGApp.BBS.Reply.MainResp | undefined;
|
||||
try {
|
||||
resp = await postReq.reply.main(
|
||||
props.postId,
|
||||
props.gid,
|
||||
isHot.value,
|
||||
lastId.value,
|
||||
onlyLz.value,
|
||||
replyOrder.value,
|
||||
);
|
||||
console.debug("[VpBtnReply] Load Reply Response:", resp);
|
||||
if (resp.retcode !== 0) {
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
await TGLogger.Warn(`[VpBtnReply] Load Reply Error: ${resp.retcode} - ${resp.message}`);
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
const errMsg = TGHttps.getErrMsg(e);
|
||||
showSnackbar.error(`获取回复失败:${errMsg}`);
|
||||
await TGLogger.Error(`[VpBtnReply] 获取回复异常`);
|
||||
await TGLogger.Error(`[VpBtnReply] ${e}`);
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
isLast.value = resp.is_last;
|
||||
lastId.value = resp.last_id;
|
||||
pinId.value = resp.pin_reply_id;
|
||||
reply.value = reply.value.concat(resp.list);
|
||||
isLast.value = resp.data.is_last;
|
||||
lastId.value = resp.data.last_id;
|
||||
pinId.value = resp.data.pin_reply_id;
|
||||
reply.value = reply.value.concat(resp.data.list);
|
||||
loading.value = false;
|
||||
if (isLast.value) {
|
||||
showSnackbar.warn("没有更多了");
|
||||
return;
|
||||
}
|
||||
showSnackbar.success(`成功加载${resp.list.length}条回复`);
|
||||
showSnackbar.success(`成功加载${resp.data.list.length}条回复`);
|
||||
}
|
||||
|
||||
async function handleDebug(): Promise<void> {
|
||||
|
||||
@@ -25,9 +25,12 @@
|
||||
<script lang="ts" setup>
|
||||
import TOverlay from "@comp/app/t-overlay.vue";
|
||||
import TPostcard from "@comp/app/t-postcard.vue";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import bbsReq from "@req/bbsReq.js";
|
||||
import postReq from "@req/postReq.js";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import TGHttps from "@utils/TGHttps.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { nextTick, onMounted, shallowRef, useTemplateRef, watch } from "vue";
|
||||
|
||||
type TpoCollectionProps = { collection: TGApp.BBS.Post.Collection; gid: number };
|
||||
@@ -64,7 +67,24 @@ async function refreshInfo(): Promise<void> {
|
||||
}
|
||||
|
||||
async function refreshPosts(): Promise<void> {
|
||||
postList.value = await postReq.collection(props.collection.collection_id);
|
||||
let resp: TGApp.BBS.Collection.PostsResp | undefined;
|
||||
try {
|
||||
resp = await postReq.collection(props.collection.collection_id);
|
||||
if (resp.retcode !== 0) {
|
||||
showSnackbar.error(`获取合集帖子失败:[${resp.retcode}] ${resp.message}`);
|
||||
await TGLogger.Warn(
|
||||
`[VpOverlayCollection] 获取合集帖子失败:[${resp.retcode}] ${resp.message}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
const errMsg = TGHttps.getErrMsg(e);
|
||||
showSnackbar.error(`获取合集帖子失败:${errMsg}`);
|
||||
await TGLogger.Error(`[VpOverlayCollection] 获取合集帖子异常`);
|
||||
await TGLogger.Error(`[VpOverlayCollection] ${e}`);
|
||||
return;
|
||||
}
|
||||
postList.value = resp.data.posts;
|
||||
}
|
||||
|
||||
async function toOuterCollect(): Promise<void> {
|
||||
|
||||
@@ -43,6 +43,8 @@ import { useBoxReachBottom } from "@hooks/reachBottom.js";
|
||||
import postReq from "@req/postReq.js";
|
||||
import useBBSStore from "@store/bbs.js";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import TGHttps from "@utils/TGHttps.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref, shallowRef, useTemplateRef, watch } from "vue";
|
||||
|
||||
@@ -161,14 +163,30 @@ async function searchPosts(): Promise<void> {
|
||||
load.value = false;
|
||||
return;
|
||||
}
|
||||
const res = await postReq.search(gameId.value, search.value, lastId.value, sortType.value);
|
||||
if (lastId.value === "") results.value = res.posts;
|
||||
else results.value = results.value.concat(res.posts);
|
||||
lastId.value = res.last_id;
|
||||
isLast.value = res.is_last;
|
||||
let res: TGApp.BBS.Post.SearchResp | undefined;
|
||||
try {
|
||||
res = await postReq.search(gameId.value, search.value, lastId.value, sortType.value);
|
||||
if (res.retcode !== 0) {
|
||||
showSnackbar.error(`搜索失败:[${res.retcode}] ${res.message}`);
|
||||
await TGLogger.Warn(`[VpOverlaySearch] 搜索失败:[${res.retcode}] ${res.message}`);
|
||||
load.value = false;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
const errMsg = TGHttps.getErrMsg(e);
|
||||
showSnackbar.error(`搜索失败:${errMsg}`);
|
||||
await TGLogger.Error(`[VpOverlaySearch] 搜索异常`);
|
||||
await TGLogger.Error(`[VpOverlaySearch] ${e}`);
|
||||
load.value = false;
|
||||
return;
|
||||
}
|
||||
if (lastId.value === "") results.value = res.data.posts;
|
||||
else results.value = results.value.concat(res.data.posts);
|
||||
lastId.value = res.data.last_id;
|
||||
isLast.value = res.data.is_last;
|
||||
load.value = false;
|
||||
if (!visible.value) visible.value = true;
|
||||
showSnackbar.success(`成功加载${res.posts.length}条数据`);
|
||||
showSnackbar.success(`成功加载${res.data.posts.length}条数据`);
|
||||
}
|
||||
|
||||
async function toUserProfile(user: TGApp.BBS.Post.User, gid: number): Promise<void> {
|
||||
|
||||
@@ -49,6 +49,8 @@ import { useBoxReachBottom } from "@hooks/reachBottom.js";
|
||||
import bbsReq from "@req/bbsReq.js";
|
||||
import postReq from "@req/postReq.js";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import TGHttps from "@utils/TGHttps.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { getUserAvatar } from "@utils/toolFunc.js";
|
||||
import { computed, ref, shallowRef, useTemplateRef, watch } from "vue";
|
||||
|
||||
@@ -128,18 +130,29 @@ async function loadPosts(): Promise<void> {
|
||||
load.value = false;
|
||||
return;
|
||||
}
|
||||
const resp = await postReq.user.post(props.uid, 0, offset.value);
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.warn(`[${resp.retcode}] ${resp.message}`);
|
||||
let resp: TGApp.BBS.Post.UserPostResp | undefined;
|
||||
try {
|
||||
resp = await postReq.user.post(props.uid, 0, offset.value);
|
||||
if (resp.retcode !== 0) {
|
||||
showSnackbar.warn(`[${resp.retcode}] ${resp.message}`);
|
||||
load.value = false;
|
||||
visible.value = false;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
const errMsg = TGHttps.getErrMsg(e);
|
||||
showSnackbar.error(`获取用户帖子失败:${errMsg}`);
|
||||
await TGLogger.Error(`[VpOverlayUser] 获取用户帖子异常`);
|
||||
await TGLogger.Error(`[VpOverlayUser] ${e}`);
|
||||
load.value = false;
|
||||
visible.value = false;
|
||||
return;
|
||||
}
|
||||
offset.value = resp.next_offset;
|
||||
isLast.value = resp.is_last;
|
||||
results.value = results.value.concat(resp.list);
|
||||
offset.value = resp.data.next_offset;
|
||||
isLast.value = resp.data.is_last;
|
||||
results.value = results.value.concat(resp.data.list);
|
||||
load.value = false;
|
||||
showSnackbar.success(`成功加载${resp.list.length}条数据`);
|
||||
showSnackbar.success(`成功加载${resp.data.list.length}条数据`);
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -114,6 +114,8 @@ import { event, path } from "@tauri-apps/api";
|
||||
import { emit, type Event, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { save } from "@tauri-apps/plugin-dialog";
|
||||
import { writeTextFile } from "@tauri-apps/plugin-fs";
|
||||
import TGHttps from "@utils/TGHttps.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { generateShareImg } from "@utils/TGShare.js";
|
||||
import { getNearTime, getUserAvatar, timestampToDate } from "@utils/toolFunc.js";
|
||||
import {
|
||||
@@ -235,22 +237,30 @@ async function showReply(): Promise<void> {
|
||||
|
||||
async function loadSub(): Promise<void> {
|
||||
loading.value = true;
|
||||
const resp = await postReq.reply.sub(
|
||||
props.modelValue.reply.floor_id,
|
||||
props.modelValue.reply.game_id,
|
||||
props.modelValue.reply.post_id,
|
||||
lastId.value,
|
||||
);
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
let resp: TGApp.BBS.Reply.SubResp | undefined;
|
||||
try {
|
||||
resp = await postReq.reply.sub(
|
||||
props.modelValue.reply.floor_id,
|
||||
props.modelValue.reply.game_id,
|
||||
props.modelValue.reply.post_id,
|
||||
lastId.value,
|
||||
);
|
||||
if (resp.retcode !== 0) {
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
const errMsg = TGHttps.getErrMsg(e);
|
||||
showSnackbar.error(`获取子回复失败:${errMsg}`);
|
||||
await TGLogger.Error(`[VpReplyItem] 获取子回复异常`);
|
||||
await TGLogger.Error(`[VpReplyItem] ${e}`);
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
isLast.value = resp.is_last;
|
||||
lastId.value = resp.last_id;
|
||||
// Filter out duplicates using persistent existingIds Set
|
||||
const newReplies = resp.list.filter((r) => !existingIds.has(r.reply.reply_id));
|
||||
// Add new reply IDs to the Set
|
||||
isLast.value = resp.data.is_last;
|
||||
lastId.value = resp.data.last_id;
|
||||
const newReplies = resp.data.list.filter((r) => !existingIds.has(r.reply.reply_id));
|
||||
newReplies.forEach((r) => existingIds.add(r.reply.reply_id));
|
||||
subReplies.value = subReplies.value.concat(newReplies);
|
||||
loading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user