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
This commit is contained in:
duqigit authored and GitHub committed 2026-09-03 22:32:05 +02:00 Unverified
1 parent 13e87a18c8
commit 2ddcf53020
16 files changed
+332 -61

No files matched your search

@@ -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 && (
<button
type="button"
className="jdp-clear"
@@ -120,7 +133,7 @@ export default function DateTimePicker({
onMouseDown={(e) => e.preventDefault()}
onClick={(e) => {
e.stopPropagation();
onChange(null);
commitChange(null);
setClearNonce((n) => n + 1);
}}
>
@@ -134,13 +147,15 @@ export default function DateTimePicker({
return (
<DatePicker
value={value}
onChange={(next) => onChange(next || null)}
onCalendarChange={(next) => onChange((Array.isArray(next) ? next[0] : next) || null)}
onChange={(next) => commitChange(next || null)}
onCalendarChange={(next) => commitChange((Array.isArray(next) ? next[0] : next) || null)}
showTime={showTime ? { format: 'HH:mm:ss' } : false}
needConfirm={false}
format={format}
placeholder={placeholder}
disabled={disabled}
allowClear={allowClear}
maxDate={maxDate}
style={{ width: '100%' }}
/>
);
+10
View File
@@ -0,0 +1,10 @@
export function resolveExternalLinkExpiry(
externalExpiry: number | null | undefined,
clientExpiry: number | null | undefined,
): number {
const explicitExpiry = Number(externalExpiry) || 0;
if (explicitExpiry > 0) return explicitExpiry;
const inheritedExpiry = Number(clientExpiry) || 0;
return inheritedExpiry > 0 ? inheritedExpiry : 0;
}
+2 -2
View File
@@ -1118,14 +1118,14 @@ export const sections: readonly Section[] = [
method: 'POST',
path: '/panel/api/clients/:email/externalLinks',
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.",
"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.",
params: [
{ name: 'email', in: 'path', type: 'string', desc: 'Client email (unique identifier).' },
{
name: 'externalLinks',
in: 'body',
type: 'object[]',
desc: '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.',
desc: "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.",
},
],
body: '{\n "externalLinks": [\n { "kind": "link", "value": "vless://uuid@host:443?...#srv", "remark": "DE", "enable": true, "expiryTime": 0 },\n { "kind": "subscription", "value": "https://provider.example/sub/abc", "remark": "Provider", "enable": false, "expiryTime": 1767225600000, "namePrefix": "[zjh] " }\n ]\n}',
Loaded 3 of 16 files, more files were not shown because too many files have changed in this diff. Show more