feat: add feature/matataki (#6250)
This commit is contained in:
@@ -2366,6 +2366,51 @@
|
||||
},
|
||||
],
|
||||
},
|
||||
'matataki.io': {
|
||||
_name: 'matataki',
|
||||
www: [
|
||||
{
|
||||
title: '最热作品',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#matataki',
|
||||
source: '/article/',
|
||||
target: '/matataki/posts/hot'
|
||||
},
|
||||
{
|
||||
title: '最新作品',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#matataki',
|
||||
source: '/article/latest',
|
||||
target: '/matataki/posts/latest'
|
||||
},
|
||||
{
|
||||
title: '作者创作',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#matataki',
|
||||
source: '/user/:uid',
|
||||
target: (params) => `/matataki/users/${params.uid}/posts`
|
||||
},
|
||||
{
|
||||
title: 'Fan票关联作品',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#matataki',
|
||||
source: ['/token/:tokenId', '/token/:tokenId/circle'],
|
||||
target: (params) => `/matataki/tokens/${params.tokenId}/posts`
|
||||
},
|
||||
{
|
||||
title: '标签关联作品',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#matataki',
|
||||
source: ['/tag/:tagId'],
|
||||
target: (params, url) => {
|
||||
const tagName = new URL(url).searchParams.get('name');
|
||||
return `/matataki/tags/${params.tagId}/${tagName}/posts`;
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
title: '收藏夹',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#matataki',
|
||||
source: '/user/:uid/favlist/:fid',
|
||||
target: (params) => `/matataki/users/${params.uid}/favorites/${params.fid}/posts`
|
||||
},
|
||||
]
|
||||
},
|
||||
'eventernote.com': {
|
||||
_name: 'Eventernote',
|
||||
www: [
|
||||
|
||||
@@ -308,6 +308,46 @@ Tag
|
||||
|
||||
<Route author="loganrockmore" example="/letterboxd/user/followingdiary/demiadejuyigbe" path="/letterboxd/user/followingdiary/:username" :paramsDesc="['username']" />
|
||||
|
||||
## Matataki
|
||||
|
||||
::: tip 提示
|
||||
|
||||
在Matataki发表的文章会上传到星际文件系统(IPFS),永久保存。即使站内文章因为各种原因消失,用RSS获取过带IPFS连接的Feed Item的话,还是可以从RSS阅读器找回文章的。
|
||||
IPFS网关有可能失效,那时候换成其他网关。
|
||||
|
||||
:::
|
||||
|
||||
### 最热作品
|
||||
|
||||
<Route author="whyouare111" example="/matataki/posts/hot" path="/matataki/posts/hot/:ipfsFlag?" :paramsDesc="['IPFS标识,置空item指向主站,有值item指向IPFS网关']" radar="1"/>
|
||||
|
||||
### 最新作品
|
||||
|
||||
<Route author="whyouare111" example="/matataki/posts/latest/ipfs" path="/matataki/posts/latest/:ipfsFlag?" :paramsDesc="['IPFS标识,置空item指向主站,有值item指向IPFS网关']" radar="1"/>
|
||||
|
||||
### 作者创作
|
||||
|
||||
<Route author="whyouare111" example="/matataki/users/9/posts" path="/matataki/users/:authorId/posts/:ipfsFlag?" :paramsDesc="['作者ID', 'IPFS标识,置空item指向主站,有值item指向IPFS网关']" radar="1"/>
|
||||
|
||||
### Fan票关联作品
|
||||
|
||||
<Route author="whyouare111" example="/matataki/tokens/22/posts/3" path="/matataki/tokens/:tokenId/posts/:filterCode/:ipfsFlag?" :paramsDesc="['Fan票ID', '过滤条件,见下表', 'IPFS标识,置空item指向主站,有值item指向IPFS网关']" radar="1">
|
||||
|
||||
| 需持票 | 需支付 | 全部 |
|
||||
| ---- | ----- | --- |
|
||||
| 1 | 2 | 3 |
|
||||
|
||||
</Route>
|
||||
|
||||
### 标签关联作品
|
||||
|
||||
<Route author="whyouare111" example="/matataki/tags/150/区块链/posts" path="/matataki/tags/:tagId/:tagName/posts/:ipfsFlag?" :paramsDesc="['标签ID', '标签名称','IPFS标识,置空item指向主站,有值item指向IPFS网关']" radar="1"/>
|
||||
|
||||
|
||||
### 收藏夹
|
||||
|
||||
<Route author="whyouare111" example="/matataki/users/3017/favorites/155/posts" path="/matataki/users/:userId/favorites/:favoriteListId/posts/:ipfsFlag?" :paramsDesc="['用户ID', '收藏夹ID','IPFS标识,置空item指向主站,有值item指向IPFS网关']" radar="1"/>
|
||||
|
||||
## Matters
|
||||
|
||||
### 熱門文章
|
||||
|
||||
@@ -3512,6 +3512,20 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
|
||||
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
|
||||
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
|
||||
|
||||
// 瞬Matataki
|
||||
// 热门作品
|
||||
router.get('/matataki/posts/hot/:ipfsFlag?', require('./routes/matataki/site/posts/scoreranking'));
|
||||
// 最新作品
|
||||
router.get('/matataki/posts/latest/:ipfsFlag?', require('./routes/matataki/site/posts/timeranking'));
|
||||
// 作者创作
|
||||
router.get('/matataki/users/:authorId/posts/:ipfsFlag?', require('./routes/matataki/site/posts/author'));
|
||||
// Fan票关联作品
|
||||
router.get('/matataki/tokens/:id/posts/:filterCode/:ipfsFlag?', require('./routes/matataki/site/posts/token'));
|
||||
// 标签关联作品
|
||||
router.get('/matataki/tags/:tagId/:tagName/posts/:ipfsFlag?', require('./routes/matataki/site/posts/tag'));
|
||||
// 收藏夹
|
||||
router.get('/matataki/users/:userId/favorites/:favoriteListId/posts/:ipfsFlag?', require('./routes/matataki/site/posts/favorite'));
|
||||
|
||||
// SoBooks
|
||||
router.get('/sobooks/tag/:id?', require('./routes/sobooks/tag'));
|
||||
router.get('/sobooks/date/:date?', require('./routes/sobooks/date'));
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
const matatakiUtils = require('@/routes/matataki/utils/matataki-utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
||||
const authorId = ctx.params.authorId;
|
||||
const ipfsFlag = !!ctx.params.ipfsFlag;
|
||||
|
||||
const authorName = await matatakiUtils.getUserNickname(authorId);
|
||||
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`https://api.smartsignature.io/posts/timeRanking?author=${authorId}`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki - ${authorName}作品 ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
link: `https://www.matataki.io/user/${authorId}`,
|
||||
description: `瞬Matataki - ${authorName}作品`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
const matatakiUtils = require('@/routes/matataki/utils/matataki-utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
||||
const userId = ctx.params.userId;
|
||||
const favoriteListId = ctx.params.favoriteListId;
|
||||
const ipfsFlag = !!ctx.params.ipfsFlag;
|
||||
|
||||
const response = await matatakiUtils.get(`https://api.smartsignature.io/favorites/post?userId=${userId}&fid=${favoriteListId}&page=1`);
|
||||
let items;
|
||||
|
||||
if (ipfsFlag) {
|
||||
items = await Promise.all(response.data.data.list.map(async (item) => {
|
||||
|
||||
const ipfsHtmlHash = await matatakiUtils.getPostIpfsHtmlHash(item.pid);
|
||||
|
||||
return {
|
||||
title: `${item.title}`,
|
||||
description: item.short_content,
|
||||
link: `${matatakiUtils.IPFS_GATEWAY_URL}/ipfs/${ipfsHtmlHash}`,
|
||||
pubDate: item.create_time,
|
||||
guid: ipfsHtmlHash,
|
||||
};
|
||||
|
||||
}));
|
||||
}
|
||||
else {
|
||||
items = response.data.data.list.map((item) => ({
|
||||
title: `${item.title}`,
|
||||
description: item.short_content,
|
||||
link: `https://www.matataki.io/p/${item.pid}`,
|
||||
pubDate: item.create_time,
|
||||
}));
|
||||
}
|
||||
|
||||
const text = `瞬Matataki - ${response.data.data.info.nickname || response.data.data.info.username} 收藏夹 #${response.data.data.info.name}# ${ipfsFlag ? '(IPFS)' : ''}`;
|
||||
ctx.state.data = {
|
||||
title: text,
|
||||
link: `https://www.matataki.io/user/${userId}/favlist?fid=${favoriteListId}`,
|
||||
description: text,
|
||||
allowEmpty: true,
|
||||
item: items,
|
||||
};
|
||||
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
const matatakiUtils = require('@/routes/matataki/utils/matataki-utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
||||
const querystring = ctx.request.querystring;
|
||||
const ipfsFlag = !!ctx.params.ipfsFlag;
|
||||
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`https://api.smartsignature.io/posts/scoreRanking?${querystring}`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki - 热门作品 ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
link: `https://www.matataki.io/article/`,
|
||||
description: `瞬Matataki - 热门作品`,
|
||||
item: items
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
const matatakiUtils = require('@/routes/matataki/utils/matataki-utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
||||
const tagId = ctx.params.tagId;
|
||||
const tagName = ctx.params.tagName;
|
||||
const ipfsFlag = !!ctx.params.ipfsFlag;
|
||||
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`https://api.smartsignature.io/posts/getPostByTag?pagesize=20&tagid=${tagId}&extra=short_content&orderBy=hot_score&order=desc&page=1`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki #${tagName} ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
link: `https://www.matataki.io/tags/${tagId}`,
|
||||
description: `瞬Matataki #${tagName}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
const matatakiUtils = require('@/routes/matataki/utils/matataki-utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
||||
const querystring = ctx.request.querystring;
|
||||
const ipfsFlag = !!ctx.params.ipfsFlag;
|
||||
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`https://api.smartsignature.io/posts/timeRanking?${querystring}`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki - 最新作品 ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
link: `https://www.matataki.io/article/latest`,
|
||||
description: `瞬Matataki - 最新作品`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
const matatakiUtils = require('@/routes/matataki/utils/matataki-utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
|
||||
const id = ctx.params.id;
|
||||
const filterCode = ctx.params.filterCode;
|
||||
const ipfsFlag = !!ctx.params.ipfsFlag;
|
||||
|
||||
const tokenName = await matatakiUtils.getTokenName(id);
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`https://api.smartsignature.io/minetoken/${id}/related?filter=${filterCode}&sort=time-desc&onlyCreator=0&page=1`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki - ${tokenName ? tokenName : 'Fan票'}关联作品 ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
link: `https://www.matataki.io/token/${id}/circle`,
|
||||
description: `瞬Matataki - ${tokenName ? tokenName : 'Fan票'}关联作品`,
|
||||
allowEmpty: true,
|
||||
item: items,
|
||||
};
|
||||
|
||||
};
|
||||
@@ -0,0 +1,117 @@
|
||||
const got = require('@/utils/got');
|
||||
|
||||
/**
|
||||
* Matataki 官网地址
|
||||
*/
|
||||
const MATATAKI_WEB_URL = 'https://www.matataki.io/';
|
||||
|
||||
/**
|
||||
* IPFS网关的URL。可以换成其他公共网关,也可以换成自建的网关地址
|
||||
*/
|
||||
// const IPFS_GATEWAY_URL = 'https://ipfs.io';
|
||||
// const IPFS_GATEWAY_URL = 'https://cf-ipfs.com';
|
||||
const IPFS_GATEWAY_URL = 'https://10.via0.com';
|
||||
|
||||
/**
|
||||
* 以`get` 方式调用Matataki API的简单封装
|
||||
*
|
||||
* @param {string} url
|
||||
*/
|
||||
async function get(url) {
|
||||
return await got({
|
||||
method: 'get',
|
||||
url: url,
|
||||
headers: {
|
||||
Referer: MATATAKI_WEB_URL,
|
||||
},
|
||||
});
|
||||
}
|
||||
exports.IPFS_GATEWAY_URL = IPFS_GATEWAY_URL;
|
||||
|
||||
exports.get = get;
|
||||
|
||||
/**
|
||||
* 获取用户信息昵称
|
||||
*
|
||||
* @param {number} userId
|
||||
*/
|
||||
exports.getUserNickname = async (userId) => {
|
||||
try {
|
||||
const userInfoResponse = await get(`https://api.smartsignature.io/user/${userId}`);
|
||||
return `${userInfoResponse.data.data.nickname || userInfoResponse.data.data.username}`;
|
||||
}
|
||||
catch (err) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 获取Fan票名称
|
||||
*
|
||||
* @param {number} tokenId
|
||||
*/
|
||||
exports.getTokenName = async (tokenId) => {
|
||||
try {
|
||||
const tokenInfoResponse = await get(`https://api.smartsignature.io/minetoken/${tokenId}`);
|
||||
return `${tokenInfoResponse.data.data.token.name}`;
|
||||
}
|
||||
catch (err) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取Matataki作品在IPFS上的Hash
|
||||
*
|
||||
* @param {number} postId
|
||||
*/
|
||||
exports.getPostIpfsHtmlHash = async (postId) => {
|
||||
const ipfsInfoResponse = await get(`https://api.smartsignature.io/p/${postId}/ipfs`);
|
||||
return `${ipfsInfoResponse.data.data[0].htmlHash}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* 将Matataki作品条目转为指向IPFS网关的RSS订阅源条目
|
||||
*
|
||||
* @param {Object} item
|
||||
*/
|
||||
exports.postToIpfsFeedItem = async (item) => {
|
||||
|
||||
const ipfsHtmlHash = await this.getPostIpfsHtmlHash(item.id);
|
||||
|
||||
return {
|
||||
title: `${item.title} - ${item.nickname || item.author}${item.token_name ? ' $' + item.token_name : ''}`,
|
||||
description: item.short_content,
|
||||
link: `${IPFS_GATEWAY_URL}/ipfs/${ipfsHtmlHash}`,
|
||||
pubDate: item.create_time,
|
||||
guid: ipfsHtmlHash,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 将Matataki作品条目转为指向官网的RSS订阅源条目
|
||||
*
|
||||
* @param {Object} item
|
||||
*/
|
||||
exports.postToFeedItem = (item) => ({
|
||||
title: `${item.title} - ${item.nickname || item.author}${item.token_name ? ' $' + item.token_name : ''}`,
|
||||
description: item.short_content,
|
||||
link: `https://www.matataki.io/p/${item.id}`,
|
||||
pubDate: item.create_time,
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取作品列表并转为Feed Item数组
|
||||
*
|
||||
* @param {string} url Matataki作品相关API的url
|
||||
* @param {ipfsFlag} ipfsFlag 是否取IPFS地址
|
||||
*/
|
||||
exports.getPostsAsFeedItems = async (url, ipfsFlag) => {
|
||||
const response = await get(url);
|
||||
if (ipfsFlag) {
|
||||
return await Promise.all(response.data.data.list.map(this.postToIpfsFeedItem));
|
||||
}
|
||||
return response.data.data.list.map(this.postToFeedItem);
|
||||
};
|
||||
Reference in New Issue
Block a user