forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
97 lines (85 loc) · 3.12 KB
/
Copy pathindex.tsx
File metadata and controls
97 lines (85 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import { SettingsPage } from '../components/settings-page'
import type { ContentSettings, SystemOption } from '../types'
import {
CONTENT_DEFAULT_SECTION,
getContentSectionContent,
getContentSectionMeta,
} from './section-registry.tsx'
const defaultContentSettings: ContentSettings = {
'console_setting.api_info': '[]',
'console_setting.announcements': '[]',
'console_setting.faq': '[]',
'console_setting.uptime_kuma_groups': '[]',
'console_setting.api_info_enabled': true,
'console_setting.announcements_enabled': true,
'console_setting.faq_enabled': true,
'console_setting.uptime_kuma_enabled': false,
DataExportEnabled: false,
DataExportDefaultTime: 'hour',
DataExportInterval: 5,
Chats: '[]',
DrawingEnabled: false,
MjNotifyEnabled: false,
MjAccountFilterEnabled: false,
MjForwardUrlEnabled: false,
MjModeClearEnabled: false,
MjActionCheckSuccessEnabled: false,
}
function resolveContentSettings(
settings: ContentSettings,
raw: SystemOption[] | undefined
): ContentSettings {
if (!raw || raw.length === 0) return settings
const optionMap = new Map(raw.map((item) => [item.key, item.value]))
const next = { ...settings }
const legacyMap = [
{ current: 'console_setting.announcements', legacy: 'Announcements' },
{ current: 'console_setting.api_info', legacy: 'ApiInfo' },
{ current: 'console_setting.faq', legacy: 'FAQ' },
] as const
for (const { current, legacy } of legacyMap) {
if (!optionMap.has(current)) {
const legacyValue = optionMap.get(legacy)
if (legacyValue !== undefined) {
next[current] = legacyValue
}
}
}
if (!optionMap.has('console_setting.uptime_kuma_groups')) {
const legacyUrl = optionMap.get('UptimeKumaUrl')
const legacySlug = optionMap.get('UptimeKumaSlug')
if (legacyUrl && legacySlug) {
next['console_setting.uptime_kuma_groups'] = JSON.stringify([
{ id: 1, categoryName: 'Legacy', url: legacyUrl, slug: legacySlug },
])
}
}
return next
}
export function ContentSettings() {
return (
<SettingsPage
routePath='/_authenticated/system-settings/content/$section'
defaultSettings={defaultContentSettings}
defaultSection={CONTENT_DEFAULT_SECTION}
getSectionContent={getContentSectionContent}
getSectionMeta={getContentSectionMeta}
loadingMessage='Loading content settings...'
resolveSettings={resolveContentSettings}
/>
)
}