A decentralized music tracking and discovery platform built on AT Protocol 馃幍
rocksky.app
spotify
atproto
lastfm
musicbrainz
scrobbling
listenbrainz
1import chalk from "chalk";
2import { RockskyClient } from "client";
3import fs from "fs/promises";
4import os from "os";
5import path from "path";
6
7export async function createApiKey(name, { description }) {
8 const tokenPath = path.join(os.homedir(), ".rocksky", "token.json");
9 try {
10 await fs.access(tokenPath);
11 } catch (err) {
12 console.error(
13 `You are not logged in. Please run ${chalk.greenBright(
14 "`rocksky login <username>.bsky.social`"
15 )} first.`
16 );
17 return;
18 }
19
20 const tokenData = await fs.readFile(tokenPath, "utf-8");
21 const { token } = JSON.parse(tokenData);
22 if (!token) {
23 console.error(
24 `You are not logged in. Please run ${chalk.greenBright(
25 "`rocksky login <username>.bsky.social`"
26 )} first.`
27 );
28 return;
29 }
30
31 const client = new RockskyClient(token);
32 const apikey = await client.createApiKey(name, description);
33 if (!apikey) {
34 console.error(`Failed to create API key. Please try again later.`);
35 return;
36 }
37
38 console.log(`API key created successfully!`);
39 console.log(`Name: ${chalk.greenBright(apikey.name)}`);
40 if (apikey.description) {
41 console.log(`Description: ${chalk.greenBright(apikey.description)}`);
42 }
43 console.log(`Key: ${chalk.greenBright(apikey.api_key)}`);
44 console.log(`Secret: ${chalk.greenBright(apikey.shared_secret)}`);
45}