From e14eb410f175e6be1d6c764f5c8a07074056bb7c Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 7 Apr 2023 05:22:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=80=E4=BA=A9?= =?UTF-8?q?=E4=B8=89=E5=88=86=E5=9C=B0=E5=88=86=E5=8C=BA=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=20(#12249)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 一亩三分地分区标签 * fix: blog * fix: offer --------- --- docs/bbs.md | 97 +++++--- lib/router.js | 10 +- lib/routes/1point3acres/blog.js | 52 ----- lib/routes/1point3acres/offer.js | 211 ------------------ lib/routes/1point3acres/post.js | 50 ----- lib/v2/1point3acres/blog.js | 67 ++++++ lib/v2/1point3acres/category.js | 17 ++ lib/v2/1point3acres/maintainer.js | 9 + lib/v2/1point3acres/offer.js | 69 ++++++ lib/v2/1point3acres/radar.js | 53 +++++ lib/v2/1point3acres/router.js | 10 + lib/v2/1point3acres/section.js | 28 +++ lib/v2/1point3acres/templates/image.art | 1 + lib/v2/1point3acres/templates/offer.art | 11 + lib/v2/1point3acres/thread.js | 15 ++ .../posts.js => v2/1point3acres/user/post.js} | 0 .../1point3acres/user/thread.js} | 0 lib/v2/1point3acres/utils.js | 79 +++++++ 18 files changed, 435 insertions(+), 344 deletions(-) delete mode 100644 lib/routes/1point3acres/blog.js delete mode 100644 lib/routes/1point3acres/offer.js delete mode 100644 lib/routes/1point3acres/post.js create mode 100644 lib/v2/1point3acres/blog.js create mode 100644 lib/v2/1point3acres/category.js create mode 100644 lib/v2/1point3acres/maintainer.js create mode 100644 lib/v2/1point3acres/offer.js create mode 100644 lib/v2/1point3acres/radar.js create mode 100644 lib/v2/1point3acres/router.js create mode 100644 lib/v2/1point3acres/section.js create mode 100644 lib/v2/1point3acres/templates/image.art create mode 100644 lib/v2/1point3acres/templates/offer.art create mode 100644 lib/v2/1point3acres/thread.js rename lib/{routes/1point3acres/posts.js => v2/1point3acres/user/post.js} (100%) rename lib/{routes/1point3acres/threads.js => v2/1point3acres/user/thread.js} (100%) create mode 100644 lib/v2/1point3acres/utils.js diff --git a/docs/bbs.md b/docs/bbs.md index 57f7477e4..aeee77092 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -1073,12 +1073,77 @@ pageClass: routes ### 帖子 - + + +分类 | 热门帖子 | 最新帖子 | | -------- | -------- | | hot | new | +排序方式 + +| 最新回复 | 最新发布 | +| -------- | -------- | +| | post | + + + +### 分区 + + + +分区 + +| 分区 | id | +| -------- | --- | +| 留学申请 | 257 | +| 世界公民 | 379 | +| 投资理财 | 400 | +| 生活干货 | 31 | +| 职场达人 | 345 | +| 人际关系 | 391 | +| 海外求职 | 38 | +| 签证移民 | 265 | + +分类 + +| 热门帖子 | 最新帖子 | +| -------- | -------- | +| hot | new | + +排序方式 + +| 最新回复 | 最新发布 | +| -------- | -------- | +| | post | + + + +### 标签 + + + +::: tip + +更多标签可以在 [标签列表](https://instant.1point3acres.com/tags) 中找到。 + +::: + +分类 + +| 热门帖子 | 最新帖子 | +| -------- | -------- | +| hot | new | + +排序方式 + +| 最新回复 | 最新发布 | +| -------- | -------- | +| | post | + + + ### 用户主题帖 @@ -1090,6 +1155,7 @@ pageClass: routes ### 录取结果 + ::: warning 三个 id 获取方式 1. 打开 @@ -1105,32 +1171,11 @@ pageClass: routes ### 博客 - + -| 分类 | 分类名 | -| ---------- | --------------------------------------------------------------------- | -| 全部 | | -| 一亩三分地 | 一亩三分地 | -| 论坛精华 | 一亩三分地 - 论坛精华 | -| 咨询服务 | 咨询服务 | -| 学校院系 | 学校院系信息 | -| 找工求职 | 如何找工作 | -| 美国经济 | 如何找工作 - 美国经济与就业 | -| 杂谈其他 | 其他类别 | -| 抄袭 | 其他类别 - 抄袭 | -| 直播 | 其他类别 - 直播 | -| 热门专业 | eecsmis 统计金工等热门专业 | -| EECSMIS | eecsmis 统计金工等热门专业 - eecsmis 专业 | -| 数据科学 | eecsmis 统计金工等热门专业 - 数据科学 | -| 统计金工 | eecsmis 统计金工等热门专业 - 生物统计金融工程公共健康生物技术制药行业 | -| 留学申请 | 留学申请信息 | -| GT 考试 | 留学申请信息 - gt 考试 | -| 定位 | 留学申请信息 - 定位 | -| 文书写作 | 留学申请信息 - 文书写作 | -| 面试 | 留学申请信息 - 面试 | -| 移民绿卡 | 移民办绿卡 | -| 美国学习 | 美国学习 | -| 美国生活 | 美国生活 | +| 留学申请 | 找工求职 | 生活攻略 | 投资理财 | 签证移民 | 时政要闻 | +| ---------- | -------- | --------- | -------- | -------- | -------- | +| studyinusa | career | lifestyle | invest | visa | news | diff --git a/lib/router.js b/lib/router.js index 04e55e7e7..7e1abb41e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1506,11 +1506,11 @@ router.get('/bupt/funbox', lazyloadRouteHandler('./routes/universities/bupt/funb // router.get('/vocus/user/:id', lazyloadRouteHandler('./routes/vocus/user')); // 一亩三分地 1point3acres -router.get('/1point3acres/blog/:category?', lazyloadRouteHandler('./routes/1point3acres/blog')); -router.get('/1point3acres/user/:id/threads', lazyloadRouteHandler('./routes/1point3acres/threads')); -router.get('/1point3acres/user/:id/posts', lazyloadRouteHandler('./routes/1point3acres/posts')); -router.get('/1point3acres/offer/:year?/:major?/:school?', lazyloadRouteHandler('./routes/1point3acres/offer')); -router.get('/1point3acres/post/:category', lazyloadRouteHandler('./routes/1point3acres/post')); +// router.get('/1point3acres/blog/:category?', lazyloadRouteHandler('./routes/1point3acres/blog')); +// router.get('/1point3acres/user/:id/threads', lazyloadRouteHandler('./routes/1point3acres/threads')); +// router.get('/1point3acres/user/:id/posts', lazyloadRouteHandler('./routes/1point3acres/posts')); +// router.get('/1point3acres/offer/:year?/:major?/:school?', lazyloadRouteHandler('./routes/1point3acres/offer')); +// router.get('/1point3acres/post/:category', lazyloadRouteHandler('./routes/1point3acres/post')); // 广东海洋大学 router.get('/gdoujwc', lazyloadRouteHandler('./routes/universities/gdou/jwc/jwtz')); diff --git a/lib/routes/1point3acres/blog.js b/lib/routes/1point3acres/blog.js deleted file mode 100644 index 9182a8cde..000000000 --- a/lib/routes/1point3acres/blog.js +++ /dev/null @@ -1,52 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const category = ctx.params.category || ''; - - const rootUrl = 'https://www.1point3acres.com'; - const currentUrl = `${rootUrl}/${category === '' ? 'BlogPosts' : `category/${category.replace(/-/g, '/')}`}`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - const $ = cheerio.load(response.data); - - const list = $('.mybloglist h2 a') - .slice(0, 10) - .map((_, item) => { - item = $(item); - return { - title: item.text(), - link: item.attr('href'), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); - - content('h2, .meta_tags, .pagination, .subinfopost, #comments').remove(); - - item.description = content('.post').html(); - item.pubDate = new Date(detailResponse.data.match(/"datePublished":"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+00:00)","dateModified":/)[1]).toUTCString(); - - return item; - }) - ) - ); - - const title = $('title').text().split(' | ')[0]; - - ctx.state.data = { - title: `${title === 'BlogPosts' ? '全部' : title} - 一亩三分地论坛博客`, - link: currentUrl, - item: items, - }; -}; diff --git a/lib/routes/1point3acres/offer.js b/lib/routes/1point3acres/offer.js deleted file mode 100644 index 8fff2d597..000000000 --- a/lib/routes/1point3acres/offer.js +++ /dev/null @@ -1,211 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - // let out = ''; - // const { id } = ctx.params; - // const { year } = ctx.params.year || 'null'; - // year 2017-2022 - // 2017:6 2018:11 2019:12 2020:13 2021:14 2022:15 - // const { major } = ctx.params.major || 'null'; - // CS:1 MIS:2 - // const { school } = ctx.params.school || 'null'; - const year = ctx.params.year || 'null'; - const major = ctx.params.major || 'null'; - const school = ctx.params.school || 'null'; - // school == 'null' ? outname_w : 'CMU' - const url = 'https://api.1point3acres.com/offer/results?ps=15&pg=1'; - // const filter = '{"filters": {"planyr": "12", "planmajor": "1", "outname_w": "CMU"}}'; - // const filter = 'filters: {planyr: "12", planmajor: "1", outname_w: "CMU"}'; - let responseBasic; - // eslint-disable-next-line eqeqeq - if (year == 'null') { - // eslint-disable-next-line eqeqeq - if (major == 'null') { - // eslint-disable-next-line eqeqeq - if (school == 'null') { - // year空 major空 school空 - responseBasic = await got({ - method: 'post', - url, - json: { - filters: {}, - }, - }); - } else { - // year空 major空 school不空 - responseBasic = await got({ - method: 'post', - url, - json: { - filters: { - outname_w: school, - }, - }, - }); - } - } else { - // year空 major不空 - // eslint-disable-next-line eqeqeq - if (school == 'null') { - // year空 major不空 school空 - responseBasic = await got({ - method: 'post', - url, - json: { - filters: { - planmajor: major, - }, - }, - }); - } else { - // year空 major不空 school不空 - responseBasic = await got({ - method: 'post', - url, - json: { - filters: { - planmajor: major, - outname_w: school, - }, - }, - }); - } - } - } else { - // eslint-disable-next-line eqeqeq - if (major == 'null') { - // eslint-disable-next-line eqeqeq - if (school == 'null') { - // year不空 major空 school空 - responseBasic = await got({ - method: 'post', - url, - json: { - filters: { - planyr: year, - }, - }, - }); - } else { - // year不空 major空 school不空 - responseBasic = await got({ - method: 'post', - url, - json: { - filters: { - planyr: year, - outname_w: school, - }, - }, - }); - } - } else { - // eslint-disable-next-line eqeqeq - if (school == 'null') { - // year不空 major不空 school空 - responseBasic = await got({ - method: 'post', - url, - json: { - filters: { - planyr: year, - planmajor: major, - }, - }, - }); - } else { - // year不空 major不空 school不空 - responseBasic = await got({ - method: 'post', - url, - json: { - filters: { - planyr: year, - planmajor: major, - outname_w: school, - }, - }, - }); - } - } - } - const data = responseBasic.data.results; - // data.id-> 访问offer具体信息->获取 data.tid - // if (data.id !== 0) { - // out = await Promise.all( - // data.map(async (item) => { - // var gettidresponse = await got({ - // method: 'get', - // url: 'https://api.1point3acres.com/offer/results/'+ item.id + '/backgrounds', - // headers: { - // authorization: 'eyJhbGciOiJIUzUxMiIsImlhdCI6MTU3Njk5Njc5OSwiZXhwIjoxNTg0ODU5MTk5fQ.eyJ1aWQiOjQ1NzQyN30.0ei5UE6OgLBzN2_IS7xUIbIfW_S1Wzl42q2UeusbboxuzvctO_4Mz6YRr6f0PBLUVZMETxt8F0_4-yqIJ3_kUQ', - // }, - // }); - // var tid = gettidresponse.data.background.tid; - // //https: //www.1point3acres.com/bbs/thread-581177-1-1.html - // console.log(tid); - // const threadlink = 'https://www.1point3acres.com/bbs/thread-' + tid + '-1-1.html'; - // console.log(threadlink); - // return threadlink; - // }) - // ); - // } - // let responseBasic_1; - // responseBasic_1 = await got({ - // method: 'get', - // url: `https://api.1point3acres.com/offer/results/A7m20e4g/backgrounds`, - // headers: { - // authorization: `eyJhbGciOiJIUzUxMiIsImlhdCI6MTU3Njk5Njc5OSwiZXhwIjoxNTg0ODU5MTk5fQ.eyJ1aWQiOjQ1NzQyN30.0ei5UE6OgLBzN2_IS7xUIbIfW_S1Wzl42q2UeusbboxuzvctO_4Mz6YRr6f0PBLUVZMETxt8F0_4-yqIJ3_kUQ`, - // }, - // }); - // const tid = responseBasic_1.data.background.tid; - ctx.state.data = { - title: `录取结果 - 一亩三分地`, - link: `https://offer.1point3acres.com`, - description: `录取结果 - 一亩三分地`, - item: data.map((item) => ({ - title: item.planyr + `年` + item.planmajor + `@` + item.outname_w + ` ` + item.result + ` - 一亩三分地`, // `${year_result}年${major_result}@${outname_w_result} ${result_result}`, - description: - `国家:` + - item.country + - `
` + - `学校:` + - item.outname_w + - ` ` + - item.outname + - '
' + - `录取学位:` + - item.plandegree + - '
' + - `录取项目:` + - item.planmajor + - `-` + - item.planprogram + - '
' + - `录取结果:` + - item.result + - '
' + - `录取时间:` + - item.outtime + - '
' + - `通知方式:` + - item.noticemethod + - '
' + - `全奖/自费:` + - item.planfin + - '
' + - `申入学学期:` + - item.planterm + - '
' + - `申入学年度:` + - item.planyr + - '
' + - `提交时间:` + - item.submittime + - '
', - // pubDate: new Date(item.submittime + ' GMT+8').toUTCString(), - link: `https://offer.1point3acres.com`, - // link: out, - })), - }; -}; diff --git a/lib/routes/1point3acres/post.js b/lib/routes/1point3acres/post.js deleted file mode 100644 index 3f85db70e..000000000 --- a/lib/routes/1point3acres/post.js +++ /dev/null @@ -1,50 +0,0 @@ -const got = require('@/utils/got'); -const bbcode = require('bbcodejs'); - -module.exports = async (ctx) => { - const category = ctx.params.category; - let url; - 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 = '热门帖子'; - } - const responseBasic = await got({ - method: 'get', - url, - }); - const data = responseBasic.data.threads; - const bbcodeParser = new bbcode.Parser(); - - const items = await Promise.all( - data.map(async (item) => { - const result = { - title: item.subject, - description: `${item.summary}...

作者 ${item.author} · 回复 ${item.replies} · 查看 ${item.views}`, - 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)}

作者 ${item.author} · 回复 ${item.replies} · 查看 ${item.views}`; - }); - } catch (error) { - // nothing - } - return result; - }) - ); - ctx.state.data = { - title: `一亩三分地 - ${title}`, - link: `https://www.1point3acres.com/bbs/`, - item: items, - }; -}; diff --git a/lib/v2/1point3acres/blog.js b/lib/v2/1point3acres/blog.js new file mode 100644 index 000000000..cef1feeef --- /dev/null +++ b/lib/v2/1point3acres/blog.js @@ -0,0 +1,67 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const categoryMap = { + studyinusa: { + title: '留学申请', + id: 18, + }, + career: { + title: '找工求职', + id: 200, + }, + lifestyle: { + title: '生活攻略', + id: 370, + }, + invest: { + title: '投资理财', + id: 371, + }, + visa: { + title: '签证移民', + id: 194, + }, + news: { + title: '时政要闻', + id: 366, + }, + }; + + const { category } = ctx.params; + + const rootUrl = 'https://blog.1point3acres.com'; + const currentUrl = `${rootUrl}/${category}/`; + const { data } = await got(`${rootUrl}/wp-json/wp/v2/posts`, { + searchParams: { + categories: category ? categoryMap[category].id : undefined, + per_page: ctx.query.limit ? parseInt(ctx.query.limit) : 100, + }, + }); + + const items = data.map((item) => { + const $ = cheerio.load(item.content.rendered, null, false); + $('h2').nextAll().remove(); + $('[powered-by="1p3a"], h2').remove(); + $('img').each((_, img) => { + if (img.attribs.src.match(/wp-content\/uploads/)) { + img.attribs.src = img.attribs.src.replace(/(-\d+x\d+)/, ''); + } + }); + + return { + title: item.title.rendered, + description: $.html(), + link: item.link, + pubDate: parseDate(item.date_gmt), + }; + }); + + ctx.state.data = { + title: `${category ? `${categoryMap[category].title} | ` : ''}美国留学就业生活攻略`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/1point3acres/category.js b/lib/v2/1point3acres/category.js new file mode 100644 index 000000000..fe75c5aa4 --- /dev/null +++ b/lib/v2/1point3acres/category.js @@ -0,0 +1,17 @@ +const { rootUrl, apiRootUrl, types, ProcessThreads } = require('./utils'); + +module.exports = async (ctx) => { + const id = ctx.params.id ?? ''; + const type = ctx.params.type ?? 'hot'; + const order = ctx.params.order ?? ''; + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 10; + + const currentUrl = `${rootUrl}${id ? `/category/${id}` : ''}`; + const apiUrl = `${apiRootUrl}/api${id ? `/tags/${id}/` : ''}threads?type=${type}&includes=tags,forum_name,summary&ps=${limit}&pg=1&order=${order === '' ? '' : 'time_desc'}&is_groupid=1`; + + ctx.state.data = { + title: `一亩三分地 - ${id}${types[type]}`, + link: currentUrl, + item: await ProcessThreads(ctx.cache.tryGet, apiUrl, order), + }; +}; diff --git a/lib/v2/1point3acres/maintainer.js b/lib/v2/1point3acres/maintainer.js new file mode 100644 index 000000000..2695f2b3e --- /dev/null +++ b/lib/v2/1point3acres/maintainer.js @@ -0,0 +1,9 @@ +module.exports = { + '/blog/:category?': ['nczitzk'], + '/category/:id?/:type?/:order?': ['nczitzk'], + '/offer/:year?/:major?/:school?': ['NavePnow'], + '/post/:type?/:order?': ['NavePnow', 'DIYgod', 'nczitzk'], + '/section/:id?/:type?/:order?': ['nczitzk'], + '/user/:id/posts': ['Maecenas'], + '/user/:id/threads': ['Maecenas'], +}; diff --git a/lib/v2/1point3acres/offer.js b/lib/v2/1point3acres/offer.js new file mode 100644 index 000000000..0a84f6539 --- /dev/null +++ b/lib/v2/1point3acres/offer.js @@ -0,0 +1,69 @@ +const got = require('@/utils/got'); +const { art } = require('@/utils/render'); +const { parseDate } = require('@/utils/parse-date'); +const { join } = require('path'); + +module.exports = async (ctx) => { + // year 2017-2022 + // 2017:6 2018:11 2019:12 2020:13 2021:14 2022:15 + // CS:1 MIS:2 + const { year = 'null', major = 'null', school = 'null' } = ctx.params; + // const filter = 'filters: {planyr: "12", planmajor: "1", outname_w: "CMU"}'; + const responseBasic = await got.post('https://api.1point3acres.com/offer/results', { + searchParams: { + ps: 15, + pg: 1, + }, + json: { + filters: { + planyr: year !== 'null' ? year : undefined, + planmajor: major !== 'null' ? major : undefined, + outname_w: school !== 'null' ? school : undefined, + }, + }, + }); + + const data = responseBasic.data.results; + // data.id-> 访问offer具体信息->获取 data.tid + // if (data.id !== 0) { + // out = await Promise.all( + // data.map(async (item) => { + // var gettidresponse = await got({ + // method: 'get', + // url: 'https://api.1point3acres.com/offer/results/'+ item.id + '/backgrounds', + // headers: { + // authorization: 'eyJhbGciOiJIUzUxMiIsImlhdCI6MTU3Njk5Njc5OSwiZXhwIjoxNTg0ODU5MTk5fQ.eyJ1aWQiOjQ1NzQyN30.0ei5UE6OgLBzN2_IS7xUIbIfW_S1Wzl42q2UeusbboxuzvctO_4Mz6YRr6f0PBLUVZMETxt8F0_4-yqIJ3_kUQ', + // }, + // }); + // var tid = gettidresponse.data.background.tid; + // //https: //www.1point3acres.com/bbs/thread-581177-1-1.html + // console.log(tid); + // const threadlink = 'https://www.1point3acres.com/bbs/thread-' + tid + '-1-1.html'; + // console.log(threadlink); + // return threadlink; + // }) + // ); + // } + // let responseBasic_1; + // responseBasic_1 = await got({ + // method: 'get', + // url: `https://api.1point3acres.com/offer/results/A7m20e4g/backgrounds`, + // headers: { + // authorization: `eyJhbGciOiJIUzUxMiIsImlhdCI6MTU3Njk5Njc5OSwiZXhwIjoxNTg0ODU5MTk5fQ.eyJ1aWQiOjQ1NzQyN30.0ei5UE6OgLBzN2_IS7xUIbIfW_S1Wzl42q2UeusbboxuzvctO_4Mz6YRr6f0PBLUVZMETxt8F0_4-yqIJ3_kUQ`, + // }, + // }); + // const tid = responseBasic_1.data.background.tid; + ctx.state.data = { + title: '录取结果 - 一亩三分地', + link: 'https://offer.1point3acres.com', + item: data.map((item) => ({ + title: `${item.planyr}年${item.planmajor}@${item.outname_w}:${item.result} - 一亩三分地`, + description: art(join(__dirname, 'templates/offer.art'), { + item, + }), + pubDate: parseDate(item.dateline, 'X'), + link: 'https://offer.1point3acres.com', + guid: `1point3acres:offer:${year}:${major}:${school}:${item.id}`, + })), + }; +}; diff --git a/lib/v2/1point3acres/radar.js b/lib/v2/1point3acres/radar.js new file mode 100644 index 000000000..d92f198bb --- /dev/null +++ b/lib/v2/1point3acres/radar.js @@ -0,0 +1,53 @@ +module.exports = { + '1point3acres.com': { + _name: '一亩三分地', + blog: [ + { + title: '博客', + docs: 'https://docs.rsshub.app/bbs.html#yi-mu-san-fen-di', + source: ['/:category'], + target: '/1point3acres/blog/:category?', + }, + ], + instant: [ + { + title: '帖子', + docs: 'https://docs.rsshub.app/bbs.html#yi-mu-san-fen-di', + source: ['/'], + target: '/1point3acres/thread/:type?/:order?', + }, + { + title: '分区', + docs: 'https://docs.rsshub.app/bbs.html#yi-mu-san-fen-di', + source: ['/section/:id', '/'], + target: '/1point3acres/section/:id?/:type?/:order?', + }, + { + title: '标签', + docs: 'https://docs.rsshub.app/bbs.html#yi-mu-san-fen-di', + source: ['/section/:id', '/'], + target: '/1point3acres/category/:id?/:type?/:order?', + }, + { + title: '用户主题帖', + docs: 'https://docs.rsshub.app/bbs.html#yi-mu-san-fen-di', + source: ['/profile/:id', '/'], + target: '/1point3acres/user/:id/threads', + }, + { + title: '用户回帖', + docs: 'https://docs.rsshub.app/bbs.html#yi-mu-san-fen-di', + source: ['/profile/:id', '/'], + target: '/1point3acres/user/:id/posts', + }, + ], + offer: [ + { + title: '录取结果', + docs: 'https://docs.rsshub.app/bbs.html#yi-mu-san-fen-di', + source: ['/'], + target: '/1point3acres/offer', + }, + ], + }, +}; diff --git a/lib/v2/1point3acres/router.js b/lib/v2/1point3acres/router.js new file mode 100644 index 000000000..79c17f893 --- /dev/null +++ b/lib/v2/1point3acres/router.js @@ -0,0 +1,10 @@ +module.exports = function (router) { + router.get('/blog/:category?', require('./blog')); + router.get('/category/:id?/:type?/:order?', require('./category')); + router.get('/offer/:year?/:major?/:school?', require('./offer')); + router.get('/post/:type?/:order?', require('./thread')); + router.get('/section/:id?/:type?/:order?', require('./section')); + router.get('/thread/:type?/:order?', require('./thread')); + router.get('/user/:id/posts', require('./user/post')); + router.get('/user/:id/threads', require('./user/thread')); +}; diff --git a/lib/v2/1point3acres/section.js b/lib/v2/1point3acres/section.js new file mode 100644 index 000000000..d992c4272 --- /dev/null +++ b/lib/v2/1point3acres/section.js @@ -0,0 +1,28 @@ +const { rootUrl, apiRootUrl, types, ProcessThreads } = require('./utils'); + +const sections = { + 257: '留学申请', + 379: '世界公民', + 400: '投资理财', + 31: '生活干货', + 345: '职场达人', + 391: '人际关系', + 38: '海外求职', + 265: '签证移民', +}; + +module.exports = async (ctx) => { + const id = ctx.params.id ?? ''; + const type = ctx.params.type ?? 'hot'; + const order = ctx.params.order ?? ''; + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 10; + + const currentUrl = `${rootUrl}${id ? (isNaN(id) ? `/category/${id}` : `/section/${id}`) : ''}`; + const apiUrl = `${apiRootUrl}/api${id ? (isNaN(id) ? `/tags/${id}/` : `/forums/${id}/`) : ''}threads?type=${type}&includes=tags,forum_name,summary&ps=${limit}&pg=1&order=${order === '' ? '' : 'time_desc'}&is_groupid=1`; + + ctx.state.data = { + title: `一亩三分地 - ${sections.hasOwnProperty(id) ? sections[id] : id}${types[type]}`, + link: currentUrl, + item: await ProcessThreads(ctx.cache.tryGet, apiUrl, order), + }; +}; diff --git a/lib/v2/1point3acres/templates/image.art b/lib/v2/1point3acres/templates/image.art new file mode 100644 index 000000000..fdad197fb --- /dev/null +++ b/lib/v2/1point3acres/templates/image.art @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/lib/v2/1point3acres/templates/offer.art b/lib/v2/1point3acres/templates/offer.art new file mode 100644 index 000000000..0bdf703a6 --- /dev/null +++ b/lib/v2/1point3acres/templates/offer.art @@ -0,0 +1,11 @@ +国家:{{ item.country }}
+学校:{{ item.outname_w }} {{ item.outname }}
+录取学位:{{ item.plandegree }}
+录取项目:{{ item.planmajor }} - {{ item.planprogram }}
+录取结果:{{ item.result }}
+录取时间:{{ item.outtime }}
+通知方式:{{ item.noticemethod }}
+全奖/自费:{{ item.planfin }}
+申入学学期:{{ item.planterm }}
+申入学年度:{{ item.planyr }}
+提交时间:{{ item.submittime }} diff --git a/lib/v2/1point3acres/thread.js b/lib/v2/1point3acres/thread.js new file mode 100644 index 000000000..550e620aa --- /dev/null +++ b/lib/v2/1point3acres/thread.js @@ -0,0 +1,15 @@ +const { rootUrl, apiRootUrl, types, ProcessThreads } = require('./utils'); + +module.exports = async (ctx) => { + const type = ctx.params.type ?? 'hot'; + const order = ctx.params.order ?? ''; + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 10; + + const apiUrl = `${apiRootUrl}/api/threads?type=${type}&includes=tags,forum_name,summary&ps=${limit}&pg=1&order=${order === '' ? '' : 'time_desc'}&is_groupid=1`; + + ctx.state.data = { + title: `一亩三分地 - ${types[type]}`, + link: rootUrl, + item: await ProcessThreads(ctx.cache.tryGet, apiUrl, order), + }; +}; diff --git a/lib/routes/1point3acres/posts.js b/lib/v2/1point3acres/user/post.js similarity index 100% rename from lib/routes/1point3acres/posts.js rename to lib/v2/1point3acres/user/post.js diff --git a/lib/routes/1point3acres/threads.js b/lib/v2/1point3acres/user/thread.js similarity index 100% rename from lib/routes/1point3acres/threads.js rename to lib/v2/1point3acres/user/thread.js diff --git a/lib/v2/1point3acres/utils.js b/lib/v2/1point3acres/utils.js new file mode 100644 index 000000000..e11d6d261 --- /dev/null +++ b/lib/v2/1point3acres/utils.js @@ -0,0 +1,79 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); +const bbcode = require('bbcodejs'); + +const rootUrl = 'https://instant.1point3acres.com'; +const apiRootUrl = 'https://api.1point3acres.com'; + +const types = { + new: '最新帖子', + hot: '热门帖子', +}; + +module.exports = { + rootUrl, + apiRootUrl, + types, + ProcessThreads: async (tryGet, apiUrl, order) => { + const response = await got({ + method: 'get', + url: apiUrl, + headers: { + referer: rootUrl, + }, + }); + + const bbcodeParser = new bbcode.Parser(); + + const items = await Promise.all( + response.data.threads.map((item) => { + const result = { + guid: item.tid, + title: item.subject, + author: item.author, + link: `${rootUrl}/thread/${item.tid}`, + description: item.summary, + pubDate: parseDate((order === '' ? item.lastpost : item.dateline) * 1000), + category: [item.forum_name, ...item.tags.map((t) => t.displayname)], + }; + + return tryGet(result.link, async () => { + try { + const detailResponse = await got({ + method: 'get', + url: `${apiRootUrl}/api/v3/threads/${result.guid}`, + headers: { + referer: rootUrl, + }, + }); + + const data = detailResponse.data; + + result.description = bbcodeParser.toHTML(data.thread.message_bbcode); + + for (const a of data.thread.attachment_list) { + if (a.isimage === 1) { + result.description = result.description.replace( + new RegExp(`\\[attach\\]${a.aid}\\[\\/attach\\]`, 'g'), + art(path.join(__dirname, 'templates/image.art'), { + url: a.url, + height: a.height, + width: a.width, + }) + ); + } + } + } catch (e) { + // no-empty + } + + return result; + }); + }) + ); + + return items; + }, +};