From c772b911aaf10bf9158cb55ca49dfffdff4cf6d8 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 30 Dec 2024 22:31:17 +0800 Subject: [PATCH] feat: rsshub list check purchased instance --- .../(main)/(layer)/(subview)/rsshub/index.tsx | 64 +++++++++++-------- apps/renderer/src/queries/rsshub.ts | 6 +- locales/errors/en.json | 1 + locales/settings/en.json | 1 + packages/shared/src/hono.ts | 20 ++++-- 5 files changed, 59 insertions(+), 33 deletions(-) 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 89ebdddef3..46246f5f50 100644 --- a/apps/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx +++ b/apps/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx @@ -143,25 +143,24 @@ function List({ data }: { data?: RSSHubModel[] }) { {instance.userLimit || t("rsshub.table.unlimited")}
- {status?.data?.usage?.rsshubId === instance.id && ( - - )} - {status?.data?.usage?.rsshubId !== instance.id && ( - - )} + {me?.id === instance.ownerUserId && ( )} @@ -175,18 +174,23 @@ function List({ data }: { data?: RSSHubModel[] }) { ) } -const formSchema = z.object({ - months: z.coerce.number().min(1).max(12), -}) - const SetModalContent = ({ dismiss, instance }: { dismiss: () => void; instance: RSSHubModel }) => { const { t } = useTranslation("settings") const setRSSHubMutation = useSetRSSHubMutation() + const details = useAuthQuery(Queries.rsshub.get({ id: instance.id })) + const hasPurchase = !!details.data?.purchase + + const formSchema = z.object({ + months: z.coerce + .number() + .min(hasPurchase ? 0 : 1) + .max(12), + }) const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { - months: 1, + months: hasPurchase ? 0 : 1, }, }) @@ -235,6 +239,16 @@ const SetModalContent = ({ dismiss, instance }: { dismiss: () => void; instance:
+ {details.data?.purchase && ( +
+
+ {t("rsshub.useModal.purchase_expires_at")} +
+
+ {new Date(details.data.purchase.expiresAt).toLocaleString()} +
+
+ )}
{instance.price > 0 && ( @@ -247,7 +261,7 @@ const SetModalContent = ({ dismiss, instance }: { dismiss: () => void; instance:
- + {t("rsshub.useModal.month")} diff --git a/apps/renderer/src/queries/rsshub.ts b/apps/renderer/src/queries/rsshub.ts index 27c986c4ec..50d71eeb71 100644 --- a/apps/renderer/src/queries/rsshub.ts +++ b/apps/renderer/src/queries/rsshub.ts @@ -11,9 +11,13 @@ export const useSetRSSHubMutation = ({ onError }: MutationBaseProps = {}) => mutationFn: (data: { id: string | null; durationInMonths?: number }) => apiClient.rsshub.use.$post({ json: data }), - onSuccess: () => { + onSuccess: (_, variables) => { rsshub.list().invalidate() rsshub.status().invalidate() + + if (variables.id) { + rsshub.get({ id: variables.id }).invalidate() + } }, onError: (error) => { diff --git a/locales/errors/en.json b/locales/errors/en.json index 88659a0019..a0d9c57d81 100644 --- a/locales/errors/en.json +++ b/locales/errors/en.json @@ -56,5 +56,6 @@ "11002": "RSSHub is in use", "11003": "RSSHub not found", "11004": "RSSHub user limit exceeded", + "11005": "RSSHub purchase not found", "12000": "Action limit exceeded" } diff --git a/locales/settings/en.json b/locales/settings/en.json index 97aa26cab5..cc53c8f45b 100644 --- a/locales/settings/en.json +++ b/locales/settings/en.json @@ -291,6 +291,7 @@ "rsshub.useModal.about": "About this Instance", "rsshub.useModal.month": "month", "rsshub.useModal.months_label": "The number of months you want to purchase", + "rsshub.useModal.purchase_expires_at": "You have purchased this Instance, and your purchase expires at", "rsshub.useModal.title": "RSSHub Instance", "rsshub.useModal.useWith": "Use with {{amount}} Power", "titles.about": "About", diff --git a/packages/shared/src/hono.ts b/packages/shared/src/hono.ts index 979236e6b5..8ac0e080c6 100644 --- a/packages/shared/src/hono.ts +++ b/packages/shared/src/hono.ts @@ -12726,13 +12726,19 @@ declare const _routes: hono_hono_base.HonoBase