Skip to content

Commit

Permalink
Optional json sub (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
thenorthatlantic committed May 19, 2024
1 parent a13d8fb commit 43a669c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ UVICORN_PORT = 8000
# SINGBOX_SUBSCRIPTION_TEMPLATE="singbox/default.json"
# MUX_TEMPLATE="mux/default.json"

## Enable JSON support for compatible clients to use mux, fragment, etc. Default is null, meaning false.
# USE_CUSTOM_JSON_DEFAULT="True"

## Set headers for subscription
# SUB_PROFILE_TITLE = "Susbcription"
# SUB_SUPPORT_URL = "https://t.me/support"
Expand Down
5 changes: 3 additions & 2 deletions app/views/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
SUB_SUPPORT_URL,
SUB_UPDATE_INTERVAL,
SUBSCRIPTION_PAGE_TEMPLATE,
XRAY_SUBSCRIPTION_PATH
XRAY_SUBSCRIPTION_PATH,
USE_CUSTOM_JSON_DEFAULT
)


Expand Down Expand Up @@ -93,7 +94,7 @@ def get_subscription_user_info(user: UserResponse) -> dict:

elif re.match('^v2rayNG/(\d+\.\d+\.\d+)', user_agent):
version_str = re.match('^v2rayNG/(\d+\.\d+\.\d+)', user_agent).group(1)
if LooseVersion(version_str) >= LooseVersion("1.8.16"):
if LooseVersion(version_str) >= LooseVersion("1.8.16") and USE_CUSTOM_JSON_DEFAULT:
conf = generate_subscription(user=user, config_format="v2ray-json", as_base64=False)
return Response(content=conf, media_type="application/json", headers=response_headers)
else:
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
SINGBOX_SUBSCRIPTION_TEMPLATE = config("SINGBOX_SUBSCRIPTION_TEMPLATE", default="singbox/default.json")
MUX_TEMPLATE = config("MUX_TEMPLATE", default="mux/default.json")
V2RAY_SUBSCRIPTION_TEMPLATE = config("V2RAY_SUBSCRIPTION_TEMPLATE", default="v2ray/default.json")
USE_CUSTOM_JSON_DEFAULT = config("USE_CUSTOM_JSON_DEFAULT", default="")

ACTIVE_STATUS_TEXT = config("ACTIVE_STATUS_TEXT", default="Active")
EXPIRED_STATUS_TEXT = config("EXPIRED_STATUS_TEXT", default="Expired")
Expand Down

0 comments on commit 43a669c

Please sign in to comment.