diff --git a/src/services/dataService.js b/src/services/dataService.js index 84cd137..bb30262 100644 --- a/src/services/dataService.js +++ b/src/services/dataService.js @@ -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(); diff --git a/src/ui/dataMenu.js b/src/ui/dataMenu.js index ae0204b..4749561 100644 --- a/src/ui/dataMenu.js +++ b/src/ui/dataMenu.js @@ -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."); + } }; }