mirror of
https://github.com/logos-storage/logos-storage-installer.git
synced 2026-01-05 15:03:06 +00:00
updates the config menu
This commit is contained in:
parent
280b00802b
commit
c947a71167
@ -29,7 +29,6 @@ import { ConfigMenu } from "./ui/configMenu.js";
|
||||
import { PathSelector } from "./utils/pathSelector.js";
|
||||
import { NumberSelector } from "./utils/numberSelector.js";
|
||||
import { MenuLoop } from "./utils/menuLoop.js";
|
||||
import { DataDirMover } from "./utils/dataDirMover.js";
|
||||
import { Installer } from "./handlers/installer.js";
|
||||
import { ShellService } from "./services/shellService.js";
|
||||
import { OsService } from "./services/osService.js";
|
||||
@ -125,9 +124,7 @@ export async function main() {
|
||||
uiService,
|
||||
new MenuLoop(),
|
||||
configService,
|
||||
pathSelector,
|
||||
numberSelector,
|
||||
new DataDirMover(fsService, uiService),
|
||||
);
|
||||
const processControl = new ProcessControl(
|
||||
configService,
|
||||
|
||||
@ -1,39 +1,21 @@
|
||||
export class ConfigMenu {
|
||||
constructor(
|
||||
uiService,
|
||||
menuLoop,
|
||||
configService,
|
||||
pathSelector,
|
||||
numberSelector,
|
||||
dataDirMover,
|
||||
) {
|
||||
constructor(uiService, menuLoop, configService, numberSelector) {
|
||||
this.ui = uiService;
|
||||
this.loop = menuLoop;
|
||||
this.configService = configService;
|
||||
this.pathSelector = pathSelector;
|
||||
this.numberSelector = numberSelector;
|
||||
this.dataDirMover = dataDirMover;
|
||||
|
||||
this.loop.initialize(this.showConfigMenu);
|
||||
}
|
||||
|
||||
show = async () => {
|
||||
this.config = this.configService.get();
|
||||
this.originalDataDir = this.config.dataDir;
|
||||
this.ui.showInfoMessage("Codex Configuration");
|
||||
await this.loop.showLoop();
|
||||
};
|
||||
|
||||
showConfigMenu = async () => {
|
||||
await this.ui.askMultipleChoice("Select to edit:", [
|
||||
{
|
||||
label: `Data path = "${this.config.dataDir}"`,
|
||||
action: this.editDataDir,
|
||||
},
|
||||
{
|
||||
label: `Logs path = "${this.config.logsDir}"`,
|
||||
action: this.editLogsDir,
|
||||
},
|
||||
{
|
||||
label: `Storage quota = ${this.bytesAmountToString(this.config.storageQuota)}`,
|
||||
action: this.editStorageQuota,
|
||||
@ -78,20 +60,6 @@ export class ConfigMenu {
|
||||
return `${numBytes} Bytes (${value} ${units[index]})`;
|
||||
};
|
||||
|
||||
editDataDir = async () => {
|
||||
this.config.dataDir = await this.pathSelector.show(
|
||||
this.config.dataDir,
|
||||
false,
|
||||
);
|
||||
};
|
||||
|
||||
editLogsDir = async () => {
|
||||
this.config.logsDir = await this.pathSelector.show(
|
||||
this.config.logsDir,
|
||||
true,
|
||||
);
|
||||
};
|
||||
|
||||
editStorageQuota = async () => {
|
||||
this.ui.showInfoMessage("You can use: 'GB' or 'gb', etc.");
|
||||
const newQuota = await this.numberSelector.show(
|
||||
@ -148,15 +116,6 @@ export class ConfigMenu {
|
||||
};
|
||||
|
||||
saveChangesAndExit = async () => {
|
||||
if (this.config.dataDir !== this.originalDataDir) {
|
||||
// The Codex data-dir is a little special.
|
||||
// Use a dedicated module to move it.
|
||||
await this.dataDirMover.moveDataDir(
|
||||
this.originalDataDir,
|
||||
this.config.dataDir,
|
||||
);
|
||||
}
|
||||
|
||||
this.configService.saveConfig();
|
||||
this.ui.showInfoMessage("Configuration changes saved.");
|
||||
this.loop.stopLoop();
|
||||
|
||||
@ -3,10 +3,8 @@ import { ConfigMenu } from "./configMenu.js";
|
||||
import { mockUiService } from "../__mocks__/service.mocks.js";
|
||||
import { mockConfigService } from "../__mocks__/service.mocks.js";
|
||||
import {
|
||||
mockPathSelector,
|
||||
mockNumberSelector,
|
||||
mockMenuLoop,
|
||||
mockDataDirMover,
|
||||
} from "../__mocks__/utils.mocks.js";
|
||||
|
||||
describe("ConfigMenu", () => {
|
||||
@ -30,9 +28,7 @@ describe("ConfigMenu", () => {
|
||||
mockUiService,
|
||||
mockMenuLoop,
|
||||
mockConfigService,
|
||||
mockPathSelector,
|
||||
mockNumberSelector,
|
||||
mockDataDirMover,
|
||||
);
|
||||
});
|
||||
|
||||
@ -59,11 +55,6 @@ describe("ConfigMenu", () => {
|
||||
expect(configMenu.config).toEqual(config);
|
||||
});
|
||||
|
||||
it("sets the original datadir field", async () => {
|
||||
await configMenu.show();
|
||||
expect(configMenu.originalDataDir).toEqual(config.dataDir);
|
||||
});
|
||||
|
||||
describe("config menu options", () => {
|
||||
beforeEach(() => {
|
||||
configMenu.config = config;
|
||||
@ -74,14 +65,6 @@ describe("ConfigMenu", () => {
|
||||
expect(mockUiService.askMultipleChoice).toHaveBeenCalledWith(
|
||||
"Select to edit:",
|
||||
[
|
||||
{
|
||||
label: `Data path = "${mockConfigService.get().dataDir}"`,
|
||||
action: configMenu.editDataDir,
|
||||
},
|
||||
{
|
||||
label: `Logs path = "${mockConfigService.get().logsDir}"`,
|
||||
action: configMenu.editLogsDir,
|
||||
},
|
||||
{
|
||||
label: `Storage quota = 1073741824 Bytes (1024 MB)`,
|
||||
action: configMenu.editStorageQuota,
|
||||
@ -110,24 +93,6 @@ describe("ConfigMenu", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("edits the logs directory", async () => {
|
||||
const originalPath = config.dataDir;
|
||||
mockPathSelector.show.mockResolvedValue("/new-data");
|
||||
await configMenu.editDataDir();
|
||||
|
||||
expect(mockPathSelector.show).toHaveBeenCalledWith(originalPath, false);
|
||||
expect(configMenu.config.dataDir).toEqual("/new-data");
|
||||
});
|
||||
|
||||
it("edits the logs directory", async () => {
|
||||
const originalPath = config.logsDir;
|
||||
mockPathSelector.show.mockResolvedValue("/new-logs");
|
||||
await configMenu.editLogsDir();
|
||||
|
||||
expect(mockPathSelector.show).toHaveBeenCalledWith(originalPath, true);
|
||||
expect(configMenu.config.logsDir).toEqual("/new-logs");
|
||||
});
|
||||
|
||||
it("edits the storage quota", async () => {
|
||||
const originalQuota = config.storageQuota;
|
||||
const newQuota = 200 * 1024 * 1024;
|
||||
@ -249,19 +214,6 @@ describe("ConfigMenu", () => {
|
||||
expect(mockMenuLoop.stopLoop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls the dataDirMover when the new datadir is not equal to the original dataDir when saving changes", async () => {
|
||||
config.dataDir = "/original-data";
|
||||
await configMenu.show();
|
||||
|
||||
configMenu.config.dataDir = "/new-data";
|
||||
await configMenu.saveChangesAndExit();
|
||||
|
||||
expect(mockDataDirMover.moveDataDir).toHaveBeenCalledWith(
|
||||
configMenu.originalDataDir,
|
||||
configMenu.config.dataDir,
|
||||
);
|
||||
});
|
||||
|
||||
it("discards changes and exits", async () => {
|
||||
await configMenu.discardChangesAndExit();
|
||||
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
export class DataDirMover {
|
||||
constructor(fsService, uiService) {
|
||||
this.fs = fsService;
|
||||
this.ui = uiService;
|
||||
}
|
||||
|
||||
moveDataDir = (oldPath, newPath) => {
|
||||
if (oldPath === newPath) return;
|
||||
|
||||
// The Codex dataDir is a little strange:
|
||||
// If the old one is empty: The new one should not exist, so that codex creates it with the correct security permissions.
|
||||
// If the old one does exist: We move it.
|
||||
|
||||
if (this.fs.isDir(oldPath)) {
|
||||
this.moveDir(oldPath, newPath);
|
||||
} else {
|
||||
this.ensureDoesNotExist(newPath);
|
||||
}
|
||||
};
|
||||
|
||||
moveDir = (oldPath, newPath) => {
|
||||
this.ui.showInfoMessage(
|
||||
"Moving Codex data folder...\n" +
|
||||
`From: "${oldPath}"\n` +
|
||||
`To: "${newPath}"`,
|
||||
);
|
||||
|
||||
try {
|
||||
this.fs.moveDir(oldPath, newPath);
|
||||
} catch (error) {
|
||||
console.log(
|
||||
this.ui.showErrorMessage(
|
||||
"Error while moving dataDir: " + error.message,
|
||||
),
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
ensureDoesNotExist = (path) => {
|
||||
if (this.fs.isDir(path)) {
|
||||
console.log(
|
||||
this.ui.showInfoMessage(
|
||||
"Warning: the selected data path already exists.\n" +
|
||||
`New data path = "${path}"\n` +
|
||||
"Codex may overwrite data in this folder.\n" +
|
||||
"Codex will fail to start if this folder does not have the required\n" +
|
||||
"security permissions.",
|
||||
),
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user