mirror of
https://github.com/logos-storage/logos-storage-installer.git
synced 2026-01-02 13:33:11 +00:00
guard conditions invocation fix
This commit is contained in:
parent
fa86a80eab
commit
54dfd5ee34
@ -154,7 +154,11 @@ export async function main() {
|
||||
const dataService = new DataService(configService);
|
||||
const dataMenu = new DataMenu(uiService, fsService, dataService);
|
||||
const feedbackService = new FeedbackService();
|
||||
const nodeStatusMenu = new NodeStatusMenu(uiService, dataService, new MenuLoop());
|
||||
const nodeStatusMenu = new NodeStatusMenu(
|
||||
uiService,
|
||||
dataService,
|
||||
new MenuLoop(),
|
||||
);
|
||||
const mainMenu = new MainMenu(
|
||||
uiService,
|
||||
new MenuLoop(),
|
||||
|
||||
@ -60,7 +60,6 @@ export class ConfigService {
|
||||
this.config = defaultConfig;
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
|
||||
@ -45,14 +45,14 @@ export class DataService {
|
||||
debugInfo = async () => {
|
||||
const debug = this.getCodexDebug();
|
||||
return await debug.info();
|
||||
}
|
||||
};
|
||||
|
||||
localData = async () => {
|
||||
const data = this.getCodexData();
|
||||
return await data.cids();
|
||||
};
|
||||
|
||||
getCodex = () =>{
|
||||
getCodex = () => {
|
||||
const config = this.configService.get();
|
||||
const url = `http://localhost:${config.ports.apiPort}`;
|
||||
const codex = new Codex(url);
|
||||
@ -63,7 +63,7 @@ export class DataService {
|
||||
return this.getCodex().data;
|
||||
};
|
||||
|
||||
getCodexDebug = () =>{
|
||||
getCodexDebug = () => {
|
||||
return this.getCodex().debug;
|
||||
};
|
||||
|
||||
|
||||
@ -2,9 +2,7 @@ import open from "open";
|
||||
|
||||
export class FeedbackService {
|
||||
openFeedbackPage = async () => {
|
||||
const segments = [
|
||||
"https://tally.so/r/w2DlXb",
|
||||
];
|
||||
const segments = ["https://tally.so/r/w2DlXb"];
|
||||
|
||||
const url = segments.join("");
|
||||
open(url);
|
||||
|
||||
@ -40,33 +40,39 @@ export class DataMenu {
|
||||
try {
|
||||
const localData = await this.dataService.localData();
|
||||
this.displayLocalData(localData);
|
||||
}
|
||||
catch (exception) {
|
||||
} 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)`);
|
||||
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 { cid, manifest } = file;
|
||||
const {
|
||||
originalBytes,
|
||||
protected: isProtected,
|
||||
filename,
|
||||
mimetype,
|
||||
} = manifest;
|
||||
|
||||
const fileSize = (originalBytes / 1024).toFixed(2);
|
||||
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')}`,
|
||||
);
|
||||
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.");
|
||||
this.ui.showInfoMessage("Node contains no datasets.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -98,36 +98,44 @@ export class MainMenu {
|
||||
}
|
||||
};
|
||||
|
||||
ifInstalled = async (call) => {
|
||||
if (await this.isInstalled()) {
|
||||
await call();
|
||||
} 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.");
|
||||
}
|
||||
ifInstalled = (call) => {
|
||||
return async () => {
|
||||
if (await this.isInstalled()) {
|
||||
await call();
|
||||
} else {
|
||||
this.ui.showInfoMessage("Codex is not yet installed.");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
ifNotRunning = async (call) => {
|
||||
if (!await this.isRunning()) {
|
||||
await call();
|
||||
} else {
|
||||
this.ui.showInfoMessage("Codex is running.");
|
||||
}
|
||||
ifNotInstalled = (call) => {
|
||||
return async () => {
|
||||
if (!(await this.isInstalled())) {
|
||||
await call();
|
||||
} 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 () => {
|
||||
@ -135,6 +143,6 @@ export class MainMenu {
|
||||
};
|
||||
|
||||
isRunning = async () => {
|
||||
return ((await this.processControl.getNumberOfCodexProcesses()) > 0);
|
||||
return (await this.processControl.getNumberOfCodexProcesses()) > 0;
|
||||
};
|
||||
}
|
||||
|
||||
@ -19,13 +19,13 @@ export class NodeStatusMenu {
|
||||
if (isOnline) {
|
||||
this.showSuccessMessage(
|
||||
"Node is ONLINE & DISCOVERABLE",
|
||||
"🔌 Node Status"
|
||||
)
|
||||
"🔌 Node Status",
|
||||
);
|
||||
} else {
|
||||
this.showInfoMessage(
|
||||
"Node is ONLINE but has few peers",
|
||||
"🔌 Node Status"
|
||||
)
|
||||
"🔌 Node Status",
|
||||
);
|
||||
}
|
||||
|
||||
await this.loop.showLoop();
|
||||
@ -51,31 +51,31 @@ export class NodeStatusMenu {
|
||||
showPeers = async () => {
|
||||
const peerCount = this.debugInfo.table.nodes.length;
|
||||
if (peerCount > 0) {
|
||||
this.ui.showInfoMessage('Connected Peers');
|
||||
this.debugInfo.table.nodes.forEach((node, index) => {
|
||||
this.ui.showInfoMessage(
|
||||
`Peer ${index + 1}:\n` +
|
||||
`${chalk.cyan('Peer ID:')} ${node.peerId}\n` +
|
||||
`${chalk.cyan('Address:')} ${node.address}\n` +
|
||||
`${chalk.cyan('Status:')} ${node.seen ? chalk.green('Active') : chalk.gray('Inactive')}`,
|
||||
);
|
||||
});
|
||||
this.ui.showInfoMessage("Connected Peers");
|
||||
this.debugInfo.table.nodes.forEach((node, index) => {
|
||||
this.ui.showInfoMessage(
|
||||
`Peer ${index + 1}:\n` +
|
||||
`${chalk.cyan("Peer ID:")} ${node.peerId}\n` +
|
||||
`${chalk.cyan("Address:")} ${node.address}\n` +
|
||||
`${chalk.cyan("Status:")} ${node.seen ? chalk.green("Active") : chalk.gray("Inactive")}`,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
this.ui.showInfoMessage('No connected peers found.');
|
||||
this.ui.showInfoMessage("No connected peers found.");
|
||||
}
|
||||
};
|
||||
|
||||
showNodeInfo = async () => {
|
||||
const data = this.debugInfo;
|
||||
this.ui.showInfoMessage(
|
||||
`${chalk.cyan('Version:')} ${data.codex.version}\n` +
|
||||
`${chalk.cyan('Revision:')} ${data.codex.revision}\n\n` +
|
||||
`${chalk.cyan('Node ID:')} ${data.table.localNode.nodeId}\n` +
|
||||
`${chalk.cyan('Peer ID:')} ${data.table.localNode.peerId}\n` +
|
||||
`${chalk.cyan('Listening Address:')} ${data.table.localNode.address}\n\n` +
|
||||
`${chalk.cyan('Public IP:')} ${data.announceAddresses[0].split('/')[2]}\n` +
|
||||
`${chalk.cyan('Port:')} ${data.announceAddresses[0].split('/')[4]}\n` +
|
||||
`${chalk.cyan('Connected Peers:')} ${data.table.nodes.length}`,
|
||||
`${chalk.cyan("Version:")} ${data.codex.version}\n` +
|
||||
`${chalk.cyan("Revision:")} ${data.codex.revision}\n\n` +
|
||||
`${chalk.cyan("Node ID:")} ${data.table.localNode.nodeId}\n` +
|
||||
`${chalk.cyan("Peer ID:")} ${data.table.localNode.peerId}\n` +
|
||||
`${chalk.cyan("Listening Address:")} ${data.table.localNode.address}\n\n` +
|
||||
`${chalk.cyan("Public IP:")} ${data.announceAddresses[0].split("/")[2]}\n` +
|
||||
`${chalk.cyan("Port:")} ${data.announceAddresses[0].split("/")[4]}\n` +
|
||||
`${chalk.cyan("Connected Peers:")} ${data.table.nodes.length}`,
|
||||
);
|
||||
};
|
||||
|
||||
@ -83,13 +83,11 @@ export class NodeStatusMenu {
|
||||
const spinner = this.ui.createAndStartSpinner("Fetching...");
|
||||
try {
|
||||
return await this.dataService.debugInfo();
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
this.ui.showErrorMessage("Failed to fetch debug/info");
|
||||
return;
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
this.ui.stopSpinnerSuccess(spinner);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user