From c585b050c14a20131fc4ef658ba2fcbe07cd5872 Mon Sep 17 00:00:00 2001 From: SaintShit Date: Fri, 28 Jun 2024 01:41:12 +0330 Subject: [PATCH] feat: custom config for streisand --- .env.example | 1 + app/views/subscription.py | 11 ++++++++++- config.py | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 68c958e4..dfb3faf2 100644 --- a/.env.example +++ b/.env.example @@ -43,6 +43,7 @@ UVICORN_PORT = 8000 ## If USE_CUSTOM_JSON_DEFAULT is set True, all following programs will use the JSON config # USE_CUSTOM_JSON_FOR_V2RAYN=False # USE_CUSTOM_JSON_FOR_V2RAYNG=True +# USE_CUSTOM_JSON_FOR_STREISAND=False ## Set headers for subscription # SUB_PROFILE_TITLE = "Susbcription" diff --git a/app/views/subscription.py b/app/views/subscription.py index 31e021fd..f39e2837 100644 --- a/app/views/subscription.py +++ b/app/views/subscription.py @@ -19,7 +19,8 @@ XRAY_SUBSCRIPTION_PATH, USE_CUSTOM_JSON_DEFAULT, USE_CUSTOM_JSON_FOR_V2RAYN, - USE_CUSTOM_JSON_FOR_V2RAYNG + USE_CUSTOM_JSON_FOR_V2RAYNG, + USE_CUSTOM_JSON_FOR_STREISAND ) @@ -114,6 +115,14 @@ def get_subscription_user_info(user: UserResponse) -> dict: conf = generate_subscription(user=user, config_format="v2ray", as_base64=True) return Response(content=conf, media_type="text/plain", headers=response_headers) + elif re.match('^[Ss]treisand', user_agent): + if USE_CUSTOM_JSON_DEFAULT or USE_CUSTOM_JSON_FOR_STREISAND: + conf = generate_subscription(user=user, config_format="v2ray-json", as_base64=False) + return Response(content=conf, media_type="application/json", headers=response_headers) + else: + conf = generate_subscription(user=user, config_format="v2ray", as_base64=True) + return Response(content=conf, media_type="text/plain", headers=response_headers) + else: conf = generate_subscription(user=user, config_format="v2ray", as_base64=True) return Response(content=conf, media_type="text/plain", headers=response_headers) diff --git a/config.py b/config.py index a75cb230..fa22f994 100755 --- a/config.py +++ b/config.py @@ -54,6 +54,7 @@ USE_CUSTOM_JSON_DEFAULT = config("USE_CUSTOM_JSON_DEFAULT", default=False, cast=bool) 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) ACTIVE_STATUS_TEXT = config("ACTIVE_STATUS_TEXT", default="Active") EXPIRED_STATUS_TEXT = config("EXPIRED_STATUS_TEXT", default="Expired")