Skip to content

Commit

Permalink
feat: apply ai summary
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jun 14, 2024
1 parent c0c2513 commit 6eab583
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 62 deletions.
132 changes: 74 additions & 58 deletions src/renderer/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
status: 200;
};
};
"/ai/summary": {
$get: {
input: {
query: {
id: string;
language?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
};
};
output: {
code: 0;
data?: string | undefined;
};
outputFormat: "json";
status: 200;
};
};
} & {
"/actions": {
$get: {
Expand All @@ -107,7 +123,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
name: string;
condition: {
value: string;
field: "title" | "site_url" | "view" | "feed_url";
field: "view" | "title" | "site_url" | "feed_url";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[];
result: {
Expand All @@ -119,7 +135,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
}[] | undefined;
blockRules?: {
value: string | number;
field: "link" | "title" | "all" | "content" | "author" | "order";
field: "title" | "all" | "content" | "author" | "link" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
};
Expand All @@ -136,7 +152,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
name: string;
condition: {
value: string;
field: "title" | "site_url" | "view" | "feed_url";
field: "view" | "title" | "site_url" | "feed_url";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[];
result: {
Expand All @@ -148,7 +164,7 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
}[] | undefined;
blockRules?: {
value: string | number;
field: "link" | "title" | "all" | "content" | "author" | "order";
field: "title" | "all" | "content" | "author" | "link" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
};
Expand Down Expand Up @@ -315,10 +331,10 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
checkedAt: string;
nextCheckAt: string;
id?: string | undefined;
image?: string | null | undefined;
title?: string | null | undefined;
description?: string | null | undefined;
siteUrl?: string | null | undefined;
image?: string | null | undefined;
lastModifiedHeader?: string | null | undefined;
etagHeader?: string | null | undefined;
ttl?: number | null | undefined;
Expand All @@ -328,9 +344,9 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
subscriptionCount: number;
readCount: number;
subscription?: {
title: string | null;
userId: string;
view: number;
title: string | null;
feedId: string;
category: string | null;
isPrivate: boolean | null;
Expand Down Expand Up @@ -369,11 +385,11 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
data: {
feed: {
id: string;
url: string;
image: string | null;
title: string | null;
description: string | null;
url: string;
siteUrl: string | null;
image: string | null;
checkedAt: string;
nextCheckAt: string;
lastModifiedHeader: string | null;
Expand All @@ -384,12 +400,12 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
entries?: {
id: string;
url: string | null;
title: string | null;
description: string | null;
content: string | null;
author: string | null;
description: string | null;
feedId: string;
url: string | null;
guid: string;
authorUrl: string | null;
authorAvatar: string | null;
Expand All @@ -399,8 +415,8 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[] | null;
enclosures?: {
url: string;
length?: number | undefined;
title?: string | undefined;
length?: number | undefined;
type?: string | undefined;
}[] | null | undefined;
}[] | undefined;
Expand Down Expand Up @@ -472,27 +488,12 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
code: 0;
total: number;
data?: {
feeds: {
id: string;
url: string;
title: string | null;
description: string | null;
siteUrl: string | null;
image: string | null;
checkedAt: string;
nextCheckAt: string;
lastModifiedHeader: string | null;
etagHeader: string | null;
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
};
entries: {
id: string;
url: string | null;
title: string | null;
description: string | null;
author: string | null;
description: string | null;
url: string | null;
guid: string;
authorUrl: string | null;
authorAvatar: string | null;
Expand All @@ -502,11 +503,26 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[] | null;
enclosures?: {
url: string;
length?: number | undefined;
title?: string | undefined;
length?: number | undefined;
type?: string | undefined;
}[] | null | undefined;
};
feeds: {
id: string;
image: string | null;
title: string | null;
description: string | null;
url: string;
siteUrl: string | null;
checkedAt: string;
nextCheckAt: string;
lastModifiedHeader: string | null;
etagHeader: string | null;
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
};
read: boolean | null;
collections?: {
createdAt: string;
Expand All @@ -533,28 +549,13 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
output: {
code: 0;
data?: {
feeds: {
id: string;
url: string;
title: string | null;
description: string | null;
siteUrl: string | null;
image: string | null;
checkedAt: string;
nextCheckAt: string;
lastModifiedHeader: string | null;
etagHeader: string | null;
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
};
entries: {
id: string;
url: string | null;
title: string | null;
description: string | null;
content: string | null;
author: string | null;
description: string | null;
url: string | null;
guid: string;
authorUrl: string | null;
authorAvatar: string | null;
Expand All @@ -564,14 +565,29 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[] | null;
enclosures?: {
url: string;
length?: number | undefined;
title?: string | undefined;
length?: number | undefined;
type?: string | undefined;
}[] | null | undefined;
};
collections: {
createdAt: string;
};
feeds: {
id: string;
image: string | null;
title: string | null;
description: string | null;
url: string;
siteUrl: string | null;
checkedAt: string;
nextCheckAt: string;
lastModifiedHeader: string | null;
etagHeader: string | null;
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
};
read: boolean | null;
settings?: {
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
Expand All @@ -597,12 +613,12 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
output: {
data: {
id: string;
url: string | null;
title: string | null;
description: string | null;
content: string | null;
author: string | null;
description: string | null;
feedId: string;
url: string | null;
guid: string;
authorUrl: string | null;
authorAvatar: string | null;
Expand All @@ -612,8 +628,8 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[] | null;
enclosures?: {
url: string;
length?: number | undefined;
title?: string | undefined;
length?: number | undefined;
type?: string | undefined;
}[] | null | undefined;
}[];
Expand All @@ -633,13 +649,17 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
};
output: {
data: {
userId: string;
view: number;
title: string | null;
feedId: string;
feeds: {
id: string;
url: string;
image: string | null;
title: string | null;
description: string | null;
url: string;
siteUrl: string | null;
image: string | null;
checkedAt: string;
nextCheckAt: string;
lastModifiedHeader: string | null;
Expand All @@ -648,10 +668,6 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
errorMessage: string | null;
errorAt: string | null;
};
title: string | null;
userId: string;
view: number;
feedId: string;
category: string | null;
isPrivate: boolean | null;
}[];
Expand All @@ -663,8 +679,8 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
$post: {
input: {
json: {
url: string;
view: number;
url: string;
category?: string | null | undefined;
isPrivate?: boolean | null | undefined;
};
Expand All @@ -678,8 +694,8 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
$delete: {
input: {
json: {
url?: string | undefined;
feedId?: string | undefined;
url?: string | undefined;
};
};
output: {
Expand Down
26 changes: 23 additions & 3 deletions src/renderer/src/modules/entry-content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ function EntryContentRender({ entryId }: { entryId: string }) {
},
)

const summary = useBizQuery(
Queries.ai.summary({
entryId,
language: entry?.settings?.translation,
}),
{
enabled: !!entry?.settings?.summary,
},
)

if (!entry) return null

return (
Expand All @@ -77,7 +87,7 @@ function EntryContentRender({ entryId }: { entryId: string }) {
<a
href={entry.entries.url || void 0}
target="_blank"
className="-mx-6 block rounded-md p-6 transition-colors hover:bg-theme-item-hover"
className="-mx-6 block rounded-lg p-6 transition-colors hover:bg-theme-item-hover"
rel="noreferrer"
>
<div className="select-text break-words text-3xl font-bold">
Expand All @@ -94,7 +104,6 @@ function EntryContentRender({ entryId }: { entryId: string }) {
new Date(entry.entries.publishedAt).toUTCString()}
</div>
</a>

{!content && (
<div className="center mt-16">
{!error ? (
Expand All @@ -107,7 +116,18 @@ function EntryContentRender({ entryId }: { entryId: string }) {
)}
</div>
)}
<div className="prose prose-zinc mx-auto mb-32 mt-10 max-w-full cursor-auto select-text break-all text-[15px] dark:prose-invert">
<div className="prose prose-zinc mx-auto mb-32 mt-8 max-w-full cursor-auto select-text break-all text-[15px] dark:prose-invert">
{(summary.isLoading || summary.data) && (
<div className="my-8 space-y-1 rounded-lg border px-4 py-3">
<div className="flex items-center gap-2 font-medium text-zinc-800">
<i className="i-mingcute-bling-line align-middle" />
<span>AI summary</span>
</div>
<div className="text-sm leading-relaxed">
{summary.isLoading ? "Loading..." : summary.data}
</div>
</div>
)}
{content}
</div>
</article>
Expand Down
Loading

0 comments on commit 6eab583

Please sign in to comment.