🎧 The official command-line interface for Rocksky — a modern, decentralized music tracking and discovery platform built on the AT Protocol.
1import { RockskyClient } from "client";
2import fs from "fs/promises";
3import os from "os";
4import path from "path";
5
6export async function stats(did?: string): Promise<string> {
7 const tokenPath = path.join(os.homedir(), ".rocksky", "token.json");
8 try {
9 await fs.access(tokenPath);
10 } catch (err) {
11 if (!did) {
12 return "You are not logged in. Please run `rocksky login <username>.bsky.social` first.";
13 }
14 }
15
16 const tokenData = await fs.readFile(tokenPath, "utf-8");
17 const { token } = JSON.parse(tokenData);
18 if (!token && !did) {
19 return "You are not logged in. Please run `rocksky login <username>.bsky.social` first.";
20 }
21
22 try {
23 const client = new RockskyClient(token);
24 const stats = await client.stats(did);
25
26 return JSON.stringify(
27 {
28 scrobbles: stats.scrobbles,
29 tracks: stats.tracks,
30 albums: stats.albums,
31 artists: stats.artists,
32 lovedTracks: stats.lovedTracks,
33 },
34 null,
35 2
36 );
37 } catch (err) {
38 return `Failed to fetch stats data. Please check your token and try again, error: ${err.message}`;
39 }
40}