diff --git a/apps/renderer/src/modules/rsshub/add-modal-content.tsx b/apps/renderer/src/modules/rsshub/add-modal-content.tsx index 3f76bfd2e..09cd19840 100644 --- a/apps/renderer/src/modules/rsshub/add-modal-content.tsx +++ b/apps/renderer/src/modules/rsshub/add-modal-content.tsx @@ -8,6 +8,7 @@ import { FormMessage, } from "@follow/components/ui/form/index.jsx" import { Input } from "@follow/components/ui/input/Input.js" +import type { RSSHubModel } from "@follow/models" import { zodResolver } from "@hookform/resolvers/zod" import { useEffect } from "react" import { useForm } from "react-hook-form" @@ -17,13 +18,24 @@ import { z } from "zod" import { whoami } from "~/atoms/user" import { ShikiHighLighter } from "~/components/ui/code-highlighter" import { useShikiDefaultTheme } from "~/components/ui/code-highlighter/shiki/hooks" +import { useAuthQuery } from "~/hooks/common" +import { Queries } from "~/queries" import { useAddRSSHubMutation } from "~/queries/rsshub" -export function AddModalContent({ dismiss }: { dismiss: () => void }) { +export function AddModalContent({ + dismiss, + instance, +}: { + dismiss: () => void + instance?: RSSHubModel +}) { const { t } = useTranslation("settings") const addRSSHubMutation = useAddRSSHubMutation() const shikiTheme = useShikiDefaultTheme() const me = whoami() + const details = useAuthQuery(Queries.rsshub.get({ id: instance?.id || "" }), { + enabled: !!instance?.id, + }) const formSchema = z.object({ baseUrl: z.string().url(), @@ -35,7 +47,7 @@ export function AddModalContent({ dismiss }: { dismiss: () => void }) { }) const onSubmit = (data: z.infer) => { - addRSSHubMutation.mutate(data) + addRSSHubMutation.mutate({ ...data, id: instance?.id }) } useEffect(() => { @@ -44,6 +56,15 @@ export function AddModalContent({ dismiss }: { dismiss: () => void }) { } }, [addRSSHubMutation.isSuccess]) + useEffect(() => { + if (details.data?.instance.baseUrl) { + form.reset({ + baseUrl: details.data.instance.baseUrl, + accessKey: details.data.instance.accessKey || undefined, + }) + } + }, [details.data]) + return (
{t("rsshub.addModal.description")}
@@ -52,10 +73,10 @@ export function AddModalContent({ dismiss }: { dismiss: () => void }) { transparent theme={shikiTheme} className="group relative mt-3 cursor-auto select-text whitespace-pre break-words rounded-lg border border-border bg-zinc-100 p-2 text-sm dark:bg-neutral-800 [&_pre]:whitespace-pre [&_pre]:break-words [&_pre]:!p-0" - code={`FOLLOW_OWNER_USER_ID=${me?.handle || me?.id} # User id or handle of your follow account -FOLLOW_DESCRIPTION=${me?.name}'s instance # The description of your instance -FOLLOW_PRICE=0 # The monthly price of your instance, set to 0 means free. -FOLLOW_USER_LIMIT=1000 # The user limit of your instance, set it to 0 or 1 can make your instance private, leaving it empty means no restriction`} + code={`FOLLOW_OWNER_USER_ID=${me?.handle || me?.id} # User id or handle of your follow account +FOLLOW_DESCRIPTION=${instance?.description || `${me?.name}'s instance`} # The description of your instance +FOLLOW_PRICE=${instance?.price || 100} # The monthly price of your instance, set to 0 means free. +FOLLOW_USER_LIMIT=${instance?.userLimit || 1000} # The user limit of your instance, set it to 0 or 1 can make your instance private, leaving it empty means no restriction`} language="dotenv" />
diff --git a/apps/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx b/apps/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx index 33394b93a..aa01d52b6 100644 --- a/apps/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx +++ b/apps/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx @@ -165,7 +165,19 @@ function List({ data }: { data?: RSSHubModel[] }) { )} {me?.id === instance.ownerUserId && ( - + )}
diff --git a/apps/renderer/src/queries/rsshub.ts b/apps/renderer/src/queries/rsshub.ts index 02a108662..31cf73e66 100644 --- a/apps/renderer/src/queries/rsshub.ts +++ b/apps/renderer/src/queries/rsshub.ts @@ -1,4 +1,5 @@ import { useMutation } from "@tanstack/react-query" +import { toast } from "sonner" import { apiClient } from "~/lib/api-fetch" import { defineQuery } from "~/lib/defineQuery" @@ -22,16 +23,26 @@ export const useSetRSSHubMutation = ({ onError }: MutationBaseProps = {}) => onError: (error) => { onError?.(error) + toast.error(error.message) }, }) export const useAddRSSHubMutation = ({ onError }: MutationBaseProps = {}) => useMutation({ - mutationFn: ({ baseUrl, accessKey }: { baseUrl: string; accessKey?: string }) => + mutationFn: ({ + baseUrl, + accessKey, + id, + }: { + baseUrl: string + accessKey?: string + id?: string + }) => apiClient.rsshub.$post({ json: { baseUrl, accessKey, + id, }, }), @@ -42,6 +53,7 @@ export const useAddRSSHubMutation = ({ onError }: MutationBaseProps = {}) => onError: (error) => { onError?.(error) + toast.error(error.message) }, }) @@ -51,6 +63,7 @@ export const useDeleteRSSHubMutation = ({ onError }: MutationBaseProps = {}) => onError: (error) => { onError?.(error) + toast.error(error.message) }, }) diff --git a/locales/errors/en.json b/locales/errors/en.json index a0d9c57d8..639270d48 100644 --- a/locales/errors/en.json +++ b/locales/errors/en.json @@ -57,5 +57,6 @@ "11003": "RSSHub not found", "11004": "RSSHub user limit exceeded", "11005": "RSSHub purchase not found", + "11006": "RSSHub config invalid", "12000": "Action limit exceeded" } diff --git a/packages/shared/src/hono.ts b/packages/shared/src/hono.ts index 69fc94e24..98b5c9378 100644 --- a/packages/shared/src/hono.ts +++ b/packages/shared/src/hono.ts @@ -12654,6 +12654,7 @@ declare const _routes: hono_hono_base.HonoBase