🎧 The official command-line interface for Rocksky — a modern, decentralized music tracking and discovery platform built on the AT Protocol.

save current user did to file

+15 -2
+15 -2
src/client.ts
··· 1 export const ROCKSKY_API_URL = "https://api.rocksky.app"; 2 3 export class RockskyClient { ··· 122 123 async stats(did?: string) { 124 if (!did) { 125 - const user = await this.getCurrentUser(); 126 - did = user.handle; 127 } 128 129 const response = await fetch(`${ROCKSKY_API_URL}/users/${did}/stats`, {
··· 1 + import fs from "fs"; 2 + import os from "os"; 3 + import path from "path"; 4 + 5 export const ROCKSKY_API_URL = "https://api.rocksky.app"; 6 7 export class RockskyClient { ··· 126 127 async stats(did?: string) { 128 if (!did) { 129 + const didFile = path.join(os.homedir(), ".rocksky", "did"); 130 + try { 131 + await fs.promises.access(didFile); 132 + did = await fs.promises.readFile(didFile, "utf-8"); 133 + } catch (err) { 134 + const user = await this.getCurrentUser(); 135 + did = user.did; 136 + const didPath = path.join(os.homedir(), ".rocksky"); 137 + fs.promises.mkdir(didPath, { recursive: true }); 138 + await fs.promises.writeFile(didFile, did); 139 + } 140 } 141 142 const response = await fetch(`${ROCKSKY_API_URL}/users/${did}/stats`, {