mirror of
https://github.com/logos-storage/logos-storage-installer.git
synced 2026-01-03 22:13:07 +00:00
applies ports to codex start and api calls
This commit is contained in:
parent
0c7681d06f
commit
e26b65daf6
@ -10,8 +10,8 @@ import path from 'path';
|
||||
import mime from 'mime-types';
|
||||
import axios from 'axios';
|
||||
|
||||
export async function uploadFile(filePath = null, handleCommandLineOperation, showNavigationMenu) {
|
||||
const nodeRunning = await isNodeRunning();
|
||||
export async function uploadFile(config, filePath = null, handleCommandLineOperation, showNavigationMenu) {
|
||||
const nodeRunning = await isNodeRunning(config);
|
||||
if (!nodeRunning) {
|
||||
console.log(showErrorMessage('Codex node is not running. Try again after starting the node'));
|
||||
return handleCommandLineOperation() ? process.exit(1) : showNavigationMenu();
|
||||
@ -51,7 +51,7 @@ export async function uploadFile(filePath = null, handleCommandLineOperation, sh
|
||||
const spinner = createSpinner('Uploading file').start();
|
||||
try {
|
||||
const result = await runCommand(
|
||||
`curl -X POST http://localhost:8080/api/codex/v1/data ` +
|
||||
`curl -X POST http://localhost:${config.ports.apiPort}/api/codex/v1/data ` +
|
||||
`-H 'Content-Type: ${contentType}' ` +
|
||||
`-H 'Content-Disposition: attachment; filename="${filename}"' ` +
|
||||
`-w '\\n' -T "${fileToUpload}"`
|
||||
@ -71,8 +71,8 @@ export async function uploadFile(filePath = null, handleCommandLineOperation, sh
|
||||
return handleCommandLineOperation() ? process.exit(0) : showNavigationMenu();
|
||||
}
|
||||
|
||||
export async function downloadFile(cid = null, handleCommandLineOperation, showNavigationMenu) {
|
||||
const nodeRunning = await isNodeRunning();
|
||||
export async function downloadFile(config, cid = null, handleCommandLineOperation, showNavigationMenu) {
|
||||
const nodeRunning = await isNodeRunning(config);
|
||||
if (!nodeRunning) {
|
||||
console.log(showErrorMessage('Codex node is not running. Try again after starting the node'));
|
||||
return handleCommandLineOperation() ? process.exit(1) : showNavigationMenu();
|
||||
@ -95,7 +95,7 @@ export async function downloadFile(cid = null, handleCommandLineOperation, showN
|
||||
const spinner = createSpinner('Fetching file metadata...').start();
|
||||
try {
|
||||
// First, get the file metadata
|
||||
const metadataResponse = await axios.post(`http://localhost:8080/api/codex/v1/data/${cidToDownload}/network`);
|
||||
const metadataResponse = await axios.post(`http://localhost:${config.ports.apiPort}/api/codex/v1/data/${cidToDownload}/network`);
|
||||
const { manifest } = metadataResponse.data;
|
||||
const { filename, mimetype } = manifest;
|
||||
|
||||
@ -103,7 +103,7 @@ export async function downloadFile(cid = null, handleCommandLineOperation, showN
|
||||
spinner.start('Downloading file...');
|
||||
|
||||
// Then download the file with the correct filename
|
||||
await runCommand(`curl "http://localhost:8080/api/codex/v1/data/${cidToDownload}/network/stream" -o "${filename}"`);
|
||||
await runCommand(`curl "http://localhost:${config.ports.apiPort}/api/codex/v1/data/${cidToDownload}/network/stream" -o "${filename}"`);
|
||||
|
||||
spinner.success();
|
||||
console.log(showSuccessMessage(
|
||||
@ -144,8 +144,8 @@ export async function downloadFile(cid = null, handleCommandLineOperation, showN
|
||||
return handleCommandLineOperation() ? process.exit(0) : showNavigationMenu();
|
||||
}
|
||||
|
||||
export async function showLocalFiles(showNavigationMenu) {
|
||||
const nodeRunning = await isNodeRunning();
|
||||
export async function showLocalFiles(config, showNavigationMenu) {
|
||||
const nodeRunning = await isNodeRunning(config);
|
||||
if (!nodeRunning) {
|
||||
console.log(showErrorMessage('Codex node is not running. Try again after starting the node'));
|
||||
await showNavigationMenu();
|
||||
@ -154,7 +154,7 @@ export async function showLocalFiles(showNavigationMenu) {
|
||||
|
||||
try {
|
||||
const spinner = createSpinner('Fetching local files...').start();
|
||||
const filesResponse = await runCommand('curl http://localhost:8080/api/codex/v1/data -w \'\\n\'');
|
||||
const filesResponse = await runCommand(`curl http://localhost:${config.ports.apiPort}/api/codex/v1/data -w \'\\n\'`);
|
||||
spinner.success();
|
||||
|
||||
const filesData = JSON.parse(filesResponse);
|
||||
|
||||
@ -43,27 +43,12 @@ export async function runCodex(config, showNavigationMenu) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nodeAlreadyRunning = await isNodeRunning();
|
||||
const nodeAlreadyRunning = await isNodeRunning(config);
|
||||
|
||||
if (nodeAlreadyRunning) {
|
||||
console.log(showInfoMessage('A Codex node is already running.'));
|
||||
await showNavigationMenu();
|
||||
} else {
|
||||
const { discPort, listenPort } = await inquirer.prompt([
|
||||
{
|
||||
type: 'number',
|
||||
name: 'discPort',
|
||||
message: 'Enter the discovery port (default is 8090):',
|
||||
default: 8090
|
||||
},
|
||||
{
|
||||
type: 'number',
|
||||
name: 'listenPort',
|
||||
message: 'Enter the listening port (default is 8070):',
|
||||
default: 8070
|
||||
}
|
||||
]);
|
||||
|
||||
try {
|
||||
let nat;
|
||||
if (platform === 'win32') {
|
||||
@ -88,8 +73,9 @@ export async function runCodex(config, showNavigationMenu) {
|
||||
`--log-level=DEBUG`,
|
||||
`--log-file="${logFilePath}"`,
|
||||
`--storage-quota="${config.storageQuota}"`,
|
||||
`--disc-port=${discPort}`,
|
||||
`--listen-addrs=/ip4/0.0.0.0/tcp/${listenPort}`,
|
||||
`--disc-port=${config.ports.discPort}`,
|
||||
`--listen-addrs=/ip4/0.0.0.0/tcp/${config.ports.listenPort}`,
|
||||
`--api-port=${config.ports.apiPort}`,
|
||||
`--nat=${nat}`,
|
||||
`--api-cors-origin="*"`,
|
||||
`--bootstrap-node=spr:CiUIAhIhAiJvIcA_ZwPZ9ugVKDbmqwhJZaig5zKyLiuaicRcCGqLEgIDARo8CicAJQgCEiECIm8hwD9nA9n26BUoNuarCEllqKDnMrIuK5qJxFwIaosQ3d6esAYaCwoJBJ_f8zKRAnU6KkYwRAIgM0MvWNJL296kJ9gWvfatfmVvT-A7O2s8Mxp8l9c8EW0CIC-h-H-jBVSgFjg3Eny2u33qF7BDnWFzo7fGfZ7_qc9P`
|
||||
@ -110,7 +96,7 @@ export async function runCodex(config, showNavigationMenu) {
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8080/api/codex/v1/debug/info');
|
||||
const response = await axios.get(`http://localhost:${config.ports.apiPort}/api/codex/v1/debug/info`);
|
||||
if (response.status === 200) {
|
||||
// Check if wallet exists
|
||||
try {
|
||||
@ -128,7 +114,7 @@ export async function runCodex(config, showNavigationMenu) {
|
||||
}
|
||||
|
||||
// Start periodic logging
|
||||
const stopLogging = await startPeriodicLogging();
|
||||
const stopLogging = await startPeriodicLogging(config);
|
||||
|
||||
nodeProcess.on('exit', () => {
|
||||
stopLogging();
|
||||
@ -262,13 +248,13 @@ async function showNodeDetails(data, showNavigationMenu) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkNodeStatus(showNavigationMenu) {
|
||||
export async function checkNodeStatus(config, showNavigationMenu) {
|
||||
try {
|
||||
const nodeRunning = await isNodeRunning();
|
||||
const nodeRunning = await isNodeRunning(config);
|
||||
|
||||
if (nodeRunning) {
|
||||
const spinner = createSpinner('Checking node status...').start();
|
||||
const response = await runCommand('curl http://localhost:8080/api/codex/v1/debug/info');
|
||||
const response = await runCommand(`curl http://localhost:${config.ports.apiPort}/api/codex/v1/debug/info`);
|
||||
spinner.success();
|
||||
|
||||
const data = JSON.parse(response);
|
||||
|
||||
@ -108,16 +108,16 @@ export async function main() {
|
||||
await runCodex(config, showNavigationMenu);
|
||||
return;
|
||||
case '4':
|
||||
await checkNodeStatus(showNavigationMenu);
|
||||
await checkNodeStatus(config, showNavigationMenu);
|
||||
break;
|
||||
case '5':
|
||||
await uploadFile(null, handleCommandLineOperation, showNavigationMenu);
|
||||
await uploadFile(config, null, handleCommandLineOperation, showNavigationMenu);
|
||||
break;
|
||||
case '6':
|
||||
await downloadFile(null, handleCommandLineOperation, showNavigationMenu);
|
||||
await downloadFile(config, null, handleCommandLineOperation, showNavigationMenu);
|
||||
break;
|
||||
case '7':
|
||||
await showLocalFiles(showNavigationMenu);
|
||||
await showLocalFiles(config, showNavigationMenu);
|
||||
break;
|
||||
case '8':
|
||||
await uninstallCodex(config, showNavigationMenu);
|
||||
|
||||
@ -21,9 +21,9 @@ export async function getWalletAddress() {
|
||||
return currentWallet;
|
||||
}
|
||||
|
||||
export async function isNodeRunning() {
|
||||
export async function isNodeRunning(config) {
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8080/api/codex/v1/debug/info');
|
||||
const response = await axios.get(`http://localhost:${config.ports.apiPort}/api/codex/v1/debug/info`);
|
||||
return response.status === 200;
|
||||
} catch (error) {
|
||||
return false;
|
||||
@ -105,12 +105,12 @@ export async function checkDependencies() {
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function startPeriodicLogging() {
|
||||
export async function startPeriodicLogging(config) {
|
||||
const FIFTEEN_MINUTES = 15 * 60 * 1000; // 15 minutes in milliseconds
|
||||
|
||||
const logNodeInfo = async () => {
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8080/api/codex/v1/debug/info');
|
||||
const response = await axios.get(`http://localhost:${config.ports.apiPort}/api/codex/v1/debug/info`);
|
||||
if (response.status === 200) {
|
||||
await logToSupabase(response.data);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user