From 7ab2a7cd7a79036ca37f4d9196e8b80472839a33 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 25 Oct 2024 06:56:38 +0800 Subject: [PATCH] fix: update types --- lib/routes/dxy/special.ts | 19 +++---- lib/routes/dxy/types.ts | 110 ++++++++++++++++++++++++++++++++++++++ lib/routes/dxy/utils.ts | 10 ++-- 3 files changed, 125 insertions(+), 14 deletions(-) diff --git a/lib/routes/dxy/special.ts b/lib/routes/dxy/special.ts index 2ef12239a40f22..3d41e6e656157d 100644 --- a/lib/routes/dxy/special.ts +++ b/lib/routes/dxy/special.ts @@ -1,9 +1,10 @@ import { Route } from '@/types'; import cache from '@/utils/cache'; -import got from '@/utils/got'; +import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; import { phoneBaseUrl, webBaseUrl, generateNonce, sign, getPost } from './utils'; import { config } from '@/config'; +import { RecommendListData, SpecialBoardDetail } from './types'; export const route: Route = { path: '/bbs/special/:specialId', @@ -27,7 +28,7 @@ async function handler(ctx) { const specialId = ctx.req.param('specialId'); const { limit = '10' } = ctx.req.query(); - const specialDetail = await cache.tryGet(`dxy:special:detail:${specialId}`, async () => { + const specialDetail = (await cache.tryGet(`dxy:special:detail:${specialId}`, async () => { const detailParams = { specialId, requestType: 'h5', @@ -35,8 +36,8 @@ async function handler(ctx) { noncestr: generateNonce(8, 'number'), }; - const { data: detail } = await got(`${phoneBaseUrl}/newh5/bbs/special/detail`, { - searchParams: { + const detail = await ofetch(`${phoneBaseUrl}/newh5/bbs/special/detail`, { + query: { ...detailParams, sign: sign(detailParams), }, @@ -45,9 +46,9 @@ async function handler(ctx) { throw new Error(detail.message); } return detail.data; - }); + })) as SpecialBoardDetail; - const recommendList = await cache.tryGet( + const recommendList = (await cache.tryGet( `dxy:special:recommend-list-v3:${specialId}`, async () => { const listParams = { @@ -59,8 +60,8 @@ async function handler(ctx) { noncestr: generateNonce(8, 'number'), }; - const { data: recommendList } = await got(`${phoneBaseUrl}/newh5/bbs/special/post/recommend-list-v3`, { - searchParams: { + const recommendList = await ofetch(`${phoneBaseUrl}/newh5/bbs/special/post/recommend-list-v3`, { + query: { ...listParams, sign: sign(listParams), }, @@ -72,7 +73,7 @@ async function handler(ctx) { }, config.cache.routeExpire, false - ); + )) as RecommendListData; const list = recommendList.result.map((item) => { const { postInfo, dataTime, entityId } = item; diff --git a/lib/routes/dxy/types.ts b/lib/routes/dxy/types.ts index aae3926c93b38a..40c221f638273a 100644 --- a/lib/routes/dxy/types.ts +++ b/lib/routes/dxy/types.ts @@ -55,17 +55,59 @@ interface TagInfo { tagName: string; } +interface PostSpecial { + specialId: number; + specialName: string; + followCount: number; + postCount: number; + followStatus: boolean; + personalSpecial: boolean; + avatar: string; + customAvatar: string; + backgroundColor: string; + type: number; +} + +interface Video { + videoId: number; + videoUrl: string; + cover: string; + size: number; + duration: number; + auditState: number; + userVideoState: number; +} + interface Post { id: number; + rootId: number; createTime: number; + simpleBody: string; subject: string; body: string; + coverPic: string; + isVideoCover: boolean; + isVideoCoverPic: boolean; + postTime: number; reads: number; pv: number; + replies: number; + qualityPost: boolean; + contentType: number; + postStatus: number; + signatured: number; + userVote: boolean; + postSpecial: PostSpecial; + isEditorRecommend: boolean; + isTop: boolean; ipLocation: string; isCurrentUser: boolean; anonymous: boolean; boardInfo: BoardInfo; + votes: number; + archived: boolean; + approved: boolean; + video?: Video; postPerm: PostPerm; showStatus: boolean; postUser: PostUser; @@ -83,3 +125,71 @@ export interface PostData { message: string; data: Post; } + +interface SpecialAdmin { + userId: number; + username: string; + nickname: string; + avatar: string; + followers: number; + bbsVotes: number; + level: number; + talentStatus: number; + levelStatus: number; + professional: boolean; + enterpriseStatus: boolean; + identificationTitle: string; + blueVip: boolean; + talentBoard: false[]; + userTitle: UserTitle; + enterpriseName: string; +} + +export interface SpecialBoardDetail { + id: number; + name: string; + content: string; + categoryId: number; + type: number; + submitted: number; + status: number; + rangeed: number; + userId: number; + followCount: number; + postCount: number; + backgroundColor: string; + pushMessage: number; + bestTime: number; + updateTime: number; + createTime: number; + modifyTime: number; + followStatus: boolean; + tabOption: number; + specialAvatar: string; + pushStatus: boolean; + specialAdmins: SpecialAdmin[]; + isContribute: boolean; + post: false[]; + isOpenPostEntrance: boolean; +} + +interface RecommendPost { + entityId: number; + entityType: number; + dataTime: number; + sortValue: number; + recommendReason: string; + postInfo: Post; + feedType: number; + source: string; + pointMap: Record; + globalId: string; +} + +export interface RecommendListData { + pageNum: number; + pageSize: number; + total: number; + result: RecommendPost[]; + empty: boolean; +} diff --git a/lib/routes/dxy/utils.ts b/lib/routes/dxy/utils.ts index e670bf0ed814ef..b404e3920fa0af 100644 --- a/lib/routes/dxy/utils.ts +++ b/lib/routes/dxy/utils.ts @@ -54,20 +54,20 @@ const getPost = (item, tryGet) => $('img').each((_, img) => { img = $(img); - if (img.data('osrc')) { - img.attr('src', img.data('osrc')); - img.removeAttr('data-osrc'); - } if (img.data('hsrc')) { img.attr('src', img.data('hsrc')); img.removeAttr('data-hsrc'); } + if (img.data('osrc')) { + img.attr('src', img.data('osrc')); + img.removeAttr('data-osrc'); + } }); item.description = $.html(); item.pubDate = parseDate(post.data.createTime, 'x'); item.updated = post.data.lastEditTime ? parseDate(post.data.lastEditTime, 'x') : item.pubDate; - item.category = [...new Set([item.category, ...post.data.tagInfos.map((tag) => tag.tagName)])]; + item.category = [...new Set([...item.category, ...post.data.tagInfos.map((tag) => tag.tagName)])]; return item; });