mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 13:02:49 +08:00
feat(spotify): web OAuth endpoints + thread single shared SpotifyOAuth to web + controllers (Stage 3, Task 6)
Add the /api/spotify {login,callback,status} router behind the SpotifyOAuthLike
seam (DI-tested with supertest, no network). Build ONE process-wide SpotifyOAuth
in index.ts (clientId/redirectUri from config; store via the already-exported
createFileOAuthTokenStore) and thread that same instance into BOTH createWebServer
AND BotManager -> BotInstance -> SpotifyController, so a web login authorizes
playback (C3.1). Reuses the existing file token store (no token-store.ts).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
322335dfc5
commit
8998b9623f
8 files changed
+363
-2
No files matched your search
+8
-1
@@ -14,6 +14,7 @@ import type { Logger } from "../logger.js";
|
||||
import type { ServerProtocol } from "../ts-protocol/client.js";
|
||||
import type { AvatarStore } from "../data/avatars.js";
|
||||
import type { PermissionStore } from "../data/permissions.js";
|
||||
import type { SpotifyOAuth } from "../music/spotify/spotify-oauth.js";
|
||||
|
||||
/**
|
||||
* Run bot.connect() with a hard deadline. If the handshake hangs (e.g. the
|
||||
@@ -79,6 +80,7 @@ export class BotManager extends EventEmitter {
|
||||
private kugouProvider: MusicProvider;
|
||||
private spotifyProvider: MusicProvider;
|
||||
private spotifyDataDir: string;
|
||||
private readonly spotifyOAuth?: SpotifyOAuth;
|
||||
private database: BotDatabase;
|
||||
private config: BotConfig;
|
||||
private logger: Logger;
|
||||
@@ -99,7 +101,8 @@ export class BotManager extends EventEmitter {
|
||||
localProvider?: MusicProvider,
|
||||
kugouProvider?: MusicProvider,
|
||||
spotifyProvider?: MusicProvider,
|
||||
spotifyDataDir?: string
|
||||
spotifyDataDir?: string,
|
||||
spotifyOAuth?: SpotifyOAuth
|
||||
) {
|
||||
super();
|
||||
this.neteaseProvider = neteaseProvider;
|
||||
@@ -110,6 +113,7 @@ export class BotManager extends EventEmitter {
|
||||
this.kugouProvider = kugouProvider ?? neteaseProvider;
|
||||
this.spotifyProvider = spotifyProvider ?? neteaseProvider;
|
||||
this.spotifyDataDir = spotifyDataDir ?? path.join(process.cwd(), "data", "spotify");
|
||||
this.spotifyOAuth = spotifyOAuth;
|
||||
// Let the local provider see which uploads are still referenced by any
|
||||
// bot's queue, so it never deletes a file another queue/bot still needs.
|
||||
const referenceable = this.localProvider as Partial<{
|
||||
@@ -154,6 +158,7 @@ export class BotManager extends EventEmitter {
|
||||
logger: this.logger,
|
||||
avatarStore: this.avatarStore,
|
||||
spotifyDataDir: this.spotifyDataDir,
|
||||
spotifyOAuth: this.spotifyOAuth,
|
||||
});
|
||||
|
||||
this.bots.set(id, bot);
|
||||
@@ -296,6 +301,7 @@ export class BotManager extends EventEmitter {
|
||||
logger: this.logger,
|
||||
avatarStore: this.avatarStore,
|
||||
spotifyDataDir: this.spotifyDataDir,
|
||||
spotifyOAuth: this.spotifyOAuth,
|
||||
});
|
||||
this.bots.set(id, bot);
|
||||
this.emit("botInstance", bot);
|
||||
@@ -352,6 +358,7 @@ export class BotManager extends EventEmitter {
|
||||
logger: this.logger,
|
||||
avatarStore: this.avatarStore,
|
||||
spotifyDataDir: this.spotifyDataDir,
|
||||
spotifyOAuth: this.spotifyOAuth,
|
||||
});
|
||||
|
||||
this.bots.set(saved.id, bot);
|
||||
|
||||
Reference in new issue
Block a user