feat: 1point3acres post fulltext

This commit is contained in:
DIYgod
2020-12-08 17:42:22 +08:00
parent 1bedbef657
commit 6cc742fc71
4 changed files with 51 additions and 33 deletions
+10 -10
View File
@@ -611,22 +611,22 @@ pageClass: routes
## 一亩三分地
### 主题帖
### 帖子
<Route author="NavePnow DIYgod" example="/1point3acres/post/hot" path="/1point3acres/post/:category" :paramsDesc="['分类 category, 见下表']"/>
| 热门帖子 | 最新帖子 |
| -------- | -------- |
| hot | new |
### 用户主题帖
<Route author="Maecenas" example="/1point3acres/user/1/threads" path="/1point3acres/user/:id/threads" :paramsDesc="['用户 id,可在 Instant 版网站的个人主页 URL 找到']"/>
### 回帖
### 用户回帖
<Route author="Maecenas" example="/1point3acres/user/1/posts" path="/1point3acres/user/:id/posts" :paramsDesc="['用户 id,可在 Instant 版网站的个人主页 URL 找到']"/>
### 帖子 (手机端的最热与最新 Tab)
<Route author="NavePnow" example="/1point3acres/post/hot" path="/1point3acres/post/:category" :paramsDesc="['分类 category, 见下表']"/>
| 最热帖子 | 最新帖子 |
| -------- | -------- |
| hot | new |
### 录取结果
<Route author="NavePnow" example="/1point3acres/offer/12/null/CMU" path="/1point3acres/offer/:year?/:major?/:school?" :paramsDesc="['录取年份 id,空为null', '录取专业 id,空为null', '录取学校 id,空为null']">
+35 -23
View File
@@ -1,38 +1,50 @@
const got = require('@/utils/got');
const bbcode = require('bbcodejs');
module.exports = async (ctx) => {
const category = ctx.params.category;
let url;
let method;
let description;
let { title } = 'null';
// eslint-disable-next-line eqeqeq
if (title == 'null') {
method = 'get';
let title;
if (category === 'new') {
url = 'https://api.1point3acres.com/api/threads?type=new&pg=1&ps=20&includes=summary';
title = '最新帖子';
} else {
url = 'https://api.1point3acres.com/api/threads?type=hot&pg=1&ps=20&includes=summary';
title = '热门帖子';
}
// eslint-disable-next-line eqeqeq
category == 'new'
? ((url = 'https://api.1point3acres.com/api/threads?type=new&pg=1&ps=20&includes=last_reply'), (title = '最新帖子'))
: ((url = 'https://api.1point3acres.com/api/threads?type=hot&pg=1&ps=20&includes=last_reply'), (title = '最热帖子'));
const responseBasic = await got({
method: method,
method: 'get',
url: url,
});
const data = responseBasic.data.threads;
ctx.state.data = {
title: `${title} - 一亩三分地`,
link: `https://www.1point3acres.com/bbs/`,
description: `${title} - 一亩三分地`,
item: data.map((item) => {
// eslint-disable-next-line eqeqeq
item.last_reply.quote == '' ? (description = item.last_reply.message_bbcode) : (description = item.last_reply.quote);
return {
const bbcodeParser = new bbcode.Parser();
const items = await Promise.all(
data.map(async (item) => {
const result = {
title: `${item.subject}`,
// description: item.last_reply.message_bbcode,// + `<b>楼主:</b>` + item.author,
description: description,
// pubDate: new Date(item.submittime + ' GMT+8').toUTCString(),
description: `${item.summary}...<br><br><small>作者 ${item.author} · 回复 ${item.replies} · 查看 ${item.views}</small>`,
link: `https://instant.1point3acres.com/thread/${item.tid}`,
};
}),
try {
await ctx.cache.tryGet(item.link, async () => {
const detail = await got({
method: 'get',
url: `https://api.1point3acres.com/instant/threads/${item.tid}`,
referer: 'https://instant.1point3acres.com/',
});
result.description = `${bbcodeParser.toHTML(detail.data.thread.message_bbcode)}<br><br><small>作者 ${item.author} · 回复 ${item.replies} · 查看 ${item.views}</small>`;
});
} catch (error) {
// nothing
}
return result;
})
);
ctx.state.data = {
title: `一亩三分地 - ${title}`,
link: `https://www.1point3acres.com/bbs/`,
item: items,
};
};
+1
View File
@@ -69,6 +69,7 @@
"@sentry/node": "5.28.0",
"aes-js": "3.1.2",
"art-template": "4.13.2",
"bbcodejs": "0.0.4",
"cheerio": "1.0.0-rc.3",
"chrono-node": "2.1.10",
"co-redis": "2.1.1",
+5
View File
@@ -2822,6 +2822,11 @@ batch@0.6.1:
resolved "https://registry.yarnpkg.com/batch/-/batch-0.6.1.tgz#dc34314f4e679318093fc760272525f94bf25c16"
integrity sha1-3DQxT05nkxgJP8dgJyUl+UvyXBY=
bbcodejs@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/bbcodejs/-/bbcodejs-0.0.4.tgz#85f081738c9b6e71ec58a32a419734c987bf8305"
integrity sha1-hfCBc4ybbnHsWKMqQZc0yYe/gwU=
bcrypt-pbkdf@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e"