tangled
alpha
login
or
join now
tsiry-sandratraina.com
/
rocksky-cli
9
fork
atom
🎧 The official command-line interface for Rocksky — a modern, decentralized music tracking and discovery platform built on the AT Protocol.
9
fork
atom
overview
issues
pulls
pipelines
save current user did to file
tsiry-sandratraina.com
11 months ago
1aa661f9
f2e89c99
+15
-2
1 changed file
expand all
collapse all
unified
split
src
client.ts
+15
-2
src/client.ts
···
1
1
+
import fs from "fs";
2
2
+
import os from "os";
3
3
+
import path from "path";
4
4
+
1
5
export const ROCKSKY_API_URL = "https://api.rocksky.app";
2
6
3
7
export class RockskyClient {
···
122
126
123
127
async stats(did?: string) {
124
128
if (!did) {
125
125
-
const user = await this.getCurrentUser();
126
126
-
did = user.handle;
129
129
+
const didFile = path.join(os.homedir(), ".rocksky", "did");
130
130
+
try {
131
131
+
await fs.promises.access(didFile);
132
132
+
did = await fs.promises.readFile(didFile, "utf-8");
133
133
+
} catch (err) {
134
134
+
const user = await this.getCurrentUser();
135
135
+
did = user.did;
136
136
+
const didPath = path.join(os.homedir(), ".rocksky");
137
137
+
fs.promises.mkdir(didPath, { recursive: true });
138
138
+
await fs.promises.writeFile(didFile, did);
139
139
+
}
127
140
}
128
141
129
142
const response = await fetch(`${ROCKSKY_API_URL}/users/${did}/stats`, {