fix(route/follow): adapt the list subscription (#16913)
This commit is contained in:
@@ -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<Data> {
|
||||
const uid = ctx.req.param('uid');
|
||||
const host = 'https://api.follow.is';
|
||||
@@ -35,13 +37,23 @@ async function handler(ctx: Context): Promise<Data> {
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
+45
-15
@@ -3,9 +3,28 @@ export interface FollowResponse<T> {
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user