Skip to content

Commit c772b91

Browse files
committed
feat: rsshub list check purchased instance
1 parent 5252f97 commit c772b91

File tree

5 files changed

+59
-33
lines changed

5 files changed

+59
-33
lines changed

apps/renderer/src/pages/(main)/(layer)/(subview)/rsshub/index.tsx

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,24 @@ function List({ data }: { data?: RSSHubModel[] }) {
143143
<TableCell>{instance.userLimit || t("rsshub.table.unlimited")}</TableCell>
144144
<TableCell>
145145
<div className="flex items-center gap-2">
146-
{status?.data?.usage?.rsshubId === instance.id && (
147-
<Button disabled className="shrink-0">
148-
{t("rsshub.table.inuse")}
149-
</Button>
150-
)}
151-
{status?.data?.usage?.rsshubId !== instance.id && (
152-
<Button
153-
onClick={() => {
154-
present({
155-
title: t("rsshub.useModal.title"),
156-
content: ({ dismiss }) => (
157-
<SetModalContent dismiss={dismiss} instance={instance} />
158-
),
159-
})
160-
}}
161-
>
162-
{t("rsshub.table.use")}
163-
</Button>
164-
)}
146+
<Button
147+
className="shrink-0"
148+
variant={status?.data?.usage?.rsshubId === instance.id ? "outline" : "primary"}
149+
onClick={() => {
150+
present({
151+
title: t("rsshub.useModal.title"),
152+
content: ({ dismiss }) => (
153+
<SetModalContent dismiss={dismiss} instance={instance} />
154+
),
155+
})
156+
}}
157+
>
158+
{t(
159+
status?.data?.usage?.rsshubId === instance.id
160+
? "rsshub.table.inuse"
161+
: "rsshub.table.use",
162+
)}
163+
</Button>
165164
{me?.id === instance.ownerUserId && (
166165
<Button variant="outline">{t("rsshub.table.edit")}</Button>
167166
)}
@@ -175,18 +174,23 @@ function List({ data }: { data?: RSSHubModel[] }) {
175174
)
176175
}
177176

178-
const formSchema = z.object({
179-
months: z.coerce.number().min(1).max(12),
180-
})
181-
182177
const SetModalContent = ({ dismiss, instance }: { dismiss: () => void; instance: RSSHubModel }) => {
183178
const { t } = useTranslation("settings")
184179
const setRSSHubMutation = useSetRSSHubMutation()
180+
const details = useAuthQuery(Queries.rsshub.get({ id: instance.id }))
181+
const hasPurchase = !!details.data?.purchase
182+
183+
const formSchema = z.object({
184+
months: z.coerce
185+
.number()
186+
.min(hasPurchase ? 0 : 1)
187+
.max(12),
188+
})
185189

186190
const form = useForm<z.infer<typeof formSchema>>({
187191
resolver: zodResolver(formSchema),
188192
defaultValues: {
189-
months: 1,
193+
months: hasPurchase ? 0 : 1,
190194
},
191195
})
192196

@@ -235,6 +239,16 @@ const SetModalContent = ({ dismiss, instance }: { dismiss: () => void; instance:
235239
</div>
236240
</CardContent>
237241
</Card>
242+
{details.data?.purchase && (
243+
<div>
244+
<div className="text-sm text-muted-foreground">
245+
{t("rsshub.useModal.purchase_expires_at")}
246+
</div>
247+
<div className="line-clamp-2">
248+
{new Date(details.data.purchase.expiresAt).toLocaleString()}
249+
</div>
250+
</div>
251+
)}
238252
<Form {...form}>
239253
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
240254
{instance.price > 0 && (
@@ -247,7 +261,7 @@ const SetModalContent = ({ dismiss, instance }: { dismiss: () => void; instance:
247261
<FormControl>
248262
<div className="flex items-center gap-10">
249263
<div className="space-x-2">
250-
<Input className="w-24" type="number" max={12} min={1} {...field} />
264+
<Input className="w-24" type="number" max={12} {...field} />
251265
<span className="text-sm text-muted-foreground">
252266
{t("rsshub.useModal.month")}
253267
</span>

apps/renderer/src/queries/rsshub.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ export const useSetRSSHubMutation = ({ onError }: MutationBaseProps = {}) =>
1111
mutationFn: (data: { id: string | null; durationInMonths?: number }) =>
1212
apiClient.rsshub.use.$post({ json: data }),
1313

14-
onSuccess: () => {
14+
onSuccess: (_, variables) => {
1515
rsshub.list().invalidate()
1616
rsshub.status().invalidate()
17+
18+
if (variables.id) {
19+
rsshub.get({ id: variables.id }).invalidate()
20+
}
1721
},
1822

1923
onError: (error) => {

locales/errors/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
"11002": "RSSHub is in use",
5757
"11003": "RSSHub not found",
5858
"11004": "RSSHub user limit exceeded",
59+
"11005": "RSSHub purchase not found",
5960
"12000": "Action limit exceeded"
6061
}

locales/settings/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
"rsshub.useModal.about": "About this Instance",
292292
"rsshub.useModal.month": "month",
293293
"rsshub.useModal.months_label": "The number of months you want to purchase",
294+
"rsshub.useModal.purchase_expires_at": "You have purchased this Instance, and your purchase expires at",
294295
"rsshub.useModal.title": "RSSHub Instance",
295296
"rsshub.useModal.useWith": "Use with {{amount}} Power",
296297
"titles.about": "About",

packages/shared/src/hono.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12726,13 +12726,19 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
1272612726
output: {
1272712727
code: 0;
1272812728
data: {
12729-
description: string | null;
12730-
id: string;
12731-
ownerUserId: string;
12732-
baseUrl: string;
12733-
accessKey: string | null;
12734-
price: number;
12735-
userLimit: number | null;
12729+
purchase: {
12730+
hash: string | null;
12731+
expiresAt: string;
12732+
} | null;
12733+
instance: {
12734+
description: string | null;
12735+
id: string;
12736+
ownerUserId: string;
12737+
price: number;
12738+
userLimit: number | null;
12739+
baseUrl?: string | null | undefined;
12740+
accessKey?: string | null | undefined;
12741+
};
1273612742
};
1273712743
};
1273812744
outputFormat: "json";

0 commit comments

Comments
 (0)