feat(route): followin (#12574)

* feat(route): followin

* feat: add radar

* fix: fix news title
This commit is contained in:
Tony
2023-05-28 21:38:48 +08:00
committed by GitHub
parent 55cbde4789
commit 728490130e
12 changed files with 372 additions and 0 deletions
+36
View File
@@ -53,6 +53,42 @@ pageClass: routes
<RouteEn author="HenryQW" example="/finviz/news/AAPL" path="/finviz/news/:ticker" :paramsDesc="['The stock ticker']"/>
## Followin
### Home
<RouteEn author="TonyRL" example="/followin" path="/followin/:categoryId?/:lang?" :paramsDesc="['Category ID, see table below, `1` by default', 'Language, see table below, `en` by default']" radar="1">
Category ID
| For You | Market | Meme | BRC20 | NFT | Thread | In-depth | Tutorials | Videos |
| ------- | ------ | ---- | ----- | --- | ------ | -------- | --------- | ------ |
| 1 | 9 | 13 | 14 | 3 | 5 | 6 | 8 | 11 |
Language
| English | 简体中文 | 繁體中文 | Tiếng Việt |
| ------- | ------- | -------- | ---------- |
| en | zh-Hans | zh-Hant | vi |
</RouteEn>
### News
<RouteEn author="TonyRL" example="/followin/news" path="/followin/news/:lang?" :paramsDesc="['Language, see table above, `en` by default']" radar="1" />
### KOL
<RouteEn author="TonyRL" example="/followin/kol/4075592991" path="/followin/kol/:kolId/:lang?" :paramsDesc="['KOL ID, can be found in URL', 'Language, see table above, `en` by default']" radar="1" />
### Topic
<RouteEn author="TonyRL" example="/followin/topic/40" path="/followin/topic/:topicId/:lang?" :paramsDesc="['Topic ID, can be found in URL', 'Language, see table above, `en` by default']" radar="1" />
### Tag
<RouteEn author="TonyRL" example="/followin/tag/177008" path="/followin/tag/:tagId/:lang?" :paramsDesc="['Tag ID, can be found in URL', 'Language, see table above, `en` by default']" radar="1" />
## Futubull
### Headlines
+36
View File
@@ -92,6 +92,42 @@ pageClass: routes
<Route author="HenryQW" example="/finviz/news/AAPL" path="/finviz/news/:ticker" :paramsDesc="['股票代码']"/>
## Followin
### 首页
<Route author="TonyRL" example="/followin" path="/followin/:categoryId?/:lang?" :paramsDesc="['分类 ID,见下表,默认为 `1`', '语言,见下表,默认为 `en`']" radar="1">
分类 ID
| 推荐 | 行情 | Meme | BRC20 | NFT | 长推 | 深度 | 入门 | 视频 |
| ---- | ---- | ---- | ----- | --- | ---- | ---- | ---- | ---- |
| 1 | 9 | 13 | 14 | 3 | 5 | 6 | 8 | 11 |
语言
| English | 简体中文 | 繁體中文 | Tiếng Việt |
| ------- | -------- | -------- | ---------- |
| en | zh-Hans | zh-Hant | vi |
</Route>
### 快讯
<Route author="TonyRL" example="/followin/news" path="/followin/news/:lang?" :paramsDesc="['语言,见上表,默认为 `en`']" radar="1" />
### KOL
<Route author="TonyRL" example="/followin/kol/4075592991" path="/followin/kol/:kolId/:lang?" :paramsDesc="['KOL ID,可在 URL 找到', '语言,见上表,默认为 `en`']" radar="1" />
### 话题
<Route author="TonyRL" example="/followin/topic/40" path="/followin/topic/:topicId/:lang?" :paramsDesc="['话题 ID,可在 URL 找到', '语言,见上表,默认为 `en`']" radar="1" />
### 标签
<Route author="TonyRL" example="/followin/tag/177008" path="/followin/tag/:tagId/:lang?" :paramsDesc="['标签 ID,可在 URL 找到', '语言,见上表,默认为 `en`']" radar="1" />
## FX Markets
### 分类
+35
View File
@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const { apiUrl, favicon, getBParam, getBuildId, getGToken, parseList, parseItem } = require('./utils');
module.exports = async (ctx) => {
const { categoryId = '1', lang = 'en' } = ctx.params;
const { limit = 20 } = ctx.query;
const gToken = await getGToken(ctx.cache.tryGet);
const bParam = getBParam(lang);
const { data: response } = await got.post(`${apiUrl}/feed/list/recommended`, {
headers: {
'x-bparam': JSON.stringify(bParam),
'x-gtoken': gToken,
},
json: {
category_id: parseInt(categoryId),
count: parseInt(limit),
},
});
if (response.code !== 2000) {
throw Error(response.msg);
}
const buildId = await getBuildId(ctx.cache.tryGet);
const list = parseList(response.data.list, lang, buildId);
const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet)));
ctx.state.data = {
title: 'Followin',
link: 'https://followin.io',
image: favicon,
item: items,
};
};
+25
View File
@@ -0,0 +1,25 @@
const got = require('@/utils/got');
const { baseUrl, getBuildId, parseList, parseItem } = require('./utils');
module.exports = async (ctx) => {
const { kolId, lang = 'en' } = ctx.params;
const { limit = 10 } = ctx.query;
const buildId = await getBuildId(ctx.cache.tryGet);
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/${lang}/kol/${kolId}.json`);
const { queries } = response.pageProps.dehydratedState;
const { data: profile } = queries.find((q) => q.queryKey[0] === '/user/get_profile').state;
const list = parseList(queries.find((q) => q.queryKey[0] === '/feed/list/user').state.data.pages[0].list.slice(0, limit), lang, buildId);
const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet)));
ctx.state.data = {
title: `${profile.nickname} - Followin`,
description: profile.bio,
link: `${baseUrl}/${lang}/kol/${kolId}`,
image: profile.avatar,
language: lang,
item: items,
};
};
+7
View File
@@ -0,0 +1,7 @@
module.exports = {
'/kol/:kolId/:lang?': ['TonyRL'],
'/news/:lang?': ['TonyRL'],
'/tag/:tagId/:lang?': ['TonyRL'],
'/topic/:topicId/:lang?': ['TonyRL'],
'/:categoryId?/:lang?': ['TonyRL'],
};
+21
View File
@@ -0,0 +1,21 @@
const got = require('@/utils/got');
const { baseUrl, favicon, getBuildId, parseList, parseItem } = require('./utils');
module.exports = async (ctx) => {
const { lang = 'en' } = ctx.params;
const { limit = 20 } = ctx.query;
const buildId = await getBuildId(ctx.cache.tryGet);
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/${lang}/news.json`);
const list = parseList(response.pageProps.dehydratedState.queries.find((q) => q.queryKey[0] === '/feed/list/recommended/news').state.data.pages[0].list.slice(0, limit), lang, buildId);
const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet)));
ctx.state.data = {
title: `${lang === 'en' ? 'News' : lang === 'vi' ? 'Bản tin' : '快讯'} - Followin`,
link: `${baseUrl}/${lang}/news`,
image: favicon,
language: lang,
item: items,
};
};
+37
View File
@@ -0,0 +1,37 @@
module.exports = {
'followin.io': {
_name: 'Followin',
'.': [
{
title: '首页',
docs: 'https://docs.rsshub.app/finance.html#followin',
source: ['/:lang'],
target: (params) => (params.lang !== 'news' ? '/followin/1/:lang' : ''),
},
{
title: '快讯',
docs: 'https://docs.rsshub.app/finance.html#followin',
source: ['/:lang?/news', '/news'],
target: '/followin/news/:lang?',
},
{
title: 'KOL',
docs: 'https://docs.rsshub.app/finance.html#followin',
source: ['/:lang/kol/:kolId', '/kol/:kolId'],
target: '/followin/kol/:kolId/:lang?',
},
{
title: '话题',
docs: 'https://docs.rsshub.app/finance.html#followin',
source: ['/:lang/topic/:topicId', '/topic/:topicId'],
target: '/followin/topic/:topicId/:lang?',
},
{
title: '标签',
docs: 'https://docs.rsshub.app/finance.html#followin',
source: ['/:lang/tag/:tagId', '/tag/:tagId'],
target: '/followin/tag/:tagId/:lang?',
},
],
},
};
+7
View File
@@ -0,0 +1,7 @@
module.exports = (router) => {
router.get('/kol/:kolId/:lang?', require('./kol'));
router.get('/news/:lang?', require('./news'));
router.get('/tag/:tagId/:lang?', require('./tag'));
router.get('/topic/:topicId/:lang?', require('./topic'));
router.get('/:categoryId?/:lang?', require('./index'));
};
+44
View File
@@ -0,0 +1,44 @@
const got = require('@/utils/got');
const { apiUrl, baseUrl, getBParam, getBuildId, getGToken, parseList, parseItem } = require('./utils');
module.exports = async (ctx) => {
const { tagId, lang = 'en' } = ctx.params;
const { limit = 20 } = ctx.query;
const buildId = await getBuildId(ctx.cache.tryGet);
const tagInfo = await ctx.cache.tryGet(`followin:tag:${tagId}:${lang}`, async () => {
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/${lang}/tag/${tagId}.json`);
const { queries } = response.pageProps.dehydratedState;
const { base_info: tagInfo } = queries.find((q) => q.queryKey[0] === '/tag/info/v2').state.data;
return tagInfo;
});
const gToken = await getGToken(ctx.cache.tryGet);
const bParam = getBParam(lang);
const { data: tagResponse } = await got.post(`${apiUrl}/feed/list/tag`, {
headers: {
'x-bparam': JSON.stringify(bParam),
'x-gtoken': gToken,
},
json: {
count: limit,
id: parseInt(tagId),
type: 'tag_discussion_feed',
},
});
if (tagResponse.code !== 2000) {
throw Error(tagResponse.msg);
}
const list = parseList(tagResponse.data.list.slice(0, limit), lang, buildId);
const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet)));
ctx.state.data = {
title: `${tagInfo.name} - Followin`,
description: tagInfo.description,
link: `${baseUrl}/${lang}/tag/${tagId}`,
image: tagInfo.logo,
language: lang,
item: items,
};
};
+15
View File
@@ -0,0 +1,15 @@
{{ each list l }}
{{@ l.translated_content.replaceAll('\n', '<br>') || l.content.replaceAll('\n', '<br>') }}
<br>
{{ if l.images.length }}
{{ each l.images img }}
<img src="{{ img }}">
{{ /each }}
{{ /if }}
{{ if l.link_previews.length }}
{{ each l.link_previews a }}
<a href="{{ a.link }}">{{ a.title }}<br>{{ a.content }}</a>
{{ /each }}
{{ /if }}
<br>
{{ /each }}
+25
View File
@@ -0,0 +1,25 @@
const got = require('@/utils/got');
const { baseUrl, getBuildId, parseList, parseItem } = require('./utils');
module.exports = async (ctx) => {
const { topicId, lang = 'en' } = ctx.params;
const { limit = 20 } = ctx.query;
const buildId = await getBuildId(ctx.cache.tryGet);
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/${lang}/topic/${topicId}.json`);
const { queries } = response.pageProps.dehydratedState;
const { data: topicInfo } = queries.find((q) => q.queryKey[0] === '/topic/info').state;
const list = parseList(queries.find((q) => q.queryKey[0] === '/feed/list/topic').state.data.pages[0].list.slice(0, limit), lang, buildId);
const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet)));
ctx.state.data = {
title: `${topicInfo.title} - Followin`,
description: topicInfo.desc,
link: `${baseUrl}/${lang}/topic/${topicId}`,
image: topicInfo.logo,
language: lang,
item: items,
};
};
+84
View File
@@ -0,0 +1,84 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const config = require('@/config').value;
const { art } = require('@/utils/render');
const { join } = require('path');
const apiUrl = 'https://api.followin.io';
const baseUrl = 'https://followin.io';
const favicon = `${baseUrl}/favicon.ico`;
const getBParam = (lang) => ({
a: 'web',
b: '',
c: lang,
d: 0,
e: '',
f: '',
g: '',
h: '0.1.0',
i: 'official',
});
const getBuildId = (tryGet) =>
tryGet(
'followin:buildId',
async () => {
const { data: pageResponse } = await got(baseUrl);
const $ = cheerio.load(pageResponse);
const { buildId } = JSON.parse($('script#__NEXT_DATA__').text());
return buildId;
},
config.cache.routeExpire,
false
);
const getGToken = (tryGet) =>
tryGet('followin:gtoken', async () => {
const { data } = await got.post(`${apiUrl}/user/gtoken`);
return data.data.gtoken;
});
const parseList = (list, lang, buildId) =>
list.map((item) => ({
title: item.translated_title || item.title,
description: item.translated_content || item.content,
link: `${baseUrl}/${lang === 'en' ? '' : `${lang}/`}feed/${item.id}`,
pubDate: parseDate(item.publish_time, 'x'),
category: item.tags.map((tag) => tag.name),
author: item.nickname,
nextData: `${baseUrl}/_next/data/${buildId}/${lang}/feed/${item.id}.json`,
}));
const parseItem = (item, tryGet) =>
tryGet(item.link, async () => {
const { data } = await got(item.nextData);
const { queries } = data.pageProps.dehydratedState;
const info = queries.find((q) => q.queryKey[0] === '/feed/info').state;
const thread = queries.find((q) => q.queryKey[0] === '/feed/thread');
if (thread) {
item.description = art(join(__dirname, 'templates/thread.art'), {
list: thread.state.data.list,
});
} else {
item.description = info.data.translated_full_content || info.data.full_content;
}
item.updated = parseDate(info.dataUpdatedAt, 'x');
item.category = [...new Set([...item.category, ...info.data.tags.map((tag) => tag.name)])];
return item;
});
module.exports = {
apiUrl,
baseUrl,
favicon,
getBParam,
getBuildId,
getGToken,
parseList,
parseItem,
};