Skip to content

Commit

Permalink
fix: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL committed Oct 24, 2024
1 parent 5be3638 commit 7ab2a7c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 14 deletions.
19 changes: 10 additions & 9 deletions lib/routes/dxy/special.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -27,16 +28,16 @@ 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',
timestamp: Date.now(),
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),
},
Expand All @@ -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 = {
Expand All @@ -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),
},
Expand All @@ -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;
Expand Down
110 changes: 110 additions & 0 deletions lib/routes/dxy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string, unknown>;
globalId: string;
}

export interface RecommendListData {
pageNum: number;
pageSize: number;
total: number;
result: RecommendPost[];
empty: boolean;
}
10 changes: 5 additions & 5 deletions lib/routes/dxy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down

0 comments on commit 7ab2a7c

Please sign in to comment.