feat(spotify): implement milestone M2 auth
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import minimist from "minimist";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { getAuthStatus, runAuthorizationFlow } from "./auth.js";
|
||||
|
||||
export interface CliDeps {
|
||||
stdout: Pick<NodeJS.WriteStream, "write">;
|
||||
stderr: Pick<NodeJS.WriteStream, "write">;
|
||||
@@ -37,8 +39,24 @@ function notImplemented(command: string): CommandHandler {
|
||||
|
||||
export function createDefaultHandlers(): CommandHandlers {
|
||||
return {
|
||||
auth: notImplemented("auth"),
|
||||
status: notImplemented("status"),
|
||||
auth: async (_args, deps) => {
|
||||
await runAuthorizationFlow();
|
||||
deps.stdout.write("Spotify authorization complete.\n");
|
||||
return 0;
|
||||
},
|
||||
status: async (args, deps) => {
|
||||
const status = await getAuthStatus();
|
||||
if (args.json) {
|
||||
deps.stdout.write(`${JSON.stringify(status, null, 2)}\n`);
|
||||
} else {
|
||||
deps.stdout.write(`Spotify config: ${status.configFound ? "found" : "missing"}\n`);
|
||||
deps.stdout.write(`Spotify token: ${status.tokenFound ? "found" : "missing"}\n`);
|
||||
if (status.tokenFound) {
|
||||
deps.stdout.write(`Spotify token expired: ${status.tokenExpired ? "yes" : "no"}\n`);
|
||||
}
|
||||
}
|
||||
return status.configFound && status.tokenFound ? 0 : 1;
|
||||
},
|
||||
search: notImplemented("search"),
|
||||
"list-playlists": notImplemented("list-playlists"),
|
||||
"create-playlist": notImplemented("create-playlist"),
|
||||
|
||||
Reference in New Issue
Block a user