Skip to content

Commit fc50d4c

Browse files
committed
feat: add disable subscription template feature
- Introduced a new boolean field `disable_sub_template` in the Subscription model to control the rendering of subscription templates. - Updated the SubscriptionOperation to conditionally render HTML based on the new field. - Added localization support for the new feature in English, Persian, Russian, and Chinese. - Enhanced the subscription settings UI to include a toggle for disabling the subscription template. These changes provide users with more control over the subscription experience by allowing API responses instead of HTML pages when the template is disabled.
1 parent d92204a commit fc50d4c

File tree

8 files changed

+41
-5
lines changed

8 files changed

+41
-5
lines changed

app/models/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class Subscription(BaseModel):
263263
manual_sub_request: SubFormatEnable = Field(default_factory=SubFormatEnable)
264264
applications: list[Application] = Field(default_factory=list)
265265
allow_browser_config: bool = Field(default=True)
266+
disable_sub_template: bool = Field(default=False)
266267

267268
@field_validator("applications")
268269
@classmethod

app/operation/subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async def user_subscription(
142142

143143
response_headers = self.create_response_headers(user, request_url, sub_settings)
144144

145-
if "text/html" in accept_header:
145+
if not sub_settings.disable_sub_template and "text/html" in accept_header:
146146
template = (
147147
db_user.admin.sub_template
148148
if db_user.admin and db_user.admin.sub_template

dashboard/public/statics/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@
212212
"announceUrlPlaceholder": "https://status.example.com",
213213
"announceUrlDescription": "Optional link with more information about the announcement",
214214
"allowBrowserConfig": "Show Links in Subscription Page",
215-
"allowBrowserConfigDescription": "Display subscription links on the subscription page template when accessed via browser"
215+
"allowBrowserConfigDescription": "Display subscription links on the subscription page template when accessed via browser",
216+
"disableSubTemplate": "Disable Subscription Template",
217+
"disableSubTemplateDescription": "When disabled, browser requests will return API responses instead of HTML subscription pages"
216218
},
217219
"rules": {
218220
"title": "Subscription Rules",

dashboard/public/statics/locales/fa.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@
119119
"announceUrlPlaceholder": "https://status.example.com",
120120
"announceUrlDescription": "لینک اختیاری برای جزئیات بیشتر اطلاعیه",
121121
"allowBrowserConfig": "نمایش لینک‌ها در صفحه اشتراک",
122-
"allowBrowserConfigDescription": "نمایش لینک‌های اشتراک در قالب صفحه اشتراک هنگام دسترسی از طریق مرورگر"
122+
"allowBrowserConfigDescription": "نمایش لینک‌های اشتراک در قالب صفحه اشتراک هنگام دسترسی از طریق مرورگر",
123+
"disableSubTemplate": "غیرفعال کردن قالب اشتراک",
124+
"disableSubTemplateDescription": "هنگام غیرفعال بودن، درخواست‌های مرورگر به جای صفحات HTML اشتراک، پاسخ‌های API برمی‌گردانند"
123125
},
124126
"rules": {
125127
"title": "قوانین اشتراک",

dashboard/public/statics/locales/ru.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@
226226
"announceUrlPlaceholder": "https://status.example.com",
227227
"announceUrlDescription": "Необязательная ссылка с дополнительной информацией об объявлении",
228228
"allowBrowserConfig": "Показывать ссылки на странице подписки",
229-
"allowBrowserConfigDescription": "Отображать ссылки подписки в шаблоне страницы подписки при доступе через браузер"
229+
"allowBrowserConfigDescription": "Отображать ссылки подписки в шаблоне страницы подписки при доступе через браузер",
230+
"disableSubTemplate": "Отключить шаблон подписки",
231+
"disableSubTemplateDescription": "При отключении запросы браузера будут возвращать ответы API вместо HTML-страниц подписки"
230232
},
231233
"rules": {
232234
"title": "Правила подписки",

dashboard/public/statics/locales/zh.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@
192192
"announceUrlPlaceholder": "https://status.example.com",
193193
"announceUrlDescription": "可选的链接,用于提供更多公告细节",
194194
"allowBrowserConfig": "在订阅页面显示链接",
195-
"allowBrowserConfigDescription": "当通过浏览器访问时,在订阅页面模板中显示订阅链接"
195+
"allowBrowserConfigDescription": "当通过浏览器访问时,在订阅页面模板中显示订阅链接",
196+
"disableSubTemplate": "禁用订阅模板",
197+
"disableSubTemplateDescription": "禁用后,浏览器请求将返回 API 响应而不是 HTML 订阅页面"
196198
},
197199
"rules": {
198200
"title": "订阅规则",

dashboard/src/pages/_dashboard.settings.subscriptions.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const subscriptionSchema = z.object({
3232
announce: z.string().max(128, 'Announcement must be 128 characters or less').optional(),
3333
announce_url: z.string().url('Please enter a valid URL').optional().or(z.literal('')),
3434
allow_browser_config: z.boolean().optional(),
35+
disable_sub_template: z.boolean().optional(),
3536
rules: z.array(
3637
z.object({
3738
pattern: z.string().min(1, 'Pattern is required'),
@@ -450,6 +451,7 @@ export default function SubscriptionSettings() {
450451
announce: '',
451452
announce_url: '',
452453
allow_browser_config: true,
454+
disable_sub_template: false,
453455
rules: [],
454456
applications: [],
455457
manual_sub_request: {
@@ -537,6 +539,7 @@ export default function SubscriptionSettings() {
537539
announce: subscriptionData.announce || '',
538540
announce_url: subscriptionData.announce_url || '',
539541
allow_browser_config: subscriptionData.allow_browser_config ?? true,
542+
disable_sub_template: subscriptionData.disable_sub_template ?? false,
540543
rules: subscriptionData.rules || [],
541544
applications: subscriptionData.applications || [],
542545
manual_sub_request: {
@@ -671,6 +674,7 @@ export default function SubscriptionSettings() {
671674
announce: subscriptionData.announce || '',
672675
announce_url: subscriptionData.announce_url || '',
673676
allow_browser_config: subscriptionData.allow_browser_config ?? true,
677+
disable_sub_template: subscriptionData.disable_sub_template ?? false,
674678
rules: subscriptionData.rules || [],
675679
applications: subscriptionData.applications || [],
676680
manual_sub_request: {
@@ -991,6 +995,27 @@ export default function SubscriptionSettings() {
991995
</FormItem>
992996
)}
993997
/>
998+
999+
<FormField
1000+
control={form.control}
1001+
name="disable_sub_template"
1002+
render={({ field }) => (
1003+
<FormItem className="flex items-center justify-between space-y-0 rounded-lg border bg-card p-3 transition-colors hover:bg-accent/50 sm:p-4 lg:col-span-2">
1004+
<div className="flex-1 space-y-0.5 pr-4">
1005+
<FormLabel className="flex cursor-pointer items-center gap-2 text-sm font-medium">
1006+
<FileCode2 className="h-4 w-4 shrink-0" />
1007+
<span className="break-words">{t('settings.subscriptions.general.disableSubTemplate')}</span>
1008+
</FormLabel>
1009+
<FormDescription className="text-xs leading-relaxed text-muted-foreground sm:leading-normal">
1010+
{t('settings.subscriptions.general.disableSubTemplateDescription')}
1011+
</FormDescription>
1012+
</div>
1013+
<FormControl>
1014+
<Switch checked={field.value} onCheckedChange={field.onChange} className="shrink-0" />
1015+
</FormControl>
1016+
</FormItem>
1017+
)}
1018+
/>
9941019
</div>
9951020
</div>
9961021

dashboard/src/service/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ export interface SubscriptionOutput {
914914
manual_sub_request?: SubFormatEnable
915915
applications?: ApplicationOutput[]
916916
allow_browser_config?: boolean
917+
disable_sub_template?: boolean
917918
}
918919

919920
export interface SubscriptionInput {
@@ -928,6 +929,7 @@ export interface SubscriptionInput {
928929
manual_sub_request?: SubFormatEnable
929930
applications?: ApplicationInput[]
930931
allow_browser_config?: boolean
932+
disable_sub_template?: boolean
931933
}
932934

933935
export type SingBoxMuxSettingsBrutal = Brutal | null

0 commit comments

Comments
 (0)