diff --git a/lib/routes/follow/profile.ts b/lib/routes/follow/profile.ts index db86e476b..3dd084590 100644 --- a/lib/routes/follow/profile.ts +++ b/lib/routes/follow/profile.ts @@ -1,7 +1,7 @@ import { ViewType, type Data, type Route } from '@/types'; import type { Context } from 'hono'; import ofetch from '@/utils/ofetch'; -import type { FollowResponse, Profile, Subscription } from './types'; +import type { FollowResponse, ListSubscription, Profile, Subscription } from './types'; import { parse } from 'tldts'; export const route: Route = { @@ -26,6 +26,8 @@ export const route: Route = { view: ViewType.Notifications, }; +const isList = (subscription: Subscription): subscription is ListSubscription => 'lists' in subscription; + async function handler(ctx: Context): Promise { const uid = ctx.req.param('uid'); const host = 'https://api.follow.is'; @@ -35,13 +37,23 @@ async function handler(ctx: Context): Promise { return { title: `${profile.data.name}'s subscriptions`, - item: subscriptions.data.map((subscription) => ({ - title: subscription.feeds.title, - description: subscription.feeds.description, - link: `https://app.follow.is/feed/${subscription.feedId}`, - image: getUrlIcon(subscription.feeds.siteUrl).src, - category: [subscription.category], - })), + item: subscriptions.data.map((subscription) => { + if (isList(subscription)) { + return { + title: subscription.lists.title, + description: subscription.lists.description, + link: `https://app.follow.is/list/${subscription.listId}`, + image: subscription.lists.image, + }; + } + return { + title: subscription.feeds.title, + description: subscription.feeds.description, + link: `https://app.follow.is/feed/${subscription.feedId}`, + image: getUrlIcon(subscription.feeds.siteUrl).src, + category: subscription.category ? [subscription.category] : undefined, + }; + }), link: `https://app.follow.is/profile/${uid}`, image: profile.data.image, }; diff --git a/lib/routes/follow/types.ts b/lib/routes/follow/types.ts index 5fb2ee0be..fc73fef4c 100644 --- a/lib/routes/follow/types.ts +++ b/lib/routes/follow/types.ts @@ -3,9 +3,28 @@ export interface FollowResponse { data: T; } -export interface Subscription { - category: string; +export type Subscription = FeedSubscription | ListSubscription; + +export interface Profile { + id: string; + name: string; + email: string; + emailVerified: unknown; + image: string; + handle: unknown; + createdAt: string; +} + +export interface BaseSubscription { feedId: string; + isPrivate: boolean; + title: string | null; + userId: string; + view: number; +} + +export interface FeedSubscription extends BaseSubscription { + category: string | null; feeds: { checkAt: string; description: string; @@ -18,21 +37,32 @@ export interface Subscription { ownerUserId: string | null; siteUrl: string; title: string; - ttl: number; + type: 'feed'; 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; +export interface ListSubscription extends BaseSubscription { + lastViewedAt: string; + listId: string; + lists: { + description: string; + fee: number; + feedIds: string[]; + id: string; + image: string; + owner: { + createdAt: string; + emailVerified: unknown; + handle: string | null; + id: string; + image: string; + name: string; + }; + ownerUserId: string; + timelineUpdatedAt: string; + title: string; + type: 'list'; + view: number; + }; }