🐛 修复link_card_ids字段不识别

This commit is contained in:
目棃
2024-12-25 14:28:47 +08:00
parent f401b8d0a2
commit ab5dfa9b57
4 changed files with 96 additions and 52 deletions

View File

@@ -7,7 +7,12 @@
{{ props.data.insert.link_card.price }} {{ props.data.insert.link_card.price }}
</div> </div>
<div @click="toLink()" class="tp-link-card-btn"> <div @click="toLink()" class="tp-link-card-btn">
{{ props.data.insert.link_card.button_text ?? "详情" }} > {{
props.data.insert.link_card.button_text === ""
? "详情"
: props.data.insert.link_card.button_text
}}
>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,7 +1,7 @@
/** /**
* @file plugins/Mys/types/post.d.ts * @file plugins/Mys/types/post.d.ts
* @description Mys 插件帖子类型定义文件 * @description Mys 插件帖子类型定义文件
* @since Beta v0.6.3 * @since Beta v0.6.7
*/ */
declare namespace TGApp.Plugins.Mys.Post { declare namespace TGApp.Plugins.Mys.Post {
@@ -13,15 +13,11 @@ declare namespace TGApp.Plugins.Mys.Post {
* @property {FullData} data.post 帖子数据 * @property {FullData} data.post 帖子数据
* @return Response * @return Response
*/ */
interface Response extends TGApp.BBS.Response.BaseWithData { type Response = TGApp.BBS.Response.BaseWithData & { data: { post: FullData } };
data: {
post: FullData;
};
}
/** /**
* @description 帖子数据 * @description 帖子数据
* @since Beta v0.5.0 * @since Beta v0.6.7
* @interface FullData * @interface FullData
* @property {Post} post 帖子信息 * @property {Post} post 帖子信息
* @property {Forum|null} forum 所属版块,可能为 null * @property {Forum|null} forum 所属版块,可能为 null
@@ -42,7 +38,7 @@ declare namespace TGApp.Plugins.Mys.Post {
* @property {unknown[]} vod_list 视频列表,可能为空 * @property {unknown[]} vod_list 视频列表,可能为空
* @property {boolean} is_block_on 是否被屏蔽 * @property {boolean} is_block_on 是否被屏蔽
* @property {unknown} forum_rank_info 版块排行信息,可能为 null * @property {unknown} forum_rank_info 版块排行信息,可能为 null
* @property {unknown[]} link_card_list 链接卡片列表,可能为空 * @property {LinkCard[]} link_card_list 链接卡片列表,可能为空
* @property {TGApp.Plugins.Mys.News.Meta} news_meta 咨讯元数据,可能为 null * @property {TGApp.Plugins.Mys.News.Meta} news_meta 咨讯元数据,可能为 null
* @return FullData * @return FullData
*/ */
@@ -66,7 +62,7 @@ declare namespace TGApp.Plugins.Mys.Post {
vod_list: Vod[]; vod_list: Vod[];
is_block_on: boolean; is_block_on: boolean;
forum_rank_info: unknown | null; forum_rank_info: unknown | null;
link_card_list: unknown[]; link_card_list: LinkCard[];
news_meta: TGApp.Plugins.Mys.News.Meta | null | undefined; news_meta: TGApp.Plugins.Mys.News.Meta | null | undefined;
recommend_reason: unknown | null; recommend_reason: unknown | null;
villa_card: unknown | null; villa_card: unknown | null;
@@ -302,6 +298,45 @@ declare namespace TGApp.Plugins.Mys.Post {
next_post_view_type: number; next_post_view_type: number;
} }
/**
* @description 链接卡片信息
* @since Beta v0.6.7
* @interface LinkCard
* @property {string} button_text 按钮文本
* @property {string} card_id 卡片 ID
* @property {unknown} card_meta 卡片元数据
* @property {number} card_status 卡片状态
* @property {string} cover 封面图 URL
* @property {string} landing_url 落地页 URL
* @property {number} landing_url_type 落地页类型
* @property {number} link_type 链接类型
* @property {string} market_price 市场价
* @property {string} origin_url 原始 URL
* @property {string} origin_user_avatar 原始用户头像 URL
* @property {string} origin_user_avatar_url 原始用户头像 URL
* @property {string} origin_user_nickname 原始用户名
* @property {string} price 价格
* @property {string} title 标题
* @returns LinkCard
*/
type LinkCard = {
button_text: string;
card_id: string;
card_meta: unknown;
card_status: number;
cover: string;
landing_url: string;
landing_url_type: number;
link_type: number;
market_price: string;
origin_url: string;
origin_user_avatar: string;
origin_user_avatar_url: string;
origin_user_nickname: string;
price: string;
title: string;
};
/** /**
* @description 视频信息 * @description 视频信息
* @since Beta v0.3.7 * @since Beta v0.3.7

View File

@@ -1,15 +1,9 @@
/** /**
* @file plugins/Mys/types/SctPost.d.ts * @file plugins/Mys/types/SctPost.d.ts
* @description Mys 插件 结构化帖子类型声明文件 * @description Mys 插件 结构化帖子类型声明文件
* @since Beta v0.4.5 * @since Beta v0.6.7
*/ */
/**
* @description 结构化帖子类型命名空间
* @since Beta v0.4.5
* @namespace TGApp.Plugins.Mys.SctPost
* @memberof TGApp.Plugins.Mys
*/
declare namespace TGApp.Plugins.Mys.SctPost { declare namespace TGApp.Plugins.Mys.SctPost {
/** /**
* @description 帖子结构化数据-基础类型 * @description 帖子结构化数据-基础类型
@@ -20,11 +14,7 @@ declare namespace TGApp.Plugins.Mys.SctPost {
* @property {Base[]} children - 子帖子 * @property {Base[]} children - 子帖子
* @return Base * @return Base
*/ */
interface Base { type Base = { insert: any; attributes?: any; children?: Base[] };
insert: any;
attributes?: any;
children?: Base[];
}
/** /**
* @description 帖子结构化数据-空类型 * @description 帖子结构化数据-空类型
@@ -34,22 +24,17 @@ declare namespace TGApp.Plugins.Mys.SctPost {
* @property {never} attributes - 帖子属性 * @property {never} attributes - 帖子属性
* @return Empty * @return Empty
*/ */
interface Empty { type Empty = { insert: never; attributes?: never };
insert: never;
attributes?: never;
}
/** /**
* @description 帖子结构化数据-其他类型 * @description 帖子结构化数据-其他类型
* @since Beta v0.3.4 * @since Beta v0.6.7
* @property {string} describe - 描述 * @property {string} describe - 描述
* @property {string[]} imgs - 图片链接 * @property {string[]} imgs - 图片链接
* @property {string[]} link_card_ids - 关联卡片ID
* @return Other * @return Other
*/ */
interface Other { type Other = { describe: string; imgs: string[]; link_card_ids?: string[] } & {
describe: string;
imgs: string[];
[key: string]: unknown; [key: string]: unknown;
} };
} }

View File

@@ -6,7 +6,7 @@
<VpBtnReply :gid="postData.post.game_id" :post-id="postData.post.post_id" v-if="postData" /> <VpBtnReply :gid="postData.post.game_id" :post-id="postData.post.post_id" v-if="postData" />
<div class="tp-post-body" v-if="postData"> <div class="tp-post-body" v-if="postData">
<div class="tp-post-info"> <div class="tp-post-info">
<div class="tp-post-version"> <div class="tp-post-version" @click="openJson()">
PostID{{ postId }} | Render by TeyvatGuide v{{ appVersion }} PostID{{ postId }} | Render by TeyvatGuide v{{ appVersion }}
</div> </div>
<div class="tp-post-meta"> <div class="tp-post-meta">
@@ -38,7 +38,7 @@
</div> </div>
<TpAvatar :data="postData.user" position="right" v-if="postData.user" /> <TpAvatar :data="postData.user" position="right" v-if="postData.user" />
</div> </div>
<div class="tp-post-title" @click="toPost()" title="点击查看评论"> <div class="tp-post-title" @click="toPost()">
<span class="mpt-official" v-if="postData.post.post_status.is_official"></span> <span class="mpt-official" v-if="postData.post.post_status.is_official"></span>
<span>{{ postData.post.subject }}</span> <span>{{ postData.post.subject }}</span>
</div> </div>
@@ -100,9 +100,9 @@ import { onMounted, onUnmounted, ref, shallowRef } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { useAppStore } from "@/store/modules/app.js"; import { useAppStore } from "@/store/modules/app.js";
import TGClient from "@/utils/TGClient.js";
import TGLogger from "@/utils/TGLogger.js"; import TGLogger from "@/utils/TGLogger.js";
import { createTGWindow } from "@/utils/TGWindow.js"; import { createTGWindow } from "@/utils/TGWindow.js";
import { CHANNEL_LIST } from "@/web/constant/bbs.js";
import TGConstant from "@/web/constant/TGConstant.js"; import TGConstant from "@/web/constant/TGConstant.js";
const appVersion = ref<string>(); const appVersion = ref<string>();
@@ -141,17 +141,13 @@ onMounted(async () => {
} }
postData.value = resp; postData.value = resp;
await showLoading.update("正在渲染数据"); await showLoading.update("正在渲染数据");
renderPost.value = getRenderPost(postData.value); renderPost.value = await getRenderPost(postData.value);
await webviewWindow await webviewWindow
.getCurrentWebviewWindow() .getCurrentWebviewWindow()
.setTitle(`Post_${postId} ${postData.value.post.subject}`); .setTitle(`Post_${postId} ${postData.value.post.subject}`);
await TGLogger.Info(`[t-post][${postId}][onMounted] ${postData.value.post.subject}`); await TGLogger.Info(`[t-post][${postId}][onMounted] ${postData.value.post.subject}`);
const isDev = useAppStore().devMode ?? false; const isDev = useAppStore().devMode ?? false;
if (isDev) { if (isDev) await openJson();
await showLoading.update("正在打开调试窗口");
await TGLogger.Info(`[t-post][${postId}][onMounted] 打开 JSON 窗口`);
await createPostJson(postId);
}
if (shareTimer !== null) { if (shareTimer !== null) {
clearInterval(shareTimer); clearInterval(shareTimer);
shareTimer = null; shareTimer = null;
@@ -160,6 +156,12 @@ onMounted(async () => {
await showLoading.end(); await showLoading.end();
}); });
async function openJson(): Promise<void> {
// @ts-expect-error import.meta
if (import.meta.env.MODE === "production") return;
await createPostJson(postId);
}
function getShareTimer(): void { function getShareTimer(): void {
shareTime.value = Math.floor(Date.now() / 1000); shareTime.value = Math.floor(Date.now() / 1000);
} }
@@ -183,27 +185,30 @@ function getRepublishAuthorization(type: number): string {
} }
} }
function getRenderPost(data: TGApp.Plugins.Mys.Post.FullData): TGApp.Plugins.Mys.SctPost.Base[] { async function getRenderPost(
data: TGApp.Plugins.Mys.Post.FullData,
): Promise<Array<TGApp.Plugins.Mys.SctPost.Base>> {
const postContent = data.post.content; const postContent = data.post.content;
let jsonParse: string; let jsonParse: string;
if (postContent.startsWith("<")) { if (postContent.startsWith("<")) {
jsonParse = data.post.structured_content; jsonParse = data.post.structured_content;
} else { } else {
try { try {
jsonParse = parseContent(data.post.content); jsonParse = await parseContent(data.post.content);
} catch (e) { } catch (e) {
if (e instanceof SyntaxError) TGLogger.Warn(`[t-post][${postId}] ${e.name}: ${e.message}`); if (e instanceof SyntaxError) {
await TGLogger.Warn(`[t-post][${postId}] ${e.name}: ${e.message}`);
}
jsonParse = data.post.structured_content; jsonParse = data.post.structured_content;
} }
} }
return JSON.parse(jsonParse); return JSON.parse(jsonParse);
} }
function parseContent(content: string): string { async function parseContent(content: string): Promise<string> {
const data: TGApp.Plugins.Mys.SctPost.Other = JSON.parse(content); const data: TGApp.Plugins.Mys.SctPost.Other = JSON.parse(content);
const result: TGApp.Plugins.Mys.SctPost.Base[] = []; const result: TGApp.Plugins.Mys.SctPost.Base[] = [];
const keys = Object.keys(data); for (const key of Object.keys(data)) {
keys.forEach((key) => {
switch (key) { switch (key) {
case "describe": case "describe":
result.push({ insert: data.describe }); result.push({ insert: data.describe });
@@ -211,12 +216,22 @@ function parseContent(content: string): string {
case "imgs": case "imgs":
data.imgs.forEach((item) => result.push({ insert: { image: item } })); data.imgs.forEach((item) => result.push({ insert: { image: item } }));
break; break;
case "link_card_ids":
if (!data.link_card_ids) break;
for (const item of data.link_card_ids) {
const dataFind = postData.value?.link_card_list.find((card) => card.card_id === item);
if (dataFind) result.push({ insert: { link_card: dataFind } });
else {
await TGLogger.Warn(`[t-post][${postId}][parseContent] link_card_ids: ${item} 未找到`);
}
}
break;
default: default:
TGLogger.Warn(`[t-post][${postId}][parseContent] Unknown key: ${key}`); await TGLogger.Warn(`[t-post][${postId}][parseContent] Unknown key: ${key}`);
result.push({ insert: data[key] }); result.push({ insert: data[key] });
break; break;
} }
}); }
return JSON.stringify(result); return JSON.stringify(result);
} }
@@ -226,9 +241,13 @@ async function createPostJson(postId: number): Promise<void> {
await createTGWindow(jsonPath, "Dev_JSON", jsonTitle, 960, 720, false, false); await createTGWindow(jsonPath, "Dev_JSON", jsonTitle, 960, 720, false, false);
} }
async function toPost(): Promise<void> { function toPost(): void {
const url = `https://m.miyoushe.com/ys/#/article/${postId}`; const channel = CHANNEL_LIST.find((item) => item.gid === postData.value?.post.game_id.toString());
await TGClient.open("web_thin", url); if (channel) {
window.open(`https://miyoushe.com/${channel.mini}/#/article/${postId}`);
} else {
window.open(`https://miyoushe.com/ys/#/article/${postId}`);
}
} }
async function toTopic(topic: TGApp.Plugins.Mys.Topic.Info): Promise<void> { async function toTopic(topic: TGApp.Plugins.Mys.Topic.Info): Promise<void> {