diff --git a/packages/core/src/webui/server.ts b/packages/core/src/webui/server.ts index 56ca2157..78c80431 100644 --- a/packages/core/src/webui/server.ts +++ b/packages/core/src/webui/server.ts @@ -3,6 +3,7 @@ import { serveStatic } from '@hono/node-server/serve-static'; import type { HookManager, HookProcessInfo } from '@snowluma/bridge'; import { createLogger, getLogLevel, getRecentLogs, LOG_LEVELS, setLogLevel, subscribeLogs } from '@snowluma/common/logger'; import { loadOneBotConfig, saveOneBotConfig } from '@snowluma/onebot/config'; +import { loadGlobalSettings, saveGlobalSettings } from '@snowluma/onebot/global-config'; import type { OneBotManager } from '@snowluma/onebot/manager'; import type { OneBotConfig, JsonObject as OneBotJsonObject } from '@snowluma/onebot/types'; import { readRuntimeConfig, updateRuntimeConfig, resolveRuntimeEnvOverrides } from '@snowluma/common/runtime'; @@ -1247,6 +1248,32 @@ export async function initWebUI( }); }); + // ─── Global deployment config (config/snowluma.json) ───────────────────── + // All-accounts SnowLuma knobs (rkey fallback servers + musicSignUrl). Saving + // section-merges + normalizes server-side, then hot-reloads every instance. + app.get('/api/global-config', (c) => c.json({ config: loadGlobalSettings() })); + + app.post('/api/global-config', async (c) => { + const declaredLen = Number(c.req.header('content-length')); + if (Number.isFinite(declaredLen) && declaredLen > 512 * 1024) { + return c.json({ success: false, message: '配置过大' }, 413); + } + let body: unknown; + try { + body = await c.req.json(); + } catch { + return c.json({ success: false, message: '请求格式错误' }, 400); + } + try { + const config = saveGlobalSettings(body); + oneBotManager.reloadGlobalSettings(); + return c.json({ success: true, config }); + } catch (err) { + log.warn('save global config failed: %s', err instanceof Error ? err.message : String(err)); + return c.json({ success: false, message: '保存失败,请检查服务器日志' }, 500); + } + }); + // ─── WebUI customization config (config/ui.json) ───────────────────────── // Appearance (A) + layout (C). The full config is bearer-gated; only the // cosmetic appearance subset is exposed unauthenticated for the login page. diff --git a/packages/webui/src/components/config/general-settings-tab.tsx b/packages/webui/src/components/config/general-settings-tab.tsx index 144852f1..6ac71168 100644 --- a/packages/webui/src/components/config/general-settings-tab.tsx +++ b/packages/webui/src/components/config/general-settings-tab.tsx @@ -1,7 +1,8 @@ -// "通用设置" tab — fields that apply to the whole OneBotInstance rather -// than any specific adapter: the music-sign service URL and the built-in -// `#sl` status command. Edits here mark the config dirty and are -// auto-saved with debounce by the parent ConfigPage. +// "通用设置" tab — per-account fields that apply to the whole OneBotInstance +// rather than any specific adapter: the built-in `#sl` status command and the +// notification opt-in. Edits here mark the config dirty and are auto-saved with +// debounce by the parent ConfigPage. (Deployment-wide knobs like the music-sign +// URL live in Settings → 全局配置, not here.) import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; @@ -21,19 +22,6 @@ export function GeneralSettingsTab({ config, onChange }: GeneralSettingsTabProps return (
- 用于音乐分享卡片签名。未配置时音乐相关消息段会回落为普通文本。 -
-加载全局配置失败
+ +
+ 图片 / 文件下载链接需要服务器签发的 rkey。SnowLuma 默认走内核获取;
+ 当内核在你的环境下持续取不到时,会按顺序向这里配置的 HTTP 端点回退。
+ 默认留空=关闭,不配置就不会联系任何第三方。
+ 建议填你自建的端点。
+
+ 未配置回退服务器(rkey 回退已关闭) +
+ ) : ( +
+ 端点需返回 {'{ group_rkey, private_rkey, expired_time }'}
+ (兼容 NapCat rkey 服务格式)。非 http(s) 链接会被忽略。
+
音乐分享卡片的签名服务,对所有账号统一生效。留空则使用内置默认服务。
+
+ 内置默认:{MUSIC_SIGN_DEFAULT}
+
{msg.text}
} +