✨ feat(ratio-sync, ui): add built‑in “Official Ratio Preset” and harden upstream sync
Backend (controller/ratio_sync.go): - Add built‑in official upstream to GetSyncableChannels (ID: -100, BaseURL: https://basellm.github.io) - Support absolute endpoint URLs; otherwise join BaseURL + endpoint (defaults to /api/ratio_config) - Harden HTTP client: - IPv4‑first with IPv6 fallback for github.io - Add ResponseHeaderTimeout - 3 attempts with exponential backoff (200/400/800ms) - Validate Content-Type and limit response body to 10MB (safe decode via io.LimitReader) - Robust parsing: support type1 ratio_config map and type2 pricing list - Use net.SplitHostPort for host parsing - Use float tolerance in differences comparison to avoid false mismatches - Remove unused code (tryDirect) and improve warnings Frontend: - UpstreamRatioSync.jsx: auto-assign official endpoint to /llm-metadata/api/newapi/ratio_config-v1-base.json - ChannelSelectorModal.jsx: - Pin the official source at the top of the list - Show a green “官方” tag next to the status - Refactor status renderer to accept the full record Notes: - Backward compatible; no API surface changes - Official ratio_config reference: https://basellm.github.io/llm-metadata/api/newapi/ratio_config-v1-base.json
This commit is contained in:
@@ -20,67 +20,66 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export const useNavigation = (t, docsLink, headerNavModules) => {
|
||||
const mainNavLinks = useMemo(
|
||||
() => {
|
||||
// 默认配置,如果没有传入配置则显示所有模块
|
||||
const defaultModules = {
|
||||
home: true,
|
||||
console: true,
|
||||
pricing: true,
|
||||
docs: true,
|
||||
about: true,
|
||||
};
|
||||
const mainNavLinks = useMemo(() => {
|
||||
// 默认配置,如果没有传入配置则显示所有模块
|
||||
const defaultModules = {
|
||||
home: true,
|
||||
console: true,
|
||||
pricing: true,
|
||||
docs: true,
|
||||
about: true,
|
||||
};
|
||||
|
||||
// 使用传入的配置或默认配置
|
||||
const modules = headerNavModules || defaultModules;
|
||||
// 使用传入的配置或默认配置
|
||||
const modules = headerNavModules || defaultModules;
|
||||
|
||||
const allLinks = [
|
||||
{
|
||||
text: t('首页'),
|
||||
itemKey: 'home',
|
||||
to: '/',
|
||||
},
|
||||
{
|
||||
text: t('控制台'),
|
||||
itemKey: 'console',
|
||||
to: '/console',
|
||||
},
|
||||
{
|
||||
text: t('模型广场'),
|
||||
itemKey: 'pricing',
|
||||
to: '/pricing',
|
||||
},
|
||||
...(docsLink
|
||||
? [
|
||||
{
|
||||
text: t('文档'),
|
||||
itemKey: 'docs',
|
||||
isExternal: true,
|
||||
externalLink: docsLink,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
text: t('关于'),
|
||||
itemKey: 'about',
|
||||
to: '/about',
|
||||
},
|
||||
];
|
||||
const allLinks = [
|
||||
{
|
||||
text: t('首页'),
|
||||
itemKey: 'home',
|
||||
to: '/',
|
||||
},
|
||||
{
|
||||
text: t('控制台'),
|
||||
itemKey: 'console',
|
||||
to: '/console',
|
||||
},
|
||||
{
|
||||
text: t('模型广场'),
|
||||
itemKey: 'pricing',
|
||||
to: '/pricing',
|
||||
},
|
||||
...(docsLink
|
||||
? [
|
||||
{
|
||||
text: t('文档'),
|
||||
itemKey: 'docs',
|
||||
isExternal: true,
|
||||
externalLink: docsLink,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
text: t('关于'),
|
||||
itemKey: 'about',
|
||||
to: '/about',
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤导航链接
|
||||
return allLinks.filter(link => {
|
||||
if (link.itemKey === 'docs') {
|
||||
return docsLink && modules.docs;
|
||||
}
|
||||
if (link.itemKey === 'pricing') {
|
||||
// 支持新的pricing配置格式
|
||||
return typeof modules.pricing === 'object' ? modules.pricing.enabled : modules.pricing;
|
||||
}
|
||||
return modules[link.itemKey] === true;
|
||||
});
|
||||
},
|
||||
[t, docsLink, headerNavModules],
|
||||
);
|
||||
// 根据配置过滤导航链接
|
||||
return allLinks.filter((link) => {
|
||||
if (link.itemKey === 'docs') {
|
||||
return docsLink && modules.docs;
|
||||
}
|
||||
if (link.itemKey === 'pricing') {
|
||||
// 支持新的pricing配置格式
|
||||
return typeof modules.pricing === 'object'
|
||||
? modules.pricing.enabled
|
||||
: modules.pricing;
|
||||
}
|
||||
return modules[link.itemKey] === true;
|
||||
});
|
||||
}, [t, docsLink, headerNavModules]);
|
||||
|
||||
return {
|
||||
mainNavLinks,
|
||||
|
||||
Reference in New Issue
Block a user