From 2452eb972ea649ec05f594ee03bcd5876368ed86 Mon Sep 17 00:00:00 2001 From: SaintShit Date: Fri, 19 Jul 2024 10:50:15 +0330 Subject: [PATCH] fix: prevent duplicated tags in sing-box --- app/subscription/singbox.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/subscription/singbox.py b/app/subscription/singbox.py index 6035fc59..8fd1808e 100644 --- a/app/subscription/singbox.py +++ b/app/subscription/singbox.py @@ -14,6 +14,7 @@ class SingBoxConfiguration(str): def __init__(self): + self.proxy_remarks = [] template = render_template(SINGBOX_SUBSCRIPTION_TEMPLATE) self.config = json.loads(template) self.mux_template = render_template(MUX_TEMPLATE) @@ -33,6 +34,16 @@ def __init__(self): else: self.grpc_user_agent_data = [] + def _remark_validation(self, remark): + if not remark in self.proxy_remarks: + return remark + c = 2 + while True: + new = f'{remark} ({c})' + if not new in self.proxy_remarks: + return new + c += 1 + def add_outbound(self, outbound_data): self.config["outbounds"].append(outbound_data) @@ -250,6 +261,9 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict): alpn = inbound.get('alpn', None) + remark = self._remark_validation(remark) + self.proxy_remarks.append(remark) + outbound = self.make_outbound( remark=remark, type=inbound['protocol'],