Skip to content

Commit

Permalink
feat(route): follow (DIYgod#16683)
Browse files Browse the repository at this point in the history
* feat(route): follow

* add link

* use profile instead of subscriptions

* change the feed title
  • Loading branch information
KarasuShin committed Sep 10, 2024
1 parent 69745ad commit 7a18fb2
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/routes/follow/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Follow',
url: 'app.follow.is',
};
38 changes: 38 additions & 0 deletions lib/routes/follow/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Data, Route } from '@/types';
import { Context } from 'hono';
import ofetch from '@/utils/ofetch';
import type { FollowResponse, Profile, Subscription } from './types';

export const route: Route = {
name: 'User subscriptions',
path: '/profile/:uid',
example: '/profile/41279032429549568',
radar: [
{
source: ['app.follow.is/profile/:uid'],
target: '/follow/profile/:uid',
},
],
handler,
maintainers: ['KarasuShin'],
features: {
supportRadar: true,
},
};

async function handler(ctx: Context): Promise<Data> {
const uid = ctx.req.param('uid');
const host = 'https://api.follow.is';

const [profile, subscriptions] = await Promise.all([ofetch<FollowResponse<Profile>>(`${host}/profiles?id=${uid}`), ofetch<FollowResponse<Subscription[]>>(`${host}/subscriptions?userId=${uid}`)]);

return {
title: `${profile.data.name} - User subscriptions`,
item: subscriptions.data.map((subscription) => ({
title: subscription.feeds.title,
description: subscription.feeds.description,
link: `https://app.follow.is/feed/${subscription.feedId}`,
})),
link: `https://app.follow.is/profile/${uid}`,
};
}
38 changes: 38 additions & 0 deletions lib/routes/follow/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export interface FollowResponse<T> {
code: number;
data: T;
}

export interface Subscription {
category: string;
feedId: string;
feeds: {
checkAt: string;
description: string;
errorAt: unknown;
errorMessage: unknown;
etagHeader: string;
id: string;
image: unknown;
lastModifiedHeader: string;
ownerUserId: string | null;
siteUrl: string;
title: string;
ttl: number;
url: string;
};
isPrivate: boolean;
title: string | null;
userId: string;
view: number;
}

export interface Profile {
id: string;
name: string;
email: string;
emailVerified: unknown;
image: string;
handle: unknown;
createdAt: string;
}

0 comments on commit 7a18fb2

Please sign in to comment.