🎧 The official command-line interface for Rocksky — a modern, decentralized music tracking and discovery platform built on the AT Protocol.
at main 27 lines 904 B view raw
1import { RockskyClient } from "client"; 2import fs from "fs/promises"; 3import os from "os"; 4import path from "path"; 5 6export async function createApiKey(name, { description }) { 7 const tokenPath = path.join(os.homedir(), ".rocksky", "token.json"); 8 try { 9 await fs.access(tokenPath); 10 } catch (err) { 11 return "You are not logged in. Please run `rocksky login <username>.bsky.social` first."; 12 } 13 14 const tokenData = await fs.readFile(tokenPath, "utf-8"); 15 const { token } = JSON.parse(tokenData); 16 if (!token) { 17 return "You are not logged in. Please run `rocksky login <username>.bsky.social` first."; 18 } 19 20 const client = new RockskyClient(token); 21 const apikey = await client.createApiKey(name, description); 22 if (!apikey) { 23 return "Failed to create API key. Please try again later."; 24 } 25 26 return "API key created successfully!, navigate to your Rocksky account to view it."; 27}