Files
RSSHub/lib/v2/curiouscat/user.js
Yorzaren 9295c51713 fix(route): Fix broken CuriousCat URLs (#12715)
* Fix broken curiouscat URLs

The https://curiouscat.qa does not work, so the URL should be https://curiouscat.live

* refactor: migrate to v2

---------
2023-06-27 00:58:36 +08:00

41 lines
1.2 KiB
JavaScript

const got = require('@/utils/got');
const fetchAPIByUser = async (user) => {
const baseURL = 'https://curiouscat.me/api/v2/profile?username=';
const { data } = await got.get(baseURL + user);
return data;
};
module.exports = async (ctx) => {
const { id } = ctx.params;
const user = id;
const data = await fetchAPIByUser(user);
const items = data.posts.map((post) => {
const author = post.senderData.id ? post.senderData.username : 'Anonymous';
const title = `@${author}: ${post.comment}`;
const link = `https://curiouscat.live/${user}/post/${post.id}`;
const media = post.media ? `<img src="${post.media.img}"></img>` : '';
const description = `${post.comment}<br><br>
${post.reply}
${media}
<br>
Likes: ${post.likes}`;
const pubDate = new Date(post.timestamp * 1000);
return {
author,
link,
title,
description,
pubDate,
};
});
ctx.state.data = {
title: `CuriousCat - ${user}`,
link: `https://curiouscat.live/${user}`,
description: `Questions answered by ${user} using CuriousCat`,
language: data.lang,
item: items,
};
};