From ff663266bed0c8fe5ecc9c9d5bd8e543bd74245d Mon Sep 17 00:00:00 2001 From: Nikita Korotaev <104270279+iambabyninja@users.noreply.github.com> Date: Sun, 29 Dec 2024 23:08:47 +0500 Subject: [PATCH] add HAPP proxy app custom json (#1549) --- .env.example | 1 + app/routers/subscription.py | 12 ++++++++++++ config.py | 1 + 3 files changed, 14 insertions(+) diff --git a/.env.example b/.env.example index 82264d8b5..0dcdcc2dc 100644 --- a/.env.example +++ b/.env.example @@ -51,6 +51,7 @@ UVICORN_PORT = 8000 # USE_CUSTOM_JSON_FOR_V2RAYN=False # USE_CUSTOM_JSON_FOR_V2RAYNG=True # USE_CUSTOM_JSON_FOR_STREISAND=False +# USE_CUSTOM_JSON_FOR_HAPP=False ## Set headers for subscription # SUB_PROFILE_TITLE = "Susbcription" diff --git a/app/routers/subscription.py b/app/routers/subscription.py index 46d940837..a75525209 100644 --- a/app/routers/subscription.py +++ b/app/routers/subscription.py @@ -15,6 +15,7 @@ SUB_UPDATE_INTERVAL, SUBSCRIPTION_PAGE_TEMPLATE, USE_CUSTOM_JSON_DEFAULT, + USE_CUSTOM_JSON_FOR_HAPP, USE_CUSTOM_JSON_FOR_STREISAND, USE_CUSTOM_JSON_FOR_V2RAYN, USE_CUSTOM_JSON_FOR_V2RAYNG, @@ -122,6 +123,17 @@ def user_subscription( conf = generate_subscription(user=user, config_format="v2ray", as_base64=True, reverse=False) return Response(content=conf, media_type="text/plain", headers=response_headers) + elif (USE_CUSTOM_JSON_DEFAULT or USE_CUSTOM_JSON_FOR_HAPP) and re.match(r'^Happ/(\d+\.\d+\.\d+)', user_agent): + version_str = re.match(r'^Happ/(\d+\.\d+\.\d+)', user_agent).group(1) + if LooseVersion(version_str) >= LooseVersion("1.63.1"): + conf = generate_subscription(user=user, config_format="v2ray-json", as_base64=False, reverse=False) + return Response(content=conf, media_type="application/json", headers=response_headers) + else: + conf = generate_subscription(user=user, config_format="v2ray", as_base64=True, reverse=False) + return Response(content=conf, media_type="text/plain", headers=response_headers) + + + else: conf = generate_subscription(user=user, config_format="v2ray", as_base64=True, reverse=False) return Response(content=conf, media_type="text/plain", headers=response_headers) diff --git a/config.py b/config.py index 92ecfea18..e3981adda 100755 --- a/config.py +++ b/config.py @@ -73,6 +73,7 @@ USE_CUSTOM_JSON_FOR_V2RAYN = config("USE_CUSTOM_JSON_FOR_V2RAYN", default=False, cast=bool) USE_CUSTOM_JSON_FOR_V2RAYNG = config("USE_CUSTOM_JSON_FOR_V2RAYNG", default=False, cast=bool) USE_CUSTOM_JSON_FOR_STREISAND = config("USE_CUSTOM_JSON_FOR_STREISAND", default=False, cast=bool) +USE_CUSTOM_JSON_FOR_HAPP = config("USE_CUSTOM_JSON_FOR_HAPP", default=False, cast=bool) NOTIFY_STATUS_CHANGE = config("NOTIFY_STATUS_CHANGE", default=True, cast=bool) NOTIFY_USER_CREATED = config("NOTIFY_USER_CREATED", default=True, cast=bool)