diff --git a/src/plugins/Mys/request/postReq.ts b/src/plugins/Mys/request/postReq.ts index 616ffbbc..dc30b4c8 100644 --- a/src/plugins/Mys/request/postReq.ts +++ b/src/plugins/Mys/request/postReq.ts @@ -1,7 +1,7 @@ /** * @file plugins/Mys/request/postReq.ts * @description 帖子相关的获取 - * @since Beta v0.6.2 + * @since Beta v0.6.3 */ import TGHttp from "../../../utils/TGHttp.js"; @@ -35,18 +35,20 @@ export async function getForumPostList( /** * @description 获取单个帖子信息 - * @since Beta v0.6.2 + * @since Beta v0.6.3 * @param {number} postId 帖子 ID - * @return {Promise} + * @return {Promise} */ -export async function getPostFull(postId: number): Promise { - return ( - await TGHttp(`${Mpabu}getPostFull`, { - method: "GET", - headers: { referer: Referer }, - query: { post_id: postId }, - }) - ).data.post; +export async function getPostFull( + postId: number, +): Promise { + const resp = await TGHttp(`${Mpabu}getPostFull`, { + method: "GET", + headers: { referer: Referer }, + query: { post_id: postId }, + }); + if (resp.retcode !== 0) return resp; + return resp.data.post; } /** diff --git a/src/plugins/Mys/utils/getGachaCard.ts b/src/plugins/Mys/utils/getGachaCard.ts index 65db1884..4c0b929f 100644 --- a/src/plugins/Mys/utils/getGachaCard.ts +++ b/src/plugins/Mys/utils/getGachaCard.ts @@ -1,15 +1,16 @@ /** * @file plugins/Mys/utils/getGachaCard.ts * @description Mys 插件抽卡工具 - * @since Beta v0.6.2 + * @since Beta v0.6.3 */ +import showSnackbar from "../../../components/func/snackbar.js"; import { AppCharacterData } from "../../../data/index.js"; import { getPostFull } from "../request/postReq.js"; /** * @description 根据单个卡池信息转为渲染用的卡池信息 - * @since Beta v0.6.2 + * @since Beta v0.6.3 * @param {TGApp.Plugins.Mys.Gacha.Data} data 卡池信息 * @param {string} poolCover 卡池封面 * @returns {Promise} @@ -17,36 +18,28 @@ import { getPostFull } from "../request/postReq.js"; async function getGachaItemCard( data: TGApp.Plugins.Mys.Gacha.Data, poolCover?: string, -): Promise { +): Promise { let cover = "/source/UI/empty.webp"; const postId: number | undefined = Number(data.activity_url.split("/").pop()) || undefined; - if (postId === undefined || isNaN(postId)) { - throw new Error("无法获取帖子 ID"); - } + if (postId === undefined || isNaN(postId)) return null; if (poolCover !== undefined) { cover = poolCover; } else { - try { - console.log("调用 getPostData"); - const post = await getPostFull(postId); - cover = post.cover?.url ?? post.post.images[0]; - } catch (error) { - console.error(error); + const postResp = await getPostFull(postId); + if ("retcode" in postResp) { + showSnackbar.error(`[${postResp.retcode}] ${postResp.message}`); + return null; } + cover = postResp.cover?.url ?? postResp.post.images[0]; } const timeStr = `${data.start_time} ~ ${data.end_time}`; const characters: TGApp.Plugins.Mys.Gacha.RenderItem[] = []; for (const character of data.pool) { - const item: TGApp.Plugins.Mys.Gacha.RenderItem = { - icon: character.icon, - url: character.url, - }; + const item: TGApp.Plugins.Mys.Gacha.RenderItem = { icon: character.icon, url: character.url }; const contentId = character.url.match(/(?<=content\/)\d+/)?.[0]; if (contentId) { const itemF = AppCharacterData.find((item) => item.contentId.toString() === contentId); - if (itemF) { - item.info = itemF; - } + if (itemF) item.info = itemF; } characters.push(item); } @@ -67,7 +60,7 @@ async function getGachaItemCard( /** * @description 根据卡池信息转为渲染用的卡池信息 - * @since Beta v0.4.4 + * @since Beta v0.6.3 * @param {TGApp.Plugins.Mys.Gacha.Data[]} gachaData 卡池信息 * @param {Record} poolCover 卡池封面 * @returns {Promise} @@ -80,7 +73,7 @@ export async function getGachaCard( await Promise.allSettled( gachaData.map(async (data: TGApp.Plugins.Mys.Gacha.Data) => { const item = await getGachaItemCard(data, poolCover?.[Number(data.id)]); - gachaCard.push(item); + if (item !== null) gachaCard.push(item); }), ); return gachaCard; diff --git a/src/views/t-post-json.vue b/src/views/t-post-json.vue index f907ea8a..0c0ebf51 100644 --- a/src/views/t-post-json.vue +++ b/src/views/t-post-json.vue @@ -8,18 +8,19 @@