mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
feat: add configurable default music source (#126)
Make the default playback source a user-configurable setting so servers that mostly play e.g. Bilibili no longer need to type `-b` on every `!play`. Previously defaultPlatform() always picked the first enabled provider by a fixed priority order, with no way to override it. - config: add optional `defaultPlatform: GateableProvider | null`. loadConfig sanitizes it — kept only when it names a known provider that is also currently enabled, else null. defaultPlatform() returns the preference when enabled, otherwise falls back to the fixed priority order. - POST /api/bot/settings accepts `defaultPlatform` (validated against the possibly-updated enabledProviders; null/"" clears it), and reconciles a stored default that a new enabledProviders list no longer allows. GET and POST responses expose the field. - WebUI: new "默认音源" section with a source picker; saving refreshes the store's default source so it takes effect immediately without a restart. - Tests: extend config defaultPlatform priority tests and add coverage for the settings endpoint and /providers routing. - README: document `defaultPlatform` in the enabledProviders section. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
051171b019
commit
987513a5f6
7 files changed
+279
-9
No files matched your search
@@ -77,6 +77,7 @@ export function createBotRouter(
|
||||
spotify: maskedSpotify(),
|
||||
jellyfin: maskedJellyfin(),
|
||||
enabledProviders: config.enabledProviders,
|
||||
defaultPlatform: config.defaultPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -175,6 +176,29 @@ export function createBotRouter(
|
||||
);
|
||||
}
|
||||
|
||||
// defaultPlatform (issue #126): the operator-chosen default source for
|
||||
// platform-less commands/REST/WebUI calls. Reconciled AFTER enabledProviders
|
||||
// so both are validated against the same (possibly updated) enabled list:
|
||||
// 1) Drop a stored default that the new enabledProviders no longer allows,
|
||||
// keeping the persisted config consistent with loadConfig's invariant.
|
||||
// 2) Apply an explicit change — `null`/`""` clears it (back to priority
|
||||
// order); a known+enabled provider sets it; anything else is ignored.
|
||||
if (config.defaultPlatform && !config.enabledProviders.includes(config.defaultPlatform)) {
|
||||
config.defaultPlatform = null;
|
||||
}
|
||||
if ("defaultPlatform" in req.body) {
|
||||
const dp = req.body.defaultPlatform;
|
||||
if (dp === null || dp === "") {
|
||||
config.defaultPlatform = null;
|
||||
} else if (
|
||||
typeof dp === "string" &&
|
||||
(GATEABLE_PROVIDERS as readonly string[]).includes(dp) &&
|
||||
config.enabledProviders.includes(dp as GateableProvider)
|
||||
) {
|
||||
config.defaultPlatform = dp as GateableProvider;
|
||||
}
|
||||
}
|
||||
|
||||
saveConfig(configPath, config);
|
||||
|
||||
// Hot-apply the (possibly re-pointed) Jellyfin connection to the live
|
||||
@@ -219,6 +243,7 @@ export function createBotRouter(
|
||||
spotify: maskedSpotify(),
|
||||
jellyfin: maskedJellyfin(),
|
||||
enabledProviders: config.enabledProviders,
|
||||
defaultPlatform: config.defaultPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user