Files
RSSHub/lib/routes/voronoiapp/author.ts
T
CesaryuanandTony f9e891b360 feat(route): add voronoiapp (#16790)
* feat(route): add voronoiapp

* refactor: validate logic

* refactor: validate logic

* refactor: add validation for missing username in author route

* fix: route title

* refactor: update common route properties in voronoiapp routes

* refactor: rename base.ts

* refactor: change categories to picture and set view to Pictures

* refactor: add CommonDataProperties

* Update maintainers name's spell

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Fix voronoiapp/search.ts radar's return url

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Fix post's link

Thanks @TonyRL. In Which Nation is the Most Happy? from /voronoiapp/author/visualcapitalist, post.category is joined by - though a space still work.

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Remove reduntant username check code

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

---------
2024-09-25 10:42:15 +08:00

42 lines
1.4 KiB
TypeScript

import type { Data, Route } from '@/types';
import { CommonDataProperties, CommonRouteProperties, getPostItems } from './common';
import ofetch from '@/utils/ofetch';
import cache from '@/utils/cache';
export const route: Route = {
...CommonRouteProperties,
name: 'Author Posts',
path: '/author/:username',
radar: [
{
source: ['www.voronoiapp.com/author/:username'],
target: '/author/:username',
},
],
example: '/voronoiapp/author/visualcapitalist',
parameters: {
username: 'The username of the author',
},
handler: async (ctx) => {
const { username } = ctx.req.param();
const uid = await getUidFromUsername(username);
const items = await getPostItems({ order: 'DESC', author: uid });
return {
...CommonDataProperties,
title: `Voronoi Posts by ${username}`,
link: `https://www.voronoiapp.com/author/${username}`,
item: items,
} as Data;
},
};
async function getUidFromUsername(username: string): Promise<string> {
return (await cache.tryGet(`voronoiapp-author-${username}`, async () => {
const response = await ofetch<'text'>(`https://www.voronoiapp.com/author/${username}`);
const match = response.match(/\\"uid\\":\\"([\w-]+)\\"/);
if (!match) {
throw new Error(`No UID found for username: ${username}`);
}
return match[1];
})) as string;
}