mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-07-03 00:20:55 -05:00
Add list album command
This commit is contained in:
parent
f4aed98a1d
commit
376c8a4445
86
src/cli/nso/album.ts
Normal file
86
src/cli/nso/album.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import Table from '../../util/table.js';
|
||||
import type { Arguments as ParentArguments } from './index.js';
|
||||
import createDebug from '../../util/debug.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
|
||||
import { initStorage } from '../../util/storage.js';
|
||||
import { getToken, Login } from '../../common/auth/coral.js';
|
||||
|
||||
const debug = createDebug('cli:nso:album');
|
||||
|
||||
export const command = 'album';
|
||||
export const desc = 'List Nintendo Switch 2 album';
|
||||
|
||||
export function builder(yargs: Argv<ParentArguments>) {
|
||||
return yargs.option('user', {
|
||||
describe: 'Nintendo Account ID',
|
||||
type: 'string',
|
||||
}).option('token', {
|
||||
describe: 'Nintendo Account session token',
|
||||
type: 'string',
|
||||
}).option('json', {
|
||||
describe: 'Output raw JSON',
|
||||
type: 'boolean',
|
||||
}).option('json-pretty-print', {
|
||||
describe: 'Output pretty-printed JSON',
|
||||
type: 'boolean',
|
||||
});
|
||||
}
|
||||
|
||||
type Arguments = YargsArguments<ReturnType<typeof builder>>;
|
||||
|
||||
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
console.warn('Listing album items');
|
||||
|
||||
const storage = await initStorage(argv.dataPath);
|
||||
|
||||
const usernsid = argv.user ?? await storage.getItem('SelectedUser');
|
||||
const token: string = argv.token ||
|
||||
await storage.getItem('NintendoAccountToken.' + usernsid);
|
||||
const {nso, data} = await getToken(storage, token, argv.zncProxyUrl);
|
||||
|
||||
const [media, [friends, chats, webservices, activeevent, announcements, current_user]] = await Promise.all([
|
||||
nso.getMedia(),
|
||||
|
||||
data[Login] || true ? Promise.all([
|
||||
nso.getFriendList(),
|
||||
nso.getChats(),
|
||||
nso.getWebServices(),
|
||||
nso.getActiveEvent(),
|
||||
nso.getAnnouncements(),
|
||||
nso.getCurrentUser(),
|
||||
]) : [],
|
||||
]);
|
||||
|
||||
if (argv.jsonPrettyPrint) {
|
||||
console.log(JSON.stringify(media, null, 4));
|
||||
return;
|
||||
}
|
||||
if (argv.json) {
|
||||
console.log(JSON.stringify(media));
|
||||
return;
|
||||
}
|
||||
|
||||
const table = new Table({
|
||||
head: [
|
||||
'ID',
|
||||
'Type',
|
||||
'Title ID',
|
||||
'Title',
|
||||
'Captured at',
|
||||
'Uploaded at',
|
||||
],
|
||||
});
|
||||
|
||||
for (const item of media.media) {
|
||||
table.push([
|
||||
item.id,
|
||||
item.type,
|
||||
item.applicationId,
|
||||
item.appName,
|
||||
new Date(item.capturedAt * 1000).toISOString(),
|
||||
new Date(item.uploadedAt * 1000).toISOString(),
|
||||
]);
|
||||
}
|
||||
|
||||
console.log(table.toString());
|
||||
}
|
||||
|
|
@ -15,3 +15,4 @@ export * as friendcode from './friendcode.js';
|
|||
export * as lookup from './lookup.js';
|
||||
export * as addFriend from './add-friend.js';
|
||||
export * as playActivity from './play-activity.js';
|
||||
export * as album from './album.js';
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user