improve vault manager, refactor vault operations into shared service.

This commit is contained in:
Nystik
2026-03-18 18:52:38 +01:00
parent 408eb7fb54
commit e1d484fd28
5 changed files with 159 additions and 68 deletions

View File

@@ -1,4 +1,5 @@
import { showVaultManager } from "../ui/vault-manager.js";
import { showVaultManager } from "../../ui/bootstrap.js";
import { vaultService } from "../../services/vault-service.js";
const listeners = new Map();
@@ -44,7 +45,7 @@ const syncHandlers = {
result[v.id] = {
path: "/" + v.id,
ts: Date.now(),
open: v.id === (window.__currentVaultId || ""),
open: v.id === vaultService.getCurrentVaultId(),
};
}
@@ -56,36 +57,20 @@ const syncHandlers = {
const vault = (window.__vaultList || []).find((v) => v.id === id);
if (!vault && id) {
const xhr = new XMLHttpRequest();
xhr.open("POST", "/api/vault/create", false);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({ name: id }));
if (xhr.status >= 400) {
if (!vaultService.createVaultSync(id)) {
return "Failed to create vault";
}
}
const target = window.parent !== window ? window.parent : window;
target.location.href = "/?vault=" + encodeURIComponent(id);
vaultService.openVault(id);
return true;
},
"vault-remove": (vaultPath) => {
const id = (vaultPath || "").replace(/^\/+/, "");
const xhr = new XMLHttpRequest();
xhr.open(
"DELETE",
"/api/vault/remove?vault=" + encodeURIComponent(id),
false,
);
xhr.send();
return xhr.status < 400;
return vaultService.deleteVaultSync(id);
},
"vault-move": (oldPath, newPath) => {

View File

@@ -15,6 +15,7 @@ import * as eventsShim from "./node/events.js";
import * as osShim from "./node/os.js";
import * as netShim from "./node/net.js";
import * as httpShim from "./node/http.js";
import { vaultService } from "../services/vault-service.js";
const DEBUG = true;
const _accessLog = new Map(); // "module.property" -> count
@@ -217,14 +218,7 @@ window.__currentVaultId = _urlParams.get("vault") || "";
(function initVaultList() {
try {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/api/vault/list", false);
xhr.send();
if (xhr.status === 200) {
window.__vaultList = JSON.parse(xhr.responseText);
}
vaultService.listVaultsSync();
} catch (e) {
window.__vaultList = [];
}

View File

@@ -1,8 +0,0 @@
export function showVaultManager() {
if (!document.querySelector(".workspace")) return;
if (document.querySelector(".vault-manager-overlay")) return;
new window.IgnisUI.VaultManager({
target: document.body,
});
}