Files
3x-ui-agent/frontend/src/pages/settings/SubscriptionGeneralTab.tsx
T
Muse f887f47bb9 P7: restore agent node type, agent heartbeat expiry, build-version injection, remove log/history/xray-metrics modules, optional sub port
- nodes: port node-type (traditional/agent) picker back from web-src into
  the embedded frontend; backend annotates NodeView.nodeType from
  agent_nodes bindings; fix agent-node update path (skip reachability
  probe and apiToken requirement for agent-managed nodes); restore i18n
  keys in all 13 locales; install command now uses the Gitea mirror
- jobs: expire agent-bound nodes whose agent_nodes.last_seen is older
  than max(3x heartbeat interval, 120s) = 180s; last_seen=0 (never
  registered) is left untouched; transitions reuse UpdateHeartbeat +
  node event broadcast
- config: GetBaseVersion honors ldflags-injected buildVersion; release
  builds inject 3.7.0-agent.1 so the panel no longer reports a phantom
  update against the Gitea release tag
- logger/server: remove the three log viewers (panel/xray/amneziawg),
  their API endpoints and the 10240-entry in-memory log buffer; file
  logging via lumberjack unchanged; tests assert via a new optional
  logger hook instead of the removed buffer
- server: remove system history and xray metrics modules end to end
  (endpoints, sampling appends in RefreshStatus, per-minute persist
  cron, gob snapshot/restore, XrayMetricsService); realtime status and
  per-node history are untouched
- settings: subPort may be 0/unset - subscription links are generated
  without a port while the subscription service keeps binding the
  default 2096; the settings form declares the cleared state via
  onNumber's new onClear option instead of snapping back to 1
2026-10-21 06:44:00 +00:00

416 lines
16 KiB
TypeScript

import { Alert, Button, Input, InputNumber, Switch, Tabs, Tag } from 'antd';
import {
BranchesOutlined,
CompassOutlined,
IdcardOutlined,
InfoCircleOutlined,
NodeIndexOutlined,
SafetyCertificateOutlined,
SettingOutlined,
} from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router';
import type { AllSetting } from '@/models/setting';
import { onNumber } from '@/utils/onNumber';
import { DefaultSettingTag, SettingListItem } from '@/components/ui';
import { RemarkTemplateField } from '@/components/form';
import { useMediaQuery } from '@/hooks/useMediaQuery';
import { catTabLabel } from './catTabLabel';
import { sanitizePath, normalizePath } from './uriPath';
interface SubscriptionGeneralTabProps {
allSetting: AllSetting;
updateSetting: (patch: Partial<AllSetting>) => void;
}
const isRemoteRoutingSource = (value: string) => /^https:\/\/\S+$/i.test(value.trim());
const remoteSourceBadge = (value: string) =>
isRemoteRoutingSource(value) ? <Tag color="blue">HTTPS URL</Tag> : undefined;
export default function SubscriptionGeneralTab({
allSetting,
updateSetting,
}: SubscriptionGeneralTabProps) {
const { t } = useTranslation();
const navigate = useNavigate();
const { isMobile } = useMediaQuery();
return (
<Tabs
defaultActiveKey="1"
items={[
{
key: '1',
label: catTabLabel(<SettingOutlined />, t('pages.settings.panelSettings'), isMobile),
children: (
<>
<SettingListItem
paddings="small"
title={t('pages.settings.subEnable')}
description={t('pages.settings.subEnableDesc')}
>
<Switch
checked={allSetting.subEnable}
onChange={(v) => updateSetting({ subEnable: v })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subJsonEnableTitle')}
description={t('pages.settings.subJsonEnable')}
>
<Switch
checked={allSetting.subJsonEnable}
onChange={(v) => updateSetting({ subJsonEnable: v })}
/>
</SettingListItem>
<SettingListItem paddings="small" title={t('pages.settings.subClashEnableTitle')}>
<Switch
checked={allSetting.subClashEnable}
onChange={(v) => updateSetting({ subClashEnable: v })}
/>
</SettingListItem>
{(allSetting.subJsonEnable || allSetting.subClashEnable) && (
<Alert
type="info"
showIcon
style={{ margin: '12px 20px' }}
title={t('pages.settings.subFormatsTipTitle')}
description={t('pages.settings.subFormatsTipDesc')}
action={
<Button size="small" onClick={() => navigate('/settings#subscription-formats')}>
{t('pages.settings.subFormatsTipAction')}
</Button>
}
/>
)}
<SettingListItem
paddings="small"
title={t('pages.settings.subListen')}
description={t('pages.settings.subListenDesc')}
>
<Input
value={allSetting.subListen}
onChange={(e) => updateSetting({ subListen: e.target.value })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subDomain')}
description={t('pages.settings.subDomainDesc')}
>
<Input
value={allSetting.subDomain}
onChange={(e) => updateSetting({ subDomain: e.target.value })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subPort')}
badge={<DefaultSettingTag settingKey="subPort" value={allSetting.subPort} />}
description={t('pages.settings.subPortDesc')}
>
<InputNumber
value={allSetting.subPort || null}
min={0}
max={65535}
placeholder="2096"
style={{ width: '100%' }}
onChange={onNumber((v) => updateSetting({ subPort: v }), { onClear: 0 })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subPath')}
description={t('pages.settings.subPathDesc')}
>
<Input
value={allSetting.subPath}
placeholder="/sub/"
onChange={(e) => updateSetting({ subPath: sanitizePath(e.target.value) })}
onBlur={() => updateSetting({ subPath: normalizePath(allSetting.subPath) })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subURI')}
description={t('pages.settings.subURIDesc')}
>
<Input
value={allSetting.subURI}
placeholder="(http|https)://domain[:port]/path/"
onChange={(e) => updateSetting({ subURI: e.target.value })}
/>
</SettingListItem>
</>
),
},
{
key: '2',
label: catTabLabel(<InfoCircleOutlined />, t('pages.settings.information'), isMobile),
children: (
<>
<SettingListItem
paddings="small"
title={t('pages.settings.subEncrypt')}
description={t('pages.settings.subEncryptDesc')}
>
<Switch
checked={allSetting.subEncrypt}
onChange={(v) => updateSetting({ subEncrypt: v })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.remarkTemplate')}
description={t('pages.settings.remarkTemplateDesc')}
>
<RemarkTemplateField
value={allSetting.remarkTemplate}
onChange={(v) => updateSetting({ remarkTemplate: v })}
maxLength={256}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subShowIdentityOnAllLinks')}
description={t('pages.settings.subShowIdentityOnAllLinksDesc')}
>
<Switch
checked={allSetting.subShowIdentityOnAllLinks}
onChange={(v) => updateSetting({ subShowIdentityOnAllLinks: v })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subUpdates')}
badge={<DefaultSettingTag settingKey="subUpdates" value={allSetting.subUpdates} />}
description={t('pages.settings.subUpdatesDesc')}
>
<InputNumber
value={allSetting.subUpdates}
min={0}
max={525600}
style={{ width: '100%' }}
onChange={onNumber((v) => updateSetting({ subUpdates: v }))}
/>
</SettingListItem>
</>
),
},
{
key: '3',
label: catTabLabel(<IdcardOutlined />, t('pages.settings.profile'), isMobile),
children: (
<>
<SettingListItem
paddings="small"
title={t('pages.settings.subTitle')}
description={t('pages.settings.subTitleDesc')}
>
<RemarkTemplateField
value={allSetting.subTitle}
onChange={(v) => updateSetting({ subTitle: v })}
metadataOnly
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subSupportUrl')}
description={t('pages.settings.subSupportUrlDesc')}
>
<RemarkTemplateField
value={allSetting.subSupportUrl}
placeholder="https://example.com"
onChange={(v) => updateSetting({ subSupportUrl: v })}
metadataOnly
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subProfileUrl')}
description={t('pages.settings.subProfileUrlDesc')}
>
<RemarkTemplateField
value={allSetting.subProfileUrl}
placeholder="https://example.com"
onChange={(v) => updateSetting({ subProfileUrl: v })}
metadataOnly
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subAnnounce')}
description={t('pages.settings.subAnnounceDesc')}
>
<RemarkTemplateField
value={allSetting.subAnnounce}
onChange={(v) => updateSetting({ subAnnounce: v })}
multiline
rows={3}
metadataOnly
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subThemeDir')}
description={
<>
{t('pages.settings.subThemeDirDesc')}{' '}
<a
href="https://git.881218.xyz/rogue/3x-ui-agent/src/branch/main/docs/custom-subscription-templates.md"
target="_blank"
rel="noopener noreferrer"
>
{t('pages.settings.subThemeDirDocs')}
</a>
</>
}
>
<Input
value={allSetting.subThemeDir}
placeholder="/etc/3x-ui/sub_templates/my-theme/"
onChange={(e) => updateSetting({ subThemeDir: e.target.value })}
/>
</SettingListItem>
</>
),
},
{
key: '4',
label: catTabLabel(<SafetyCertificateOutlined />, t('pages.settings.certs'), isMobile),
children: (
<>
<SettingListItem
paddings="small"
title={t('pages.settings.subCertPath')}
description={t('pages.settings.subCertPathDesc')}
>
<Input
value={allSetting.subCertFile}
onChange={(e) => updateSetting({ subCertFile: e.target.value })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subKeyPath')}
description={t('pages.settings.subKeyPathDesc')}
>
<Input
value={allSetting.subKeyFile}
onChange={(e) => updateSetting({ subKeyFile: e.target.value })}
/>
</SettingListItem>
</>
),
},
{
key: '5',
label: catTabLabel(<BranchesOutlined />, 'Happ', isMobile),
children: (
<>
<SettingListItem
paddings="small"
title={t('pages.settings.subEnableRouting')}
description={t('pages.settings.subEnableRoutingDesc')}
>
<Switch
checked={allSetting.subEnableRouting}
onChange={(v) => updateSetting({ subEnableRouting: v })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subRoutingRules')}
badge={remoteSourceBadge(allSetting.subRoutingRules)}
description={t('pages.settings.subRoutingRulesDesc')}
>
<Input.TextArea
value={allSetting.subRoutingRules}
placeholder="happ://routing/onadd/... or https://.../DEFAULT.DEEPLINK"
onChange={(e) => updateSetting({ subRoutingRules: e.target.value })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subHideSettings')}
description={t('pages.settings.subHideSettingsDesc')}
>
<Switch
checked={allSetting.subHideSettings}
onChange={(v) => updateSetting({ subHideSettings: v })}
/>
</SettingListItem>
</>
),
},
{
key: '6',
label: catTabLabel(<NodeIndexOutlined />, 'Clash / Mihomo', isMobile),
children: (
<>
<SettingListItem
paddings="small"
title={t('pages.settings.subClashEnableRouting')}
description={t('pages.settings.subClashEnableRoutingDesc')}
>
<Switch
checked={allSetting.subClashEnableRouting}
onChange={(v) => updateSetting({ subClashEnableRouting: v })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subClashRoutingRules')}
badge={remoteSourceBadge(allSetting.subClashRules)}
description={t('pages.settings.subClashRoutingRulesDesc')}
>
<Input.TextArea
value={allSetting.subClashRules}
rows={8}
placeholder={
'https://.../routing.yaml\n\nor inline rules:\nGEOSITE,category-ir,DIRECT'
}
onChange={(e) => updateSetting({ subClashRules: e.target.value })}
/>
</SettingListItem>
</>
),
},
{
key: '7',
label: catTabLabel(<CompassOutlined />, 'Incy', isMobile),
children: (
<>
<SettingListItem
paddings="small"
title={t('pages.settings.subIncyEnableRouting')}
description={t('pages.settings.subIncyEnableRoutingDesc')}
>
<Switch
checked={allSetting.subIncyEnableRouting}
onChange={(v) => updateSetting({ subIncyEnableRouting: v })}
/>
</SettingListItem>
<SettingListItem
paddings="small"
title={t('pages.settings.subIncyRoutingRules')}
badge={remoteSourceBadge(allSetting.subIncyRoutingRules)}
description={t('pages.settings.subIncyRoutingRulesDesc')}
>
<Input.TextArea
value={allSetting.subIncyRoutingRules}
placeholder="incy://routing/onadd/... or https://.../DEFAULT.JSON"
onChange={(e) => updateSetting({ subIncyRoutingRules: e.target.value })}
/>
</SettingListItem>
</>
),
},
]}
/>
);
}