Add list album command

This commit is contained in:
Ellie 2026-03-20 01:43:27 +00:00
parent f4aed98a1d
commit 376c8a4445
No known key found for this signature in database
GPG Key ID: 9DBD8FA906936CFF
2 changed files with 87 additions and 0 deletions

86
src/cli/nso/album.ts Normal file
View 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());
}

View File

@ -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';