[PR #6517] [MERGED] feat(sub): add opt-in month-end expiry presentation #6324

Closed
opened 2026-11-02 04:07:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6517
Author: @JacktheRanger
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/14/2026
Merged by: @MHSanaei

Base: main ← Head: codex/calendar-expiry-presentation


📝 Commits (1)

  • c0982be feat(sub): add opt-in month-end expiry presentation

📊 Changes

32 files changed (+412 additions, -8 deletions)

View changed files

📝 docs/content/docs/en/config/subscription.mdx (+25 -0)
📝 docs/public/openapi.json (+8 -0)
📝 frontend/public/openapi.json (+8 -0)
📝 frontend/src/generated/examples.ts (+2 -0)
📝 frontend/src/generated/schemas.ts (+8 -0)
📝 frontend/src/generated/types.ts (+2 -0)
📝 frontend/src/generated/zod.ts (+2 -0)
📝 frontend/src/models/setting.ts (+1 -0)
📝 frontend/src/pages/settings/SubscriptionGeneralTab.tsx (+11 -0)
📝 frontend/src/schemas/setting.ts (+1 -0)
➕ frontend/src/test/calendar-expire-setting.test.tsx (+27 -0)
➕ internal/sub/calendar_expire.go (+21 -0)
➕ internal/sub/calendar_expire_test.go (+241 -0)
📝 internal/sub/clash_service.go (+1 -1)
📝 internal/sub/controller.go (+1 -1)
📝 internal/sub/json_service.go (+1 -1)
📝 internal/sub/service.go (+20 -5)
📝 internal/web/entity/entity.go (+1 -0)
📝 internal/web/service/setting.go (+5 -0)
📝 internal/web/translation/ar-EG.json (+2 -0)

...and 12 more files

📄 Description

Motivation and research

Refs #6516. Presentation-only follow-up to #6300 and #6457; the calendar-renewal/accounting fix is not changed.

For AWS/Azure-style monthly allowances, the real cutoff remains the first of the following month at midnight, but an operator may want an existing subscription client's native expiry date to show the last valid day of the current month.

Clash Verge Rev's official header documentation describes expiry-card metadata from Subscription-Userinfo. Its native card implementation formats that timestamp as a date. Adding a remark variable alone cannot change that native field.

This PR is a draft for maintainer agreement on the explicit, opt-in compatibility tradeoff. The default continues reporting the exact cutoff.

User-facing behavior

Add Subscription → Information → Month-end subscription expiry display (subCalendarExpireInclusive, default false).

When enabled, report expire = cutoff - 1 second only if:

  • All traffic-contributing clients renew on calendar day 1.
  • They share the same positive, fixed expiry.
  • That expiry is exactly day 1 at midnight in the configured panel timezone, and the immediately preceding second belongs to the previous month.

Example in the same timezone: stored cutoff 2030-10-01 00:00:00 → subscription header 2030-09-30 23:59:59.

The last condition excludes a later repeated midnight during a DST rollback. Other renewal days, fixed-day interval mode, arbitrary/non-midnight times, fractional-midnight timestamps, legacy 23:59:59 inputs, first-use durations, unlimited expiries, mixed modes, and differing cutoffs retain existing output.

Raw/Base64, JSON, Clash/Mihomo, explicit Mihomo, and legacy Clash endpoints share the same formatter. The next subscription request reads a changed setting; clients still need to refresh cached metadata.

Implementation scope

  • One shared subscription-header formatter; it derives the presentation timestamp without mutating traffic.
  • Carry the common renewal day through the existing traffic aggregation, using the clients table's calendar setting when available, including node snapshots with missing limits. Existing usage/limit aggregation is preserved.
  • Persist the opt-in bool in the existing settings key/value table; no database columns or migrations.
  • Add the UI switch, frontend schema/model, regenerated settings types/examples/Zod/OpenAPI, and matching docs OpenAPI snapshot.
  • Document the feature and caveats. All 13 locales have the new keys; English and both Chinese locales have localized text, with English text supplied in the remaining locales.

Stored expiry, real access cutoff, calendar renewal, renewal allowances, traffic counters, Xray configuration, existing expiry remark variables, and HTML/format=info page cutoff remain unchanged.

Validation

Environment: macOS arm64, Go 1.27.1, Node 24.19.0, golangci-lint 2.13.2.

  • go test ./internal/sub -run '^TestSubscriptionCalendarExpireInclusive' -count=1 — passed. Real database + HTTP coverage across all five format routes; month lengths/leap year; UTC/Taipei/New York; Havana repeated midnight; fractional/arbitrary/legacy expiries; authoritative client renewal mode; mixed identities/cutoffs; settings save/read/on-off round trip; first-use normalization; canonical info cutoff and unchanged scheduling/accounting.
  • go test -race -shuffle=on -count=1 ./internal/sub -run '^TestSubscriptionCalendarExpireInclusive' — passed.
  • cd frontend && npm test -- --project components src/test/calendar-expire-setting.test.tsx — passed in a standalone run (one new case); checks default-off UI and the exact update payload.
  • STORYBOOK_DISABLE_TELEMETRY=1 make verify — passed: codegen freshness, Go/frontend lint, frontend formatting/typecheck/MSW worker consistency, shuffled uncached Go suite, frontend unit/component/Chromium Storybook tests (150 files / 1,487 tests), production frontend + Go builds, and static Storybook build.
  • cd docs && pnpm gen:api — regenerated successfully; API MDX unchanged.
  • cd docs && pnpm typecheck, pnpm lint, pnpm test — passed (12 test files / 106 tests).
  • git diff --check — passed.

Red/green checks: the enabled month-end and all-calendar aggregate cases failed against unchanged production code before implementation. The later Havana midnight case failed without the previous-month guard and passed with it. The new UI case failed before the switch was added.

Not verified: importing into a running third-party client, live Xray/multi-node enforcement, live PostgreSQL, or the entire repository's race/vulnerability/fuzz gates. The default Go suite can skip environment-gated tests; no live compatibility claim is made.

Compatibility, privacy, and intentional exclusions

Enabling the option changes header semantics deliberately: apps receive the last-valid instant one second before the actual cutoff, and apps that treat metadata as a deadline may consider it expired one second early. Apps may format timestamps in their own timezone; a matching panel/client timezone is necessary for the same month-end date. The UI help and docs state these limitations.

Disabled remains the existing byte-for-byte header format/value. No credentials, subscription identities, extra user data, telemetry, or new network requests are added by this feature.

This does not add VALID_THROUGH_* remark variables or change panel/info cutoff presentation, does not force client timezone/formatting, and does not refund renewal counts already consumed by the old bug. Those are separate from the native expiry-header goal.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6517 **Author:** [@JacktheRanger](https://github.com/JacktheRanger) **Created:** 9/14/2026 **Status:** ✅ Merged **Merged:** 9/14/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `codex/calendar-expiry-presentation` --- ### 📝 Commits (1) - [`c0982be`](https://github.com/MHSanaei/3x-ui/commit/c0982be142d6699ece92581e4a86353ed5e6d870) feat(sub): add opt-in month-end expiry presentation ### 📊 Changes **32 files changed** (+412 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/config/subscription.mdx` (+25 -0) 📝 `docs/public/openapi.json` (+8 -0) 📝 `frontend/public/openapi.json` (+8 -0) 📝 `frontend/src/generated/examples.ts` (+2 -0) 📝 `frontend/src/generated/schemas.ts` (+8 -0) 📝 `frontend/src/generated/types.ts` (+2 -0) 📝 `frontend/src/generated/zod.ts` (+2 -0) 📝 `frontend/src/models/setting.ts` (+1 -0) 📝 `frontend/src/pages/settings/SubscriptionGeneralTab.tsx` (+11 -0) 📝 `frontend/src/schemas/setting.ts` (+1 -0) ➕ `frontend/src/test/calendar-expire-setting.test.tsx` (+27 -0) ➕ `internal/sub/calendar_expire.go` (+21 -0) ➕ `internal/sub/calendar_expire_test.go` (+241 -0) 📝 `internal/sub/clash_service.go` (+1 -1) 📝 `internal/sub/controller.go` (+1 -1) 📝 `internal/sub/json_service.go` (+1 -1) 📝 `internal/sub/service.go` (+20 -5) 📝 `internal/web/entity/entity.go` (+1 -0) 📝 `internal/web/service/setting.go` (+5 -0) 📝 `internal/web/translation/ar-EG.json` (+2 -0) _...and 12 more files_ </details> ### 📄 Description ## Motivation and research Refs #6516. Presentation-only follow-up to #6300 and #6457; the calendar-renewal/accounting fix is not changed. For AWS/Azure-style monthly allowances, the real cutoff remains the first of the following month at midnight, but an operator may want an existing subscription client's native expiry date to show the last valid day of the current month. [Clash Verge Rev's official header documentation](https://www.clashverge.dev/guide/url_schemes.html) describes expiry-card metadata from `Subscription-Userinfo`. Its [native card implementation](https://github.com/clash-verge-rev/clash-verge-rev/blob/f32fd0eaa9115b8546ba26995fbfce0b79fa5bde/src/components/profile/profile-item.tsx#L973-L975) formats that timestamp as a date. Adding a remark variable alone cannot change that native field. This PR is a draft for maintainer agreement on the explicit, opt-in compatibility tradeoff. The default continues reporting the exact cutoff. ## User-facing behavior Add **Subscription → Information → Month-end subscription expiry display** (`subCalendarExpireInclusive`, default `false`). When enabled, report `expire = cutoff - 1 second` only if: - All traffic-contributing clients renew on calendar day `1`. - They share the same positive, fixed expiry. - That expiry is exactly day `1` at midnight in the configured panel timezone, and the immediately preceding second belongs to the previous month. Example in the same timezone: stored cutoff `2030-10-01 00:00:00` → subscription header `2030-09-30 23:59:59`. The last condition excludes a later repeated midnight during a DST rollback. Other renewal days, fixed-day interval mode, arbitrary/non-midnight times, fractional-midnight timestamps, legacy `23:59:59` inputs, first-use durations, unlimited expiries, mixed modes, and differing cutoffs retain existing output. Raw/Base64, JSON, Clash/Mihomo, explicit Mihomo, and legacy Clash endpoints share the same formatter. The next subscription request reads a changed setting; clients still need to refresh cached metadata. ## Implementation scope - One shared subscription-header formatter; it derives the presentation timestamp without mutating traffic. - Carry the common renewal day through the existing traffic aggregation, using the clients table's calendar setting when available, including node snapshots with missing limits. Existing usage/limit aggregation is preserved. - Persist the opt-in bool in the existing settings key/value table; no database columns or migrations. - Add the UI switch, frontend schema/model, regenerated settings types/examples/Zod/OpenAPI, and matching docs OpenAPI snapshot. - Document the feature and caveats. All 13 locales have the new keys; English and both Chinese locales have localized text, with English text supplied in the remaining locales. Stored expiry, real access cutoff, calendar renewal, renewal allowances, traffic counters, Xray configuration, existing expiry remark variables, and HTML/`format=info` page cutoff remain unchanged. ## Validation Environment: macOS arm64, Go 1.27.1, Node 24.19.0, golangci-lint 2.13.2. - `go test ./internal/sub -run '^TestSubscriptionCalendarExpireInclusive' -count=1` — passed. Real database + HTTP coverage across all five format routes; month lengths/leap year; UTC/Taipei/New York; Havana repeated midnight; fractional/arbitrary/legacy expiries; authoritative client renewal mode; mixed identities/cutoffs; settings save/read/on-off round trip; first-use normalization; canonical info cutoff and unchanged scheduling/accounting. - `go test -race -shuffle=on -count=1 ./internal/sub -run '^TestSubscriptionCalendarExpireInclusive'` — passed. - `cd frontend && npm test -- --project components src/test/calendar-expire-setting.test.tsx` — passed in a standalone run (one new case); checks default-off UI and the exact update payload. - `STORYBOOK_DISABLE_TELEMETRY=1 make verify` — passed: codegen freshness, Go/frontend lint, frontend formatting/typecheck/MSW worker consistency, shuffled uncached Go suite, frontend unit/component/Chromium Storybook tests (150 files / 1,487 tests), production frontend + Go builds, and static Storybook build. - `cd docs && pnpm gen:api` — regenerated successfully; API MDX unchanged. - `cd docs && pnpm typecheck`, `pnpm lint`, `pnpm test` — passed (12 test files / 106 tests). - `git diff --check` — passed. Red/green checks: the enabled month-end and all-calendar aggregate cases failed against unchanged production code before implementation. The later Havana midnight case failed without the previous-month guard and passed with it. The new UI case failed before the switch was added. Not verified: importing into a running third-party client, live Xray/multi-node enforcement, live PostgreSQL, or the entire repository's race/vulnerability/fuzz gates. The default Go suite can skip environment-gated tests; no live compatibility claim is made. ## Compatibility, privacy, and intentional exclusions Enabling the option changes header semantics deliberately: apps receive the last-valid instant one second before the actual cutoff, and apps that treat metadata as a deadline may consider it expired one second early. Apps may format timestamps in their own timezone; a matching panel/client timezone is necessary for the same month-end date. The UI help and docs state these limitations. Disabled remains the existing byte-for-byte header format/value. No credentials, subscription identities, extra user data, telemetry, or new network requests are added by this feature. This does not add `VALID_THROUGH_*` remark variables or change panel/info cutoff presentation, does not force client timezone/formatting, and does not refund renewal counts already consumed by the old bug. Those are separate from the native expiry-header goal. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:57 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6324
No description provided.