From 2ddcf5302077efb59d7b8a074dce23d53a429ecc Mon Sep 17 00:00:00 2001 From: duqigit <916475145@qq.com> Date: Fri, 4 Sep 2026 04:32:05 +0800 Subject: [PATCH] Feature/fix external subscription client expiry (#6333) * fix(sub): honor client expiry for external links * fix(ui): show client expiry on external links * fix(sub): address external expiry review --- .../content/docs/en/reference/api/clients.mdx | 14 ++- docs/public/openapi.json | 4 +- frontend/public/openapi.json | 4 +- .../src/components/form/DateTimePicker.tsx | 27 +++- frontend/src/lib/clients/external-link.ts | 10 ++ frontend/src/pages/api-docs/endpoints.ts | 4 +- .../src/pages/clients/ClientFormModal.tsx | 55 +++++---- .../test/client-external-link-expiry.test.ts | 17 +++ frontend/src/test/date-time-picker.test.tsx | 55 ++++++++- internal/sub/clash_service.go | 17 ++- internal/sub/controller.go | 8 +- internal/sub/external_config.go | 11 +- internal/sub/inactive_external_sub_test.go | 115 ++++++++++++++++++ internal/sub/json_service.go | 13 +- internal/sub/mutation_audit_test.go | 32 ++++- internal/sub/service.go | 7 ++ 16 files changed, 332 insertions(+), 61 deletions(-) create mode 100644 frontend/src/lib/clients/external-link.ts create mode 100644 frontend/src/test/client-external-link-expiry.test.ts create mode 100644 internal/sub/inactive_external_sub_test.go diff --git a/docs/content/docs/en/reference/api/clients.mdx b/docs/content/docs/en/reference/api/clients.mdx index 77bd6c1f7..bcdc48019 100644 --- a/docs/content/docs/en/reference/api/clients.mdx +++ b/docs/content/docs/en/reference/api/clients.mdx @@ -56,8 +56,11 @@ _openapi: - depth: 2 title: Replace a client's external links and external subscriptions. Sends the full set; the server replaces all rows. Disabled rows stay saved for - editing but are not emitted in generated subscriptions. - url: '#replace-a-clients-external-links-and-external-subscriptions-sends-the-full-set-the-server-replaces-all-rows-disabled-rows-stay-saved-for-editing-but-are-not-emitted-in-generated-subscriptions' + editing but are not emitted in generated subscriptions. The owning + client's disabled or expired state also stops these rows from being + emitted on future subscription fetches; credentials already imported by + an app remain valid until the external provider revokes them. + url: '#replace-a-clients-external-links-and-external-subscriptions-sends-the-full-set-the-server-replaces-all-rows-disabled-rows-stay-saved-for-editing-but-are-not-emitted-in-generated-subscriptions-the-owning-clients-disabled-or-expired-state-also-stops-these-rows-from-being-emitted-on-future-subscription-fetches-credentials-already-imported-by-an-app-remain-valid-until-the-external-provider-revokes-them' - depth: 2 title: Reset the up/down counters for every client globally. Quotas and expiry are not affected. Triggers an Xray restart if any counter actually @@ -318,8 +321,11 @@ _openapi: id: detach-a-client-from-one-or-more-inbounds-without-deleting-the-client - content: Replace a client's external links and external subscriptions. Sends the full set; the server replaces all rows. Disabled rows stay saved for - editing but are not emitted in generated subscriptions. - id: replace-a-clients-external-links-and-external-subscriptions-sends-the-full-set-the-server-replaces-all-rows-disabled-rows-stay-saved-for-editing-but-are-not-emitted-in-generated-subscriptions + editing but are not emitted in generated subscriptions. The owning + client's disabled or expired state also stops these rows from being + emitted on future subscription fetches; credentials already imported + by an app remain valid until the external provider revokes them. + id: replace-a-clients-external-links-and-external-subscriptions-sends-the-full-set-the-server-replaces-all-rows-disabled-rows-stay-saved-for-editing-but-are-not-emitted-in-generated-subscriptions-the-owning-clients-disabled-or-expired-state-also-stops-these-rows-from-being-emitted-on-future-subscription-fetches-credentials-already-imported-by-an-app-remain-valid-until-the-external-provider-revokes-them - content: Reset the up/down counters for every client globally. Quotas and expiry are not affected. Triggers an Xray restart if any counter actually moved. diff --git a/docs/public/openapi.json b/docs/public/openapi.json index 0f9b1e4a6..fda39b8b4 100644 --- a/docs/public/openapi.json +++ b/docs/public/openapi.json @@ -7290,7 +7290,7 @@ "tags": [ "Clients" ], - "summary": "Replace a client's external links and external subscriptions. Sends the full set; the server replaces all rows. Disabled rows stay saved for editing but are not emitted in generated subscriptions.", + "summary": "Replace a client's external links and external subscriptions. Sends the full set; the server replaces all rows. Disabled rows stay saved for editing but are not emitted in generated subscriptions. The owning client's disabled or expired state also stops these rows from being emitted on future subscription fetches; credentials already imported by an app remain valid until the external provider revokes them.", "operationId": "post_panel_api_clients_email_externalLinks", "parameters": [ { @@ -7315,7 +7315,7 @@ "items": { "type": "object" }, - "description": "Full replacement list; the server replaces all rows. Each row supports { kind, value, remark, enable, expiryTime, namePrefix }. kind=link: value must be a supported share link such as vless://, vmess://, trojan://, ss://, hysteria2://, or wireguard://, and remark overrides the exported node name. kind=subscription: value must be an http(s) subscription URL, and namePrefix is prepended to fetched node names. Omit enable to default true; enable=false or an expired expiryTime keeps the row saved but excludes it from generated subscriptions. expiryTime is a unix millisecond timestamp where 0 means never expire; a negative value is rejected. Rows are matched by kind+value across saves, so id is ignored on write. lastFetchAt and lastFetchError are read-only status fields returned by GET." + "description": "Full replacement list; the server replaces all rows. Each row supports { kind, value, remark, enable, expiryTime, namePrefix }. kind=link: value must be a supported share link such as vless://, vmess://, trojan://, ss://, hysteria2://, or wireguard://, and remark overrides the exported node name. kind=subscription: value must be an http(s) subscription URL, and namePrefix is prepended to fetched node names. Omit enable to default true; enable=false or an expired expiryTime keeps the row saved but excludes it from generated subscriptions. expiryTime is a unix millisecond timestamp where 0 means no link-specific expiry; the owning client's enabled state and expiry still apply. A negative value is rejected. Rows are matched by kind+value across saves, so id is ignored on write. lastFetchAt and lastFetchError are read-only status fields returned by GET." } }, "required": [ diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json index 0f9b1e4a6..fda39b8b4 100644 --- a/frontend/public/openapi.json +++ b/frontend/public/openapi.json @@ -7290,7 +7290,7 @@ "tags": [ "Clients" ], - "summary": "Replace a client's external links and external subscriptions. Sends the full set; the server replaces all rows. Disabled rows stay saved for editing but are not emitted in generated subscriptions.", + "summary": "Replace a client's external links and external subscriptions. Sends the full set; the server replaces all rows. Disabled rows stay saved for editing but are not emitted in generated subscriptions. The owning client's disabled or expired state also stops these rows from being emitted on future subscription fetches; credentials already imported by an app remain valid until the external provider revokes them.", "operationId": "post_panel_api_clients_email_externalLinks", "parameters": [ { @@ -7315,7 +7315,7 @@ "items": { "type": "object" }, - "description": "Full replacement list; the server replaces all rows. Each row supports { kind, value, remark, enable, expiryTime, namePrefix }. kind=link: value must be a supported share link such as vless://, vmess://, trojan://, ss://, hysteria2://, or wireguard://, and remark overrides the exported node name. kind=subscription: value must be an http(s) subscription URL, and namePrefix is prepended to fetched node names. Omit enable to default true; enable=false or an expired expiryTime keeps the row saved but excludes it from generated subscriptions. expiryTime is a unix millisecond timestamp where 0 means never expire; a negative value is rejected. Rows are matched by kind+value across saves, so id is ignored on write. lastFetchAt and lastFetchError are read-only status fields returned by GET." + "description": "Full replacement list; the server replaces all rows. Each row supports { kind, value, remark, enable, expiryTime, namePrefix }. kind=link: value must be a supported share link such as vless://, vmess://, trojan://, ss://, hysteria2://, or wireguard://, and remark overrides the exported node name. kind=subscription: value must be an http(s) subscription URL, and namePrefix is prepended to fetched node names. Omit enable to default true; enable=false or an expired expiryTime keeps the row saved but excludes it from generated subscriptions. expiryTime is a unix millisecond timestamp where 0 means no link-specific expiry; the owning client's enabled state and expiry still apply. A negative value is rejected. Rows are matched by kind+value across saves, so id is ignored on write. lastFetchAt and lastFetchError are read-only status fields returned by GET." } }, "required": [ diff --git a/frontend/src/components/form/DateTimePicker.tsx b/frontend/src/components/form/DateTimePicker.tsx index 805147b76..aa30aaf9b 100644 --- a/frontend/src/components/form/DateTimePicker.tsx +++ b/frontend/src/components/form/DateTimePicker.tsx @@ -17,6 +17,8 @@ interface DateTimePickerProps { format?: string; placeholder?: string; disabled?: boolean; + allowClear?: boolean; + maxDate?: Dayjs; } const LIGHT_THEME = { @@ -53,6 +55,8 @@ export default function DateTimePicker({ format = 'YYYY-MM-DD HH:mm:ss', placeholder = '', disabled = false, + allowClear = true, + maxDate, }: DateTimePickerProps) { const { t } = useTranslation(); const { datepicker } = useDatepicker(); @@ -78,6 +82,14 @@ export default function DateTimePicker({ return LIGHT_THEME; }, [isDark, isUltra]); + const commitChange = (next: Dayjs | null) => { + if (next && maxDate && next.isAfter(maxDate)) { + if (datepicker === 'jalalian') setClearNonce((n) => n + 1); + return; + } + onChange(next); + }; + // The library hardcodes a Persian placeholder and exposes no working prop to // override it, so clear it (or apply the caller's) on the input directly so // the empty field shows no leftover Persian text. No dep array: re-apply @@ -100,19 +112,20 @@ export default function DateTimePicker({ onChange={(next: number | string | null) => { if (suppressMountEmit.current) return; if (next == null || next === '') { - onChange(null); + commitChange(null); return; } const ms = typeof next === 'number' ? next : Number(next); - if (Number.isFinite(ms)) onChange(dayjs(ms)); + if (Number.isFinite(ms)) commitChange(dayjs(ms)); }} showTime={showTime} outputFormat="timestamp" + maxDate={maxDate?.toDate()} persianNumbers rtlCalendar theme={persianTheme} /> - {value && !disabled && ( + {value && allowClear && !disabled && (