♻️ 迁移postReq

This commit is contained in:
BTMuli
2026-04-14 23:55:33 +08:00
parent 989f56d44c
commit b3b683811a
15 changed files with 374 additions and 192 deletions

View File

@@ -1,3 +1,3 @@
VITE_SENTRY_RELEASE=TeyvatGuide@0.10.0
VITE_COMMIT_HASH=3ded02e1
VITE_BUILD_TIME=1776054886
VITE_COMMIT_HASH=60ddfaee
VITE_BUILD_TIME=1776074393

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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> {

View File

@@ -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> {

View File

@@ -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> {

View File

@@ -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>

View File

@@ -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;

View File

@@ -127,6 +127,7 @@ import TSUserCollection from "@Sqlm/userCollect.js";
import useUserStore from "@store/user.js";
import { event } from "@tauri-apps/api";
import type { UnlistenFn } from "@tauri-apps/api/event";
import TGHttps from "@utils/TGHttps.js";
import TGLogger from "@utils/TGLogger.js";
import { storeToRefs } from "pinia";
import { computed, onMounted, onUnmounted, ref, shallowRef, watch } from "vue";
@@ -379,19 +380,48 @@ async function freshUser(uid?: string): Promise<void> {
}
const uidReal = uid || briefInfo.value.uid;
await showLoading.start(`[${uidReal}]获取用户收藏`);
let res = await postReq.user.collect(cookie.value, uidReal);
while (true) {
if ("retcode" in res) {
let res: TGApp.BBS.Collection.UserPostResp | undefined;
try {
res = await postReq.user.favorite(cookie.value, uidReal);
if (res.retcode !== 0) {
await showLoading.end();
if (res.retcode === 1001) showSnackbar.warn("用户收藏已设为私密,无法获取");
else showSnackbar.error(`[${res.retcode}] ${res.message}`);
break;
return;
}
let posts = res.list;
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
showSnackbar.error(`获取用户收藏失败:${errMsg}`);
await TGLogger.Error(`[PostCollect] 获取用户收藏异常`);
await TGLogger.Error(`[PostCollect] ${e}`);
return;
}
let posts = res.data.list;
await mergePosts(posts, uid || briefInfo.value.uid);
while (!res.data.is_last) {
await showLoading.update(`[offset]${res.data.next_offset} [is_last]${res.data.is_last}`);
try {
res = await postReq.user.favorite(
cookie.value,
uid || briefInfo.value.uid,
res.data.next_offset,
);
if (res.retcode !== 0) {
await showLoading.end();
showSnackbar.error(`[${res.retcode}] ${res.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
showSnackbar.error(`获取用户收藏失败:${errMsg}`);
await TGLogger.Error(`[PostCollect] 获取用户收藏异常`);
await TGLogger.Error(`[PostCollect] ${e}`);
return;
}
posts = res.data.list;
await mergePosts(posts, uid || briefInfo.value.uid);
if (res.is_last) break;
await showLoading.update(`[offset]${res.next_offset} [is_last]${res.is_last}`);
res = await postReq.user.collect(cookie.value, uid || briefInfo.value.uid, res.next_offset);
}
await showLoading.end();
showSnackbar.success("获取用户收藏成功,即将刷新页面");

View File

@@ -232,22 +232,36 @@ async function freshPostData(): Promise<void> {
query: { gid: curGid.value, topic: curTopic.value },
});
document.documentElement.scrollTo({ top: 0, behavior: "smooth" });
const postList = await postReq.topic(curGid.value, curTopic.value, curSortType.value);
if ("retcode" in postList) {
let postList: TGApp.BBS.Topic.PostResp | undefined;
try {
postList = await postReq.topic(curGid.value, curTopic.value, curSortType.value);
if (postList.retcode !== 0) {
await showLoading.end();
isReq.value = false;
showSnackbar.error(`[${postList.retcode}] ${postList.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
showSnackbar.error(`[${postList.retcode}] ${postList.message}`);
isReq.value = false;
showSnackbar.error(`获取帖子列表失败:${errMsg}`);
await TGLogger.Error(`[PostTopic] 获取帖子列表异常`);
await TGLogger.Error(`[PostTopic] ${e}`);
return;
}
await showLoading.update(`数量:${postList.posts.length},是否最后一页:${postList.is_last}`);
await showLoading.update(
`数量:${postList.data.posts.length},是否最后一页:${postList.data.is_last}`,
);
postRaw.value = {
isLast: postList.is_last,
lastId: postList.last_id,
total: postList.posts.length,
isLast: postList.data.is_last,
lastId: postList.data.last_id,
total: postList.data.posts.length,
};
posts.value = postList.posts;
posts.value = postList.data.posts;
await showLoading.end();
isReq.value = false;
showSnackbar.success(`加载了 ${postList.posts.length} 条帖子`);
showSnackbar.success(`加载了 ${postList.data.posts.length} 条帖子`);
}
async function loadMore(): Promise<void> {
@@ -263,29 +277,40 @@ async function loadMore(): Promise<void> {
await showLoading.start(`正在刷新${topicInfo.value?.topic.name}帖子列表`);
const mod20 = postRaw.value.total % 20;
const pageSize = mod20 === 0 ? 20 : 20 - mod20;
const resp = await postReq.topic(
curGid.value,
curTopic.value,
curSortType.value,
postRaw.value.lastId,
pageSize,
);
if ("retcode" in resp) {
let resp: TGApp.BBS.Topic.PostResp | undefined;
try {
resp = await postReq.topic(
curGid.value,
curTopic.value,
curSortType.value,
postRaw.value.lastId,
pageSize,
);
if (resp.retcode !== 0) {
await showLoading.end();
isReq.value = false;
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
return;
}
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.end();
isReq.value = false;
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
showSnackbar.error(`获取帖子列表失败:${errMsg}`);
await TGLogger.Error(`[PostTopic] 获取帖子列表异常`);
await TGLogger.Error(`[PostTopic] ${e}`);
return;
}
await showLoading.update(`数量:${resp.posts.length},是否最后一页:${resp.is_last}`);
await showLoading.update(`数量:${resp.data.posts.length},是否最后一页:${resp.data.is_last}`);
postRaw.value = {
isLast: resp.is_last,
lastId: resp.last_id,
total: postRaw.value.total + resp.posts.length,
isLast: resp.data.is_last,
lastId: resp.data.last_id,
total: postRaw.value.total + resp.data.posts.length,
};
posts.value = posts.value.concat(resp.posts);
posts.value = posts.value.concat(resp.data.posts);
await showLoading.end();
isReq.value = false;
showSnackbar.success(`加载了 ${resp.posts.length} 条帖子`);
showSnackbar.success(`加载了 ${resp.data.posts.length} 条帖子`);
}
function searchPost(): void {

View File

@@ -1,61 +1,59 @@
/**
* 帖子相关的请求
* @since Beta v0.9.9
* @since Beta v0.10.1
*/
import bbsEnum from "@enum/bbs.js";
import { getRequestHeader } from "@utils/getRequestHeader.js";
import TGHttp from "@utils/TGHttp.js";
import TGHttps from "@utils/TGHttps.js";
// BBSApiPostBaseUrl => bapBu
const bapBu: Readonly<string> = "https://bbs-api.miyoushe.com/post/wapi/";
const Referer: Readonly<string> = "https://bbs.mihoyo.com/";
/**
* 获取单个帖子信息
* @since Beta v0.9.1
* @since Beta v0.10.1
* @param postId - 帖子 ID
* @param cookie - Cookie
* @returns 帖子信息
* @returns 帖子信息响应数据
*/
async function getPostFull(
postId: number | string,
cookie?: Record<string, string>,
): Promise<TGApp.BBS.Post.FullData | TGApp.BBS.Response.Base> {
): Promise<TGApp.BBS.Post.FullResp> {
const param = { post_id: postId, read: 1 };
const header = {
...getRequestHeader(cookie ?? {}, "GET", param, "K2", true),
"x-rpc-client_type": "2",
};
const resp = await TGHttp<TGApp.BBS.Post.FullResp>(`${bapBu}getPostFull`, {
method: "GET",
const resp = await TGHttps.get<TGApp.BBS.Post.FullResp>(`${bapBu}getPostFull`, {
headers: header,
query: param,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data.post;
return resp.data;
}
/**
* 获取合集帖子
* @since Beta v0.7.9
* @since Beta v0.10.1
* @param collectionId - 合集 ID
* @returns 帖子数据
* @returns 合集帖子响应数据
*/
async function getPostFullInCollection(
collectionId: string,
): Promise<Array<TGApp.BBS.Post.FullData>> {
return (
await TGHttp<TGApp.BBS.Collection.PostsResp>(`${bapBu}getPostFullInCollection`, {
method: "GET",
): Promise<TGApp.BBS.Collection.PostsResp> {
const resp = await TGHttps.get<TGApp.BBS.Collection.PostsResp>(
`${bapBu}getPostFullInCollection`,
{
headers: { "Content-Type": "application/json", referer: Referer, cookie: "" },
query: { collection_id: collectionId },
})
).data.posts;
},
);
return resp.data;
}
/**
* 获取帖子回复信息
* @since Beta v0.9.9
* @since Beta v0.10.1
* @param postId - 帖子 ID
* @param gid - 社区 ID
* @param isHot - 是否热门
@@ -63,7 +61,7 @@ async function getPostFullInCollection(
* @param orderType - 排序类型
* @param lastId - 最后 ID
* @param size - 每页大小
* @returns 回复信息
* @returns 回复信息响应数据
*/
async function getPostReplies(
postId: string,
@@ -73,17 +71,13 @@ async function getPostReplies(
onlyMaster: boolean = false,
orderType?: TGApp.BBS.Reply.ReplyOrderTypeEnum,
size: number = 20,
): Promise<TGApp.BBS.Reply.MainRes | TGApp.BBS.Response.Base> {
type GprParam = {
post_id: string;
gids: number;
is_hot: boolean;
size: number;
last_id?: string;
order_type?: TGApp.BBS.Reply.ReplyOrderTypeEnum;
only_master?: boolean;
): Promise<TGApp.BBS.Reply.MainResp> {
const params: TGApp.BBS.Reply.MainReplyParam = {
post_id: postId,
gids: gid,
is_hot: isHot,
size: size,
};
const params: GprParam = { post_id: postId, gids: gid, is_hot: isHot, size: size };
if (lastId) params.last_id = lastId;
if (orderType) params.order_type = orderType;
if (onlyMaster) {
@@ -91,24 +85,22 @@ async function getPostReplies(
params.only_master = onlyMaster;
params.order_type = 1;
}
const resp = await TGHttp<TGApp.BBS.Reply.MainResp>(`${bapBu}getPostReplies`, {
method: "GET",
const resp = await TGHttps.get<TGApp.BBS.Reply.MainResp>(`${bapBu}getPostReplies`, {
headers: { referer: Referer },
query: params,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* 获取帖子子回复信息
* @since Beta v0.7.1
* @since Beta v0.10.1
* @param floorId - 楼层 ID
* @param gid - 社区 ID
* @param postId - 帖子 ID
* @param lastId - 最后 ID
* @param size - 每页大小
* @returns 子回复
* @returns 子回复响应数据
*/
async function getSubReplies(
floorId: number,
@@ -116,34 +108,30 @@ async function getSubReplies(
postId: string,
lastId?: string,
size: number = 20,
): Promise<TGApp.BBS.Reply.SubRes | TGApp.BBS.Response.Base> {
type GsrParam = {
floor_id: number;
gids: number;
post_id: string;
size: number;
last_id?: string;
): Promise<TGApp.BBS.Reply.SubResp> {
const params: TGApp.BBS.Reply.SubReplyParam = {
floor_id: floorId,
gids: gid,
post_id: postId,
size: size,
};
const params: GsrParam = { floor_id: floorId, gids: gid, post_id: postId, size: size };
if (lastId) params.last_id = lastId;
const resp = await TGHttp<TGApp.BBS.Reply.SubResp>(`${bapBu}getSubReplies`, {
method: "GET",
const resp = await TGHttps.get<TGApp.BBS.Reply.SubResp>(`${bapBu}getSubReplies`, {
headers: { referer: Referer },
query: params,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* 获取特定话题帖子列表
* @since Beta v0.9.9
* @since Beta v0.10.1
* @param gid - 游戏分区 ID
* @param topicId - 话题 ID
* @param orderType - 排序方式
* @param lastId - 最后一条帖子 ID
* @param size - 每页大小
* @returns 话题帖子列表数据
* @returns 话题帖子列表响应数据
*/
async function getTopicPostList(
gid: number,
@@ -151,9 +139,8 @@ async function getTopicPostList(
orderType: TGApp.BBS.Post.PostTopicSortTypeEnum = bbsEnum.post.topicSortType.LATEST,
lastId?: string,
size: number = 20,
): Promise<TGApp.BBS.Topic.PostRes | TGApp.BBS.Response.Base> {
const resp = await TGHttp<TGApp.BBS.Topic.PostResp>(`${bapBu}getTopicPostList`, {
method: "GET",
): Promise<TGApp.BBS.Topic.PostResp> {
const resp = await TGHttps.get<TGApp.BBS.Topic.PostResp>(`${bapBu}getTopicPostList`, {
headers: { referer: Referer },
query: {
gids: gid,
@@ -164,77 +151,73 @@ async function getTopicPostList(
page_size: size,
},
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* 获取用户发布帖子
* @since Beta v0.7.2
* @since Beta v0.10.1
* @param uid - 用户 ID
* @param gid - 社区 ID
* @param offset - 偏移量
* @returns 用户帖子
* @returns 用户帖子响应数据
*/
async function getUserPost(
uid: string,
gid: number,
offset?: string,
): Promise<TGApp.BBS.Post.UserPostRes | TGApp.BBS.Response.Base> {
const params = offset ? { uid, gids: gid, offset, size: 20 } : { uid, gids: gid, size: 20 };
const resp = await TGHttp<TGApp.BBS.Post.UserPostResp>(`${bapBu}userPost`, {
method: "GET",
): Promise<TGApp.BBS.Post.UserPostResp> {
const params: Record<string, string | number> = offset
? { uid, gids: gid, offset, size: 20 }
: { uid, gids: gid, size: 20 };
const resp = await TGHttps.get<TGApp.BBS.Post.UserPostResp>(`${bapBu}userPost`, {
headers: { referer: Referer },
query: params,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* 搜索帖子
* @since Beta v0.9.9
* @since Beta v0.10.1
* @param gid - 游戏分区 ID
* @param keyword - 关键词
* @param lastId - 最后一条帖子 ID
* @param orderType - 排序方式 1-最热2-最新
* @returns 返回帖子列表
* @returns 搜索帖子响应数据
*/
async function searchPosts(
gid: string = "2",
keyword: string,
lastId: string,
orderType: TGApp.BBS.Post.SearchSortTypeEnum,
): Promise<TGApp.BBS.Post.SearchRes> {
return (
await TGHttp<TGApp.BBS.Post.SearchResp>(`${bapBu}searchPosts`, {
method: "GET",
headers: { "Content-Type": "application/json" },
query: { gids: gid, keyword, last_id: lastId, size: 20, order_type: orderType },
})
).data;
): Promise<TGApp.BBS.Post.SearchResp> {
const resp = await TGHttps.get<TGApp.BBS.Post.SearchResp>(`${bapBu}searchPosts`, {
headers: { "Content-Type": "application/json" },
query: { gids: gid, keyword, last_id: lastId, size: 20, order_type: orderType },
});
return resp.data;
}
/**
* 获取用户收藏帖子
* @since Beta v0.7.4
* @since Beta v0.10.1
* @param cookie - 用户 cookie
* @param uid - 用户 UID
* @param offset - 偏移量
* @returns 用户收藏帖子
* @returns 用户收藏帖子响应数据
*/
async function userFavouritePost(
cookie: TGApp.App.Account.Cookie,
uid: string,
offset: string = "",
): Promise<TGApp.BBS.Collection.UserPostRes | TGApp.BBS.Response.Base> {
): Promise<TGApp.BBS.Collection.UserPostResp> {
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
const params = { size: "20", uid, offset };
const resp = await TGHttp<TGApp.BBS.Collection.UserPostResp | TGApp.BBS.Response.Base>(
`${bapBu}userFavouritePost`,
{ method: "GET", headers: getRequestHeader(ck, "GET", params), query: params },
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
const resp = await TGHttps.get<TGApp.BBS.Collection.UserPostResp>(`${bapBu}userFavouritePost`, {
headers: getRequestHeader(ck, "GET", params),
query: params,
});
return resp.data;
}
@@ -244,7 +227,7 @@ const postReq = {
topic: getTopicPostList,
reply: { main: getPostReplies, sub: getSubReplies },
search: searchPosts,
user: { post: getUserPost, collect: userFavouritePost },
user: { post: getUserPost, favorite: userFavouritePost },
};
export default postReq;

View File

@@ -12,12 +12,9 @@ declare namespace TGApp.BBS.Post {
/**
* 帖子详情返回数据
* @since Beta v0.7.2
* @since Beta v0.10.1
*/
type FullRes = {
/** 帖子数据 */
post: FullData;
};
type FullRes = FullData;
/**
* 搜索结果返回响应

View File

@@ -1,6 +1,6 @@
/**
* 回复数据类型定义文件
* @since Beta v0.9.9
* @since Beta v0.10.1
*/
declare namespace TGApp.BBS.Reply {
@@ -23,6 +23,44 @@ declare namespace TGApp.BBS.Reply {
*/
type ReplyOrderTypeEnum = (typeof ReplyOrderType)[keyof typeof ReplyOrderType];
/**
* 主回复请求参数
* @since Beta v0.10.1
*/
type MainReplyParam = {
/** 帖子 ID */
post_id: string;
/** 社区 ID */
gids: number;
/** 是否热门排序 */
is_hot: boolean;
/** 每页大小 */
size: number;
/** 最后一条回复 ID用于分页 */
last_id?: string;
/** 排序类型 */
order_type?: ReplyOrderTypeEnum;
/** 是否只看楼主 */
only_master?: boolean;
};
/**
* 子回复请求参数
* @since Beta v0.10.1
*/
type SubReplyParam = {
/** 楼层 ID */
floor_id: number;
/** 社区 ID */
gids: number;
/** 帖子 ID */
post_id: string;
/** 每页大小 */
size: number;
/** 最后一条子回复 ID用于分页 */
last_id?: string;
};
/**
* 帖子回复数据类型
* @since Beta v0.7.1

View File

@@ -62,6 +62,7 @@ import showSnackbar from "@comp/func/snackbar.js";
import postReq from "@req/postReq.js";
import useAppStore from "@store/app.js";
import useUserStore from "@store/user.js";
import TGHttps from "@utils/TGHttps.js";
import TGLogger from "@utils/TGLogger.js";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref, shallowRef } from "vue";
@@ -85,15 +86,23 @@ onMounted(async () => {
}
let ck: Record<string, string> | undefined = undefined;
if (cookie.value) ck = { ltoken: cookie.value.ltoken, ltuid: cookie.value.ltuid };
const resp = await postReq.post(postId, ck);
if ("retcode" in resp) {
await showLoading.empty("获取数据失败", `[${resp.retcode}]${resp.message}`);
showSnackbar.error(`[${resp.retcode}]${resp.message}`);
await TGLogger.Error(`[${postId}]获取帖子数据失败:${resp.retcode} ${resp.message}`);
try {
const resp = await postReq.post(postId, ck);
if (resp.retcode !== 0) {
await showLoading.empty("获取数据失败", `[${resp.retcode}]${resp.message}`);
showSnackbar.error(`[${resp.retcode}]${resp.message}`);
await TGLogger.Warn(`[${postId}]获取帖子数据失败:${resp.retcode} ${resp.message}`);
return;
}
jsonData.value = resp.data;
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.empty("获取数据失败", errMsg);
showSnackbar.error(errMsg);
await TGLogger.Error(`[${postId}]获取帖子数据失败:${errMsg}`);
return;
}
await showLoading.update("正在渲染帖子数据");
jsonData.value = resp;
try {
parseData.value = JSON.parse(jsonData.value.post.content);
} catch (err) {

View File

@@ -185,6 +185,7 @@ import { app, webviewWindow } from "@tauri-apps/api";
import { emit, type Event, listen, type UnlistenFn } from "@tauri-apps/api/event";
import { parseLink, parsePost } from "@utils/linkParser.js";
import TGClient from "@utils/TGClient.js";
import TGHttps from "@utils/TGHttps.js";
import TGLogger from "@utils/TGLogger.js";
import { createTGWindow } from "@utils/TGWindow.js";
import { storeToRefs } from "pinia";
@@ -240,16 +241,25 @@ onMounted(async () => {
if (cookie.value && incognito.value === false) {
ck = { ltoken: cookie.value.ltoken, ltuid: cookie.value.ltuid };
}
const resp = await postReq.post(postId, ck);
if ("retcode" in resp) {
await showLoading.empty("数据加载失败", `[${resp.retcode}]${resp.message}`);
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await webviewWindow.getCurrentWebviewWindow().setTitle(`Post_${postId} ${resp.message}`);
await TGLogger.Error(`[t-post][${postId}][onMounted] ${resp.retcode}: ${resp.message}`);
try {
const resp = await postReq.post(postId, ck);
if (resp.retcode !== 0) {
await showLoading.empty("数据加载失败", `[${resp.retcode}]${resp.message}`);
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await webviewWindow.getCurrentWebviewWindow().setTitle(`Post_${postId} ${resp.message}`);
await TGLogger.Warn(`[t-post][${postId}][onMounted] ${resp.retcode}: ${resp.message}`);
return;
}
postData.value = resp.data;
} catch (e) {
const errMsg = TGHttps.getErrMsg(e);
await showLoading.empty("数据加载失败", errMsg);
showSnackbar.error(errMsg);
await webviewWindow.getCurrentWebviewWindow().setTitle(`Post_${postId} ${errMsg}`);
await TGLogger.Error(`[t-post][${postId}][onMounted] ${errMsg}`);
return;
}
postData.value = resp;
console.log(resp);
console.log(postData.value);
isLike.value = (postData.value.self_operation?.upvote_type ?? 0) > 0;
await showLoading.update("正在渲染数据");
renderPost.value = await getRenderPost(postData.value);