guard conditions invocation fix

This commit is contained in:
Ben 2025-06-03 11:00:48 +02:00
parent fa86a80eab
commit 54dfd5ee34
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
7 changed files with 92 additions and 79 deletions

View File

@ -154,7 +154,11 @@ export async function main() {
const dataService = new DataService(configService); const dataService = new DataService(configService);
const dataMenu = new DataMenu(uiService, fsService, dataService); const dataMenu = new DataMenu(uiService, fsService, dataService);
const feedbackService = new FeedbackService(); const feedbackService = new FeedbackService();
const nodeStatusMenu = new NodeStatusMenu(uiService, dataService, new MenuLoop()); const nodeStatusMenu = new NodeStatusMenu(
uiService,
dataService,
new MenuLoop(),
);
const mainMenu = new MainMenu( const mainMenu = new MainMenu(
uiService, uiService,
new MenuLoop(), new MenuLoop(),

View File

@ -60,7 +60,6 @@ export class ConfigService {
this.config = defaultConfig; this.config = defaultConfig;
this.saveConfig(); this.saveConfig();
} }
} }
} catch (error) { } catch (error) {
console.error( console.error(

View File

@ -45,14 +45,14 @@ export class DataService {
debugInfo = async () => { debugInfo = async () => {
const debug = this.getCodexDebug(); const debug = this.getCodexDebug();
return await debug.info(); return await debug.info();
} };
localData = async () => { localData = async () => {
const data = this.getCodexData(); const data = this.getCodexData();
return await data.cids(); return await data.cids();
}; };
getCodex = () =>{ getCodex = () => {
const config = this.configService.get(); const config = this.configService.get();
const url = `http://localhost:${config.ports.apiPort}`; const url = `http://localhost:${config.ports.apiPort}`;
const codex = new Codex(url); const codex = new Codex(url);
@ -63,7 +63,7 @@ export class DataService {
return this.getCodex().data; return this.getCodex().data;
}; };
getCodexDebug = () =>{ getCodexDebug = () => {
return this.getCodex().debug; return this.getCodex().debug;
}; };

View File

@ -2,9 +2,7 @@ import open from "open";
export class FeedbackService { export class FeedbackService {
openFeedbackPage = async () => { openFeedbackPage = async () => {
const segments = [ const segments = ["https://tally.so/r/w2DlXb"];
"https://tally.so/r/w2DlXb",
];
const url = segments.join(""); const url = segments.join("");
open(url); open(url);

View File

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

View File

@ -98,36 +98,44 @@ export class MainMenu {
} }
}; };
ifInstalled = async (call) => { ifInstalled = (call) => {
if (await this.isInstalled()) { return async () => {
await call(); if (await this.isInstalled()) {
} else { await call();
this.ui.showInfoMessage("Codex is not yet installed."); } else {
} this.ui.showInfoMessage("Codex is not yet installed.");
} }
};
ifNotInstalled = async (call) => {
if (!await this.isInstalled()) {
await call();
} else {
this.ui.showInfoMessage("Codex is installed.");
}
}
ifRunning = async (call) => {
if (await this.isRunning()) {
await call();
} else {
this.ui.showInfoMessage("Codex is not yet running.");
}
}; };
ifNotRunning = async (call) => { ifNotInstalled = (call) => {
if (!await this.isRunning()) { return async () => {
await call(); if (!(await this.isInstalled())) {
} else { await call();
this.ui.showInfoMessage("Codex is running."); } else {
} this.ui.showInfoMessage("Codex is installed.");
}
};
};
ifRunning = (call) => {
return async () => {
if (await this.isRunning()) {
await call();
} else {
this.ui.showInfoMessage("Codex is not yet running.");
}
};
};
ifNotRunning = (call) => {
return async () => {
if (!(await this.isRunning())) {
await call();
} else {
this.ui.showInfoMessage("Codex is running.");
}
};
}; };
isInstalled = async () => { isInstalled = async () => {
@ -135,6 +143,6 @@ export class MainMenu {
}; };
isRunning = async () => { isRunning = async () => {
return ((await this.processControl.getNumberOfCodexProcesses()) > 0); return (await this.processControl.getNumberOfCodexProcesses()) > 0;
}; };
} }

View File

@ -19,13 +19,13 @@ export class NodeStatusMenu {
if (isOnline) { if (isOnline) {
this.showSuccessMessage( this.showSuccessMessage(
"Node is ONLINE & DISCOVERABLE", "Node is ONLINE & DISCOVERABLE",
"🔌 Node Status" "🔌 Node Status",
) );
} else { } else {
this.showInfoMessage( this.showInfoMessage(
"Node is ONLINE but has few peers", "Node is ONLINE but has few peers",
"🔌 Node Status" "🔌 Node Status",
) );
} }
await this.loop.showLoop(); await this.loop.showLoop();
@ -51,31 +51,31 @@ export class NodeStatusMenu {
showPeers = async () => { showPeers = async () => {
const peerCount = this.debugInfo.table.nodes.length; const peerCount = this.debugInfo.table.nodes.length;
if (peerCount > 0) { if (peerCount > 0) {
this.ui.showInfoMessage('Connected Peers'); this.ui.showInfoMessage("Connected Peers");
this.debugInfo.table.nodes.forEach((node, index) => { this.debugInfo.table.nodes.forEach((node, index) => {
this.ui.showInfoMessage( this.ui.showInfoMessage(
`Peer ${index + 1}:\n` + `Peer ${index + 1}:\n` +
`${chalk.cyan('Peer ID:')} ${node.peerId}\n` + `${chalk.cyan("Peer ID:")} ${node.peerId}\n` +
`${chalk.cyan('Address:')} ${node.address}\n` + `${chalk.cyan("Address:")} ${node.address}\n` +
`${chalk.cyan('Status:')} ${node.seen ? chalk.green('Active') : chalk.gray('Inactive')}`, `${chalk.cyan("Status:")} ${node.seen ? chalk.green("Active") : chalk.gray("Inactive")}`,
); );
}); });
} else { } else {
this.ui.showInfoMessage('No connected peers found.'); this.ui.showInfoMessage("No connected peers found.");
} }
}; };
showNodeInfo = async () => { showNodeInfo = async () => {
const data = this.debugInfo; const data = this.debugInfo;
this.ui.showInfoMessage( this.ui.showInfoMessage(
`${chalk.cyan('Version:')} ${data.codex.version}\n` + `${chalk.cyan("Version:")} ${data.codex.version}\n` +
`${chalk.cyan('Revision:')} ${data.codex.revision}\n\n` + `${chalk.cyan("Revision:")} ${data.codex.revision}\n\n` +
`${chalk.cyan('Node ID:')} ${data.table.localNode.nodeId}\n` + `${chalk.cyan("Node ID:")} ${data.table.localNode.nodeId}\n` +
`${chalk.cyan('Peer ID:')} ${data.table.localNode.peerId}\n` + `${chalk.cyan("Peer ID:")} ${data.table.localNode.peerId}\n` +
`${chalk.cyan('Listening Address:')} ${data.table.localNode.address}\n\n` + `${chalk.cyan("Listening Address:")} ${data.table.localNode.address}\n\n` +
`${chalk.cyan('Public IP:')} ${data.announceAddresses[0].split('/')[2]}\n` + `${chalk.cyan("Public IP:")} ${data.announceAddresses[0].split("/")[2]}\n` +
`${chalk.cyan('Port:')} ${data.announceAddresses[0].split('/')[4]}\n` + `${chalk.cyan("Port:")} ${data.announceAddresses[0].split("/")[4]}\n` +
`${chalk.cyan('Connected Peers:')} ${data.table.nodes.length}`, `${chalk.cyan("Connected Peers:")} ${data.table.nodes.length}`,
); );
}; };
@ -83,13 +83,11 @@ export class NodeStatusMenu {
const spinner = this.ui.createAndStartSpinner("Fetching..."); const spinner = this.ui.createAndStartSpinner("Fetching...");
try { try {
return await this.dataService.debugInfo(); return await this.dataService.debugInfo();
} } catch {
catch {
this.ui.showErrorMessage("Failed to fetch debug/info"); this.ui.showErrorMessage("Failed to fetch debug/info");
return; return;
} } finally {
finally {
this.ui.stopSpinnerSuccess(spinner); this.ui.stopSpinnerSuccess(spinner);
} }
} };
} }