Skip to content

Commit

Permalink
fix: prevent duplicated tags in sing-box
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintShit committed Jul 19, 2024
1 parent a6c70f6 commit 2452eb9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/subscription/singbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit 2452eb9

Please sign in to comment.