sets up previous menu and functionality

This commit is contained in:
Ben 2025-06-03 10:41:20 +02:00
parent 8379de4b32
commit 0e85190026
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
2 changed files with 36 additions and 1 deletions

View File

@ -47,7 +47,10 @@ export class DataService {
return await debug.info();
}
localData = async () => {
const data = this.getCodexData();
return await data.cids();
};
getCodex = () =>{
const config = this.configService.get();

View File

@ -1,3 +1,5 @@
import chalk from "chalk";
export class DataMenu {
constructor(uiService, fsService, dataService) {
this.ui = uiService;
@ -35,6 +37,36 @@ export class DataMenu {
};
showLocalData = async () => {
try {
const localData = await this.dataService.localData();
this.displayLocalData(localData);
}
catch (exception) {
this.ui.showErrorMessage("Failed to fetch local data: " + exception);
}
};
displayLocalData = (filesData) => {
if (filesData.content && filesData.content.length > 0) {
this.ui.showInfoMessage(`Found ${filesData.content.length} local file(s)`);
filesData.content.forEach((file, index) => {
const { cid, manifest } = file;
const { originalBytes, protected: isProtected, filename, mimetype } = manifest;
const fileSize = (originalBytes / 1024).toFixed(2);
this.ui.showInfoMessage(
`${chalk.cyan('File')} ${index + 1} of ${filesData.content.length}\n\n` +
`${chalk.cyan('Filename:')} ${filename}\n` +
`${chalk.cyan('CID:')} ${cid}\n` +
`${chalk.cyan('Size:')} ${fileSize} KB\n` +
`${chalk.cyan('MIME Type:')} ${mimetype}\n` +
`${chalk.cyan('Protected:')} ${isProtected ? chalk.green('Yes') : chalk.red('No')}`,
);
});
} else {
this.ui.showInfoMessage("Node contains no datasets.");
}
};
}