fix(route): change matataki api host (#7148)
* fix: matataki api endpoint error * fix: remove unused function `getIpfsGateway` * style: auto format Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
191b2178af
commit
8a25f4773f
|
|
@ -6,7 +6,7 @@ module.exports = async (ctx) => {
|
|||
|
||||
const authorName = await matatakiUtils.getUserNickname(authorId);
|
||||
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`https://api.smartsignature.io/posts/timeRanking?author=${authorId}`, ipfsFlag);
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`/posts/timeRanking?author=${authorId}`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki - ${authorName}作品 ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ module.exports = async (ctx) => {
|
|||
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`);
|
||||
const response = await matatakiUtils.get(`/favorites/post?userId=${userId}&fid=${favoriteListId}&page=1`);
|
||||
let items;
|
||||
|
||||
if (ipfsFlag) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ 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);
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`/posts/scoreRanking?${querystring}`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki - 热门作品 ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ module.exports = async (ctx) => {
|
|||
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);
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`/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)' : ''}`,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ 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);
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`/posts/timeRanking?${querystring}`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki - 最新作品 ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ module.exports = async (ctx) => {
|
|||
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);
|
||||
const items = await matatakiUtils.getPostsAsFeedItems(`/minetoken/${id}/related?filter=${filterCode}&sort=time-desc&onlyCreator=0&page=1`, ipfsFlag);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `瞬Matataki - ${tokenName ? tokenName : 'Fan票'}关联作品 ${ipfsFlag ? '(IPFS)' : ''}`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
const got = require('@/utils/got');
|
||||
|
||||
/**
|
||||
* Matataki API 地址
|
||||
*/
|
||||
const MTATAKI_API_URL = 'https://api.mttk.net';
|
||||
|
||||
/**
|
||||
* Matataki 官网地址
|
||||
*/
|
||||
|
|
@ -8,73 +13,68 @@ 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
|
||||
* @param {string} path 以 / 开始
|
||||
*/
|
||||
async function get(url) {
|
||||
async function get(path) {
|
||||
return await got({
|
||||
method: 'get',
|
||||
url: url,
|
||||
url: MTATAKI_API_URL + path,
|
||||
headers: {
|
||||
Referer: MATATAKI_WEB_URL,
|
||||
},
|
||||
});
|
||||
}
|
||||
exports.IPFS_GATEWAY_URL = IPFS_GATEWAY_URL;
|
||||
|
||||
exports.get = get;
|
||||
|
||||
/**
|
||||
* 获取用户信息昵称
|
||||
*
|
||||
* @param {number} userId
|
||||
*/
|
||||
exports.getUserNickname = async (userId) => {
|
||||
async function getUserNickname(userId) {
|
||||
try {
|
||||
const userInfoResponse = await get(`https://api.smartsignature.io/user/${userId}`);
|
||||
const userInfoResponse = await get(`/user/${userId}`);
|
||||
return `${userInfoResponse.data.data.nickname || userInfoResponse.data.data.username}`;
|
||||
} catch (err) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Fan票名称
|
||||
*
|
||||
* @param {number} tokenId
|
||||
*/
|
||||
exports.getTokenName = async (tokenId) => {
|
||||
async function getTokenName(tokenId) {
|
||||
try {
|
||||
const tokenInfoResponse = await get(`https://api.smartsignature.io/minetoken/${tokenId}`);
|
||||
const tokenInfoResponse = await get(`/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`);
|
||||
async function getPostIpfsHtmlHash(postId) {
|
||||
const ipfsInfoResponse = await get(`/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);
|
||||
async function postToIpfsFeedItem(item) {
|
||||
const ipfsHtmlHash = await getPostIpfsHtmlHash(item.id);
|
||||
|
||||
return {
|
||||
title: `${item.title} - ${item.nickname || item.author}${item.token_name ? ' $' + item.token_name : ''}`,
|
||||
|
|
@ -83,19 +83,21 @@ exports.postToIpfsFeedItem = async (item) => {
|
|||
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,
|
||||
});
|
||||
async function postToFeedItem(item) {
|
||||
return {
|
||||
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数组
|
||||
|
|
@ -103,10 +105,21 @@ exports.postToFeedItem = (item) => ({
|
|||
* @param {string} url Matataki作品相关API的url
|
||||
* @param {ipfsFlag} ipfsFlag 是否取IPFS地址
|
||||
*/
|
||||
exports.getPostsAsFeedItems = async (url, ipfsFlag) => {
|
||||
async function getPostsAsFeedItems(url, ipfsFlag) {
|
||||
const response = await get(url);
|
||||
if (ipfsFlag) {
|
||||
return await Promise.all(response.data.data.list.map(this.postToIpfsFeedItem));
|
||||
return await Promise.all(response.data.data.list.map(postToIpfsFeedItem));
|
||||
}
|
||||
return response.data.data.list.map(this.postToFeedItem);
|
||||
return response.data.data.list.map(postToFeedItem);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
IPFS_GATEWAY_URL,
|
||||
get,
|
||||
getUserNickname,
|
||||
getTokenName,
|
||||
getPostIpfsHtmlHash,
|
||||
postToIpfsFeedItem,
|
||||
postToFeedItem,
|
||||
getPostsAsFeedItems,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue