Skip to content

Commit bd73122

Browse files
committed
feat: view subscription config in browser when disable_sub_template is enabled
1 parent fc50d4c commit bd73122

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

app/operation/subscription.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def _format_profile_title(
6666
return profile_title
6767

6868
@staticmethod
69-
def create_response_headers(user: UsersResponseWithInbounds, request_url: str, sub_settings: SubSettings) -> dict:
69+
def create_response_headers(
70+
user: UsersResponseWithInbounds, request_url: str, sub_settings: SubSettings, inline: bool = False
71+
) -> dict:
7072
"""Create response headers for subscription responses, including user subscription info."""
7173
# Generate user subscription info
7274
user_info = {"upload": 0, "download": user.used_traffic, "total": 0, "expire": 0}
@@ -84,8 +86,11 @@ def create_response_headers(user: UsersResponseWithInbounds, request_url: str, s
8486
# Prefer admin's support_url over subscription settings
8587
support_url = (getattr(user.admin, "support_url", None) if user.admin else None) or sub_settings.support_url
8688

89+
# Use 'inline' for browser viewing, 'attachment' for download
90+
disposition = "inline" if inline else "attachment"
91+
8792
return {
88-
"content-disposition": f'attachment; filename="{user.username}"',
93+
"content-disposition": f'{disposition}; filename="{user.username}"',
8994
"profile-web-page-url": request_url,
9095
"support-url": support_url,
9196
"profile-title": encode_title(formatted_title),
@@ -140,9 +145,9 @@ async def user_subscription(
140145
db_user = await self.get_validated_sub(db, token)
141146
user = await self.validated_user(db_user)
142147

143-
response_headers = self.create_response_headers(user, request_url, sub_settings)
148+
is_browser_request = "text/html" in accept_header
144149

145-
if not sub_settings.disable_sub_template and "text/html" in accept_header:
150+
if not sub_settings.disable_sub_template and is_browser_request:
146151
template = (
147152
db_user.admin.sub_template
148153
if db_user.admin and db_user.admin.sub_template
@@ -174,6 +179,10 @@ async def user_subscription(
174179
await user_sub_update(db, db_user.id, user_agent)
175180
conf, media_type = await self.fetch_config(user, client_type)
176181

182+
# If disable_sub_template is True and it's a browser request, use inline to view instead of download
183+
inline_view = sub_settings.disable_sub_template and is_browser_request
184+
response_headers = self.create_response_headers(user, request_url, sub_settings, inline=inline_view)
185+
177186
# Create response with appropriate headers
178187
return Response(content=conf, media_type=media_type, headers=response_headers)
179188

0 commit comments

Comments
 (0)