fix(desktop): correct content length for readability content
This commit is contained in:
parent
98ef84b8fa
commit
7235a6d354
|
|
@ -8,21 +8,11 @@ import { useActionLanguage } from "~/atoms/settings/general"
|
|||
import { CopyButton } from "~/components/ui/button/CopyButton"
|
||||
import { Markdown } from "~/components/ui/markdown/Markdown"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { parseHtml } from "~/lib/parse-html"
|
||||
import { Queries } from "~/queries"
|
||||
import type { FlatEntryModel } from "~/store/entry"
|
||||
import { useEntry } from "~/store/entry"
|
||||
|
||||
const entryTextContentLengthSelector = (state: FlatEntryModel) => {
|
||||
const { content } = state.entries
|
||||
if (!content) return 0
|
||||
const text = parseHtml(content).toText()
|
||||
return text.length
|
||||
}
|
||||
|
||||
export function AISummary({ entryId }: { entryId: string }) {
|
||||
const { t } = useTranslation()
|
||||
const entryContentLength = useEntry(entryId, entryTextContentLengthSelector) || 0
|
||||
const summarySetting = useEntry(entryId, (state) => state.settings?.summary)
|
||||
const isInReadabilitySuccess = useEntryIsInReadabilitySuccess(entryId)
|
||||
const showAISummary = useShowAISummary(summarySetting)
|
||||
|
|
@ -43,7 +33,7 @@ export function AISummary({ entryId }: { entryId: string }) {
|
|||
},
|
||||
)
|
||||
|
||||
if (!showAISummary || entryContentLength < 100 || (!summary.isLoading && !summary.data)) {
|
||||
if (!showAISummary || (!summary.isLoading && !summary.data)) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import type { SupportedLanguages } from "@follow/models/types"
|
||||
|
||||
import { getReadabilityContent } from "~/atoms/readability"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { defineQuery } from "~/lib/defineQuery"
|
||||
import { parseHtml } from "~/lib/parse-html"
|
||||
import { translate } from "~/lib/translate"
|
||||
import { getEntry } from "~/store/entry"
|
||||
|
||||
export const ai = {
|
||||
translation: ({
|
||||
|
|
@ -31,6 +34,19 @@ export const ai = {
|
|||
target?: "content" | "readabilityContent"
|
||||
}) =>
|
||||
defineQuery(["summary", entryId, language, target], async () => {
|
||||
const content =
|
||||
target === "readabilityContent"
|
||||
? getReadabilityContent()[entryId]?.content
|
||||
: getEntry(entryId)?.entries.content
|
||||
if (!content) {
|
||||
return
|
||||
}
|
||||
|
||||
const text = parseHtml(content).toText()
|
||||
if (text.length < 100) {
|
||||
return
|
||||
}
|
||||
|
||||
const res = await apiClient.ai.summary.$get({
|
||||
query: {
|
||||
id: entryId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue