mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-20 23:28:38 +00:00
fix: fix model deployment style issues, lint problems, and i18n gaps. (#2556)
* fix: fix model deployment style issues, lint problems, and i18n gaps. * fix: adjust the key not to be displayed on the frontend, tested via the backend. * fix: adjust the sidebar configuration logic to use the default configuration items if they are not defined.
This commit is contained in:
@@ -25,6 +25,56 @@ import { API } from '../../helpers';
|
||||
const sidebarEventTarget = new EventTarget();
|
||||
const SIDEBAR_REFRESH_EVENT = 'sidebar-refresh';
|
||||
|
||||
export const DEFAULT_ADMIN_CONFIG = {
|
||||
chat: {
|
||||
enabled: true,
|
||||
playground: true,
|
||||
chat: true,
|
||||
},
|
||||
console: {
|
||||
enabled: true,
|
||||
detail: true,
|
||||
token: true,
|
||||
log: true,
|
||||
midjourney: true,
|
||||
task: true,
|
||||
},
|
||||
personal: {
|
||||
enabled: true,
|
||||
topup: true,
|
||||
personal: true,
|
||||
},
|
||||
admin: {
|
||||
enabled: true,
|
||||
channel: true,
|
||||
models: true,
|
||||
deployment: true,
|
||||
redemption: true,
|
||||
user: true,
|
||||
setting: true,
|
||||
},
|
||||
};
|
||||
|
||||
const deepClone = (value) => JSON.parse(JSON.stringify(value));
|
||||
|
||||
export const mergeAdminConfig = (savedConfig) => {
|
||||
const merged = deepClone(DEFAULT_ADMIN_CONFIG);
|
||||
if (!savedConfig || typeof savedConfig !== 'object') return merged;
|
||||
|
||||
for (const [sectionKey, sectionConfig] of Object.entries(savedConfig)) {
|
||||
if (!sectionConfig || typeof sectionConfig !== 'object') continue;
|
||||
|
||||
if (!merged[sectionKey]) {
|
||||
merged[sectionKey] = { ...sectionConfig };
|
||||
continue;
|
||||
}
|
||||
|
||||
merged[sectionKey] = { ...merged[sectionKey], ...sectionConfig };
|
||||
}
|
||||
|
||||
return merged;
|
||||
};
|
||||
|
||||
export const useSidebar = () => {
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const [userConfig, setUserConfig] = useState(null);
|
||||
@@ -37,48 +87,17 @@ export const useSidebar = () => {
|
||||
instanceIdRef.current = `sidebar-${Date.now()}-${randomPart}`;
|
||||
}
|
||||
|
||||
// 默认配置
|
||||
const defaultAdminConfig = {
|
||||
chat: {
|
||||
enabled: true,
|
||||
playground: true,
|
||||
chat: true,
|
||||
},
|
||||
console: {
|
||||
enabled: true,
|
||||
detail: true,
|
||||
token: true,
|
||||
log: true,
|
||||
midjourney: true,
|
||||
task: true,
|
||||
},
|
||||
personal: {
|
||||
enabled: true,
|
||||
topup: true,
|
||||
personal: true,
|
||||
},
|
||||
admin: {
|
||||
enabled: true,
|
||||
channel: true,
|
||||
models: true,
|
||||
deployment: true,
|
||||
redemption: true,
|
||||
user: true,
|
||||
setting: true,
|
||||
},
|
||||
};
|
||||
|
||||
// 获取管理员配置
|
||||
const adminConfig = useMemo(() => {
|
||||
if (statusState?.status?.SidebarModulesAdmin) {
|
||||
try {
|
||||
const config = JSON.parse(statusState.status.SidebarModulesAdmin);
|
||||
return config;
|
||||
return mergeAdminConfig(config);
|
||||
} catch (error) {
|
||||
return defaultAdminConfig;
|
||||
return mergeAdminConfig(null);
|
||||
}
|
||||
}
|
||||
return defaultAdminConfig;
|
||||
return mergeAdminConfig(null);
|
||||
}, [statusState?.status?.SidebarModulesAdmin]);
|
||||
|
||||
// 加载用户配置的通用方法
|
||||
|
||||
Reference in New Issue
Block a user