mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
improve vault manager, refactor vault operations into shared service.
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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 = [];
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user