feat(sub): support dynamic template variables in subscription remarks#5430
Open
wahh3b-lgtm wants to merge 3 commits into
Open
feat(sub): support dynamic template variables in subscription remarks#5430wahh3b-lgtm wants to merge 3 commits into
wahh3b-lgtm wants to merge 3 commits into
Conversation
…ezone-aware inline Jalali conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This Pull Request introduces a dynamic, zero-database-schema client remark templating system for generated subscription and configuration share links.
Currently,
3x-uigenerates configuration remarks statically. This PR implements an opt-in, highly robust pre-processor mapping layer that allows administrators to define dynamic variables inside the InboundRemarkor ClientRemarkfields (e.g.,📊 Left: {DATA_LEFT} of {DATA_LIMIT} | {STATUS_EMOJI}). When a user updates their subscription or copies their link, these variables are dynamically resolved on-the-fly with their real-time bandwidth and expiration statistics.Core Technical Features & Architecture
No database columns were added or modified. The system is entirely backwards-compatible and opt-in. If an inbound or client remark does not contain
{or}characters, the parser safely falls back to standard static naming.Rather than introducing large external calendar libraries to
go.modfor Persian Shamsi date calculations, this PR includes a highly optimized, lightweight inline mathematical Gregorian-to-Jalali conversion utility.Standardized expiration calculations were migrated from UTC to the server's local timezone (
.In(time.Local)) to resolve the off-by-one day error where clients under theAsia/Tehrantimezone (UTC+3:30) would see their expiration day offset incorrectly.All regular expressions are pre-compiled at the package level, and
strings.Builderis used across string formatting paths to minimize heap allocations and avoid garbage collection (GC) pressure under heavy concurrent subscription requests.Built-in character scanning safely handles unclosed braces, non-matching variables, and potential naming collisions on subsequent links (
nameOnlyTemplateverification).Supported Dynamic Variables
Administrators can use the following variables in the Inbound or Client
Remarkfield (excluding{ADMIN_USERNAME}):{USERNAME}Name{DATA_USAGE}8.00 GB{DATA_LEFT}92.00 GB{DATA_LIMIT}100.00 GB{DAYS_LEFT}14{EXPIRE_DATE}2026-06-18{JALALI_EXPIRE_DATE}1405/03/28{TIME_LEFT}14d 6h 30m{STATUS_EMOJI}✅{USAGE_PERCENTAGE}8.0%{PROTOCOL}VLESS{TRANSPORT}xhttpExample Usage
Template:
Resolved Output (active client, 92GB left of 100GB):
Resolved Output (expired client):
Files Modified
internal/sub/remark_vars.gointernal/sub/remark_vars_test.gointernal/sub/service.gointernal/sub/host_sub.gointernal/sub/json_service.gointernal/sub/clash_service.gointernal/sub/endpoint.gointernal/sub/endpoint_test.go.gitignore.mimocodeexclusionTesting & Quality Control
internal/sub/remark_vars_test.goandinternal/sub/endpoint_test.go