squidcloudctl 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/auth/whoami.js +20 -5
- package/package.json +1 -1
|
@@ -2,20 +2,35 @@ import chalk from 'chalk';
|
|
|
2
2
|
import { apiGet } from '../../lib/api/client.js';
|
|
3
3
|
import { success, muted } from '../../lib/output/brand.js';
|
|
4
4
|
import { isJsonMode } from '../../lib/output/logger.js';
|
|
5
|
+
function humanBytes(n) {
|
|
6
|
+
if (!n || n <= 0)
|
|
7
|
+
return '0 B';
|
|
8
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
9
|
+
let v = n, u = 0;
|
|
10
|
+
while (v >= 1024 && u < units.length - 1) {
|
|
11
|
+
v /= 1024;
|
|
12
|
+
u++;
|
|
13
|
+
}
|
|
14
|
+
return `${v.toFixed(v >= 100 || u === 0 ? 0 : 1)}${units[u]}`;
|
|
15
|
+
}
|
|
5
16
|
export default async function whoami() {
|
|
6
17
|
const res = await apiGet('/user/whoami');
|
|
7
18
|
if (isJsonMode()) {
|
|
8
19
|
console.log(JSON.stringify(res, null, 2));
|
|
9
20
|
return;
|
|
10
21
|
}
|
|
11
|
-
const
|
|
22
|
+
const used = res.storage_used ?? res.total_size ?? 0;
|
|
12
23
|
console.log();
|
|
13
24
|
console.log(` ${chalk.bold('account')} ${res.email || res.full_name || 'unknown'}`);
|
|
14
25
|
if (res.id)
|
|
15
26
|
console.log(` ${chalk.bold('user id')} ${muted(res.id)}`);
|
|
16
|
-
if (typeof res.total_files === 'number')
|
|
17
|
-
console.log(` ${chalk.bold('storage')} ${res.total_files} files · ${
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
if (typeof res.total_files === 'number') {
|
|
28
|
+
console.log(` ${chalk.bold('storage')} ${res.total_files} files · ${chalk.bold(humanBytes(used))}`);
|
|
29
|
+
}
|
|
30
|
+
const c = res.credits;
|
|
31
|
+
if (c && c.remaining !== undefined) {
|
|
32
|
+
const limit = c.daily_limit === -1 ? 'unlimited' : String(c.daily_limit);
|
|
33
|
+
console.log(` ${chalk.bold('api credits')} ${c.remaining === -1 ? '∞ unlimited' : c.remaining} / ${limit}`);
|
|
34
|
+
}
|
|
20
35
|
console.log(`\n ${success('session valid')} — ${muted('~/.squidcloud/credentials')}\n`);
|
|
21
36
|
}
|