Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): dxy board #17294

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions lib/routes/dxy/board.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { phoneBaseUrl, webBaseUrl, generateNonce, sign, getPost } from './utils';
import { config } from '@/config';
import { BoardInfo, PostListData } from './types';

export const route: Route = {
path: '/bbs/board/:boardId',
categories: ['bbs'],
example: '/dxy/bbs/board/46',
parameters: { specialId: '板块 ID,可在对应板块页 URL 中找到' },
name: '板块',
maintainers: ['TonyRL'],
radar: [
{
source: ['www.dxy.cn/bbs/newweb/pc/category/:boardIdId'],
target: '/bbs/board/:boardIdId',
},
{
source: ['3g.dxy.cn/bbs/board/:boardIdId'],
target: '/bbs/board/:boardIdId',
},
],
handler,
};

async function handler(ctx) {
const { boardId } = ctx.req.param();
const { limit = '20' } = ctx.req.query();

const boardDetail = (await cache.tryGet(`dxy:board:detail:${boardId}`, async () => {
const detailParams = {
boardId,
timestamp: Date.now(),
noncestr: generateNonce(8, 'number'),
};

const detail = await ofetch(`${phoneBaseUrl}/bbsapi/bbs/board/detail`, {
query: {
...detailParams,
sign: sign(detailParams),
},
});
if (detail.code !== 'success') {
throw new Error(detail.message);
}
return detail.data;
})) as BoardInfo;

const boardList = (await cache.tryGet(
`dxy:board:list:${boardId}`,
async () => {
const listParams = {
boardId,
postType: '0',
orderType: '1',
pageNum: '1',
pageSize: limit,
timestamp: Date.now(),
noncestr: generateNonce(8, 'number'),
};

const recommendList = await ofetch(`${phoneBaseUrl}/bbsapi/bbs/board/post/list`, {
query: {
...listParams,
sign: sign(listParams),
},
});
if (recommendList.code !== 'success') {
throw new Error(recommendList.message);
}
return recommendList.data;
},
config.cache.routeExpire,
false
)) as PostListData;

const list = boardList.result.map((item) => ({
title: item.subject,
author: item.postUser.nickname,
category: [boardDetail.title],
link: `${webBaseUrl}/bbs/newweb/pc/post/${item.postId}`,
postId: item.postId,
}));

const items = await Promise.all(list.map((item) => getPost(item, cache.tryGet)));

return {
title: boardDetail.title,
description: `${boardDetail.postCount} 內容 ${boardDetail.followCount} 关注`,
link: `${webBaseUrl}/bbs/newweb/pc/category/${boardId}`,
image: boardDetail.boardAvatar,
item: items,
};
}
2 changes: 1 addition & 1 deletion lib/routes/dxy/profile/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function handler(ctx) {
description: postInfo.simpleBody,
pubDate: parseDate(createdTime, 'x'),
author: postInfo.postUser.nickname,
category: postInfo.boardInfo.title,
category: [postInfo.boardInfo.title],
link: `${webBaseUrl}/bbs/newweb/pc/post/${entityId}`,
postId: entityId,
};
Expand Down
21 changes: 11 additions & 10 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 All @@ -81,7 +82,7 @@ async function handler(ctx) {
description: postInfo.simpleBody,
pubDate: parseDate(dataTime, 'x'),
author: postInfo.postUser.nickname,
category: postInfo.postSpecial.specialName,
category: [postInfo.postSpecial.specialName],
link: `${webBaseUrl}/bbs/newweb/pc/post/${entityId}`,
postId: entityId,
};
Expand Down
195 changes: 195 additions & 0 deletions lib/routes/dxy/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
interface BoardPerm {
errCode: number;
}
interface PostPerm {
errCode: number;
}

export interface BoardInfo {
id: number;
boardId: number;
title: string;
shortTitle: string;
postCount: number;
followCount: number;
boardAvatar: string;
boardPerm: BoardPerm;
followStatus: boolean;
}

interface PostUser {
userId: number;
avatar: string;
username: string;
nickname: string;
bbsStatus: number;
userTitle: UserTitle;
}

interface PostDetail {
postId: number;
boardId: number;
reads: number;
pv: number;
subject: string;
postUser: PostUser;
screenUrlList: string[];
videoScreen: boolean;
isEditorRecommend: boolean;
}

export interface PostListData {
pageNum: number;
pageSize: number;
total: number;
result: PostDetail[];
empty: boolean;
}

interface UserTitle {
type: number;
titles: string[];
}

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;
hintInfos: false[];
isDisableRepost: boolean;
tagInfos: TagInfo[];
isVoteActivityPost: boolean;
isShowCaseTag: boolean;
isPaidContent: boolean;
isNeedPay: boolean;
}

export interface PostData {
code: string;
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;
}
Loading