debugging path selection

This commit is contained in:
thatben 2025-02-20 10:04:58 +01:00
parent dc42c557fb
commit c81232637e
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
2 changed files with 46 additions and 35 deletions

View File

@ -11,7 +11,6 @@ import { runCodex, checkNodeStatus } from './handlers/nodeHandlers.js';
import { showInfoMessage } from './utils/messages.js'; import { showInfoMessage } from './utils/messages.js';
import { loadConfig } from './services/config.js'; import { loadConfig } from './services/config.js';
import { showConfigMenu } from './configmenu.js'; import { showConfigMenu } from './configmenu.js';
import {filesystemSync} from 'fs-filesystem';
async function showNavigationMenu() { async function showNavigationMenu() {
console.log('\n') console.log('\n')
@ -53,20 +52,6 @@ function handleExit() {
} }
export async function main() { export async function main() {
const result = filesystemSync();
console.log('devices', JSON.stringify(result));
Object.keys(result).forEach(function(key) {
var val = result[key];
val.volumes.forEach(function(volume) {
console.log("mounting point: " + volume.mountPoint);
});
});
return;
const commandArgs = parseCommandLineArgs(); const commandArgs = parseCommandLineArgs();
if (commandArgs) { if (commandArgs) {
switch (commandArgs.command) { switch (commandArgs.command) {

View File

@ -15,15 +15,21 @@ function showMsg(msg) {
})); }));
} }
// function getAvailableRoots() { function getAvailableRoots() {
// const platform = os.platform(); const devices = filesystemSync();
// if (platform === 'win32') { var mountPoints = [];
// const result = await runCommand('for /f "delims=" %a in (\'curl -s --ssl-reqd ip.codex.storage\') do @echo %a'); Object.keys(devices).forEach(function(key) {
// nat = result.trim(); var val = devices[key];
// } else { val.volumes.forEach(function(volume) {
// nat = await runCommand('curl -s https://ip.codex.storage'); mountPoints.push(volume.mountPoint);
// } });
// } });
if (mountPoints.length < 1) {
throw new Error("Failed to detect file system devices.");
}
return mountPoints;
}
function splitPath(str) { function splitPath(str) {
return str.replaceAll("\\", "/").split("/"); return str.replaceAll("\\", "/").split("/");
@ -65,6 +71,19 @@ function showCurrent(currentPath) {
} }
} }
function hasValidRoot(roots, checkPath) {
if (checkPath.length < 1) return false;
var result = false;
roots.forEach(function(root) {
if (root.toLowerCase() == checkPath[0].toLowerCase()) {
console.log("valid root: " + combine(checkPath));
result = true;
}
});
if (!result) console.log("invalid root: " + combine(checkPath));
return result;
}
async function showMain(currentPath) { async function showMain(currentPath) {
showCurrent(currentPath); showCurrent(currentPath);
const { choice } = await inquirer.prompt([ const { choice } = await inquirer.prompt([
@ -92,23 +111,28 @@ async function showMain(currentPath) {
} }
export async function showPathSelector(startingPath, pathMustExist) { export async function showPathSelector(startingPath, pathMustExist) {
const roots = getAvailableRoots();
var currentPath = splitPath(startingPath); var currentPath = splitPath(startingPath);
if (!hasValidRoot(roots, currentPath)) {
currentPath = [roots[0]];
}
while (true) { while (true) {
const choice = await showMain(currentPath); const choice = await showMain(currentPath);
var newCurrentPath = currentPath;
switch (choice.split('.')[0]) { switch (choice.split('.')[0]) {
case '1': case '1':
currentPath = await enterPath(currentPath, pathMustExist); newCurrentPath = await enterPath(currentPath, pathMustExist);
break; break;
case '2': case '2':
currentPath = upOne(currentPath); newCurrentPath = upOne(currentPath);
break; break;
case '3': case '3':
currentPath = await downOne(currentPath); newCurrentPath = await downOne(currentPath);
break; break;
case '4': case '4':
currentPath = await createSubDir(currentPath, pathMustExist); newCurrentPath = await createSubDir(currentPath, pathMustExist);
break; break;
case '5': case '5':
if (pathMustExist && !isDir(combine(currentPath))) { if (pathMustExist && !isDir(combine(currentPath))) {
@ -120,6 +144,12 @@ export async function showPathSelector(startingPath, pathMustExist) {
case '6': case '6':
return combine(currentPath); return combine(currentPath);
} }
if (hasValidRoot(roots, newCurrentPath)) {
currentPath = newCurrentPath;
} else {
console.log("Selected path has no valid root.");
}
} }
} }
@ -158,17 +188,13 @@ function isSubDir(currentPath, entry) {
function getSubDirOptions(currentPath) { function getSubDirOptions(currentPath) {
const fullPath = combine(currentPath); const fullPath = combine(currentPath);
currentPath.forEach(function(part) {
console.log("part: '" + part + "'");
});
console.log("current: '" + fullPath + "'");
const entries = fs.readdirSync(fullPath); const entries = fs.readdirSync(fullPath);
var result = []; var result = [];
var counter = 1; var counter = 1;
entries.forEach(function(entry) { entries.forEach(function(entry) {
console.log("entry: " + entry);
if (isSubDir(currentPath, entry)) { if (isSubDir(currentPath, entry)) {
result.push(counter + ". " + entry); result.push(counter + '. ' + entry);
counter = counter + 1;
} }
}); });
return result; return result;
@ -194,7 +220,7 @@ async function downOne(currentPath) {
return currentPath; return currentPath;
}); });
const subDir = choice.slice(3); const subDir = choice.split('. ')[1];
return [...currentPath, subDir]; return [...currentPath, subDir];
} }