mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
implement headless sync plugin
This commit is contained in:
68
server/plugins/headless-sync/plugin/src/api.js
Normal file
68
server/plugins/headless-sync/plugin/src/api.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const BASE = "/api/ext/headless-sync";
|
||||
|
||||
async function fetchJson(path, opts = {}) {
|
||||
const res = await fetch(`${BASE}${path}`, opts);
|
||||
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || `Request failed: ${res.status}`);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
function post(path, body) {
|
||||
return fetchJson(path, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
}
|
||||
|
||||
function getStatus() {
|
||||
return fetchJson("/status");
|
||||
}
|
||||
|
||||
function login(token, email, name) {
|
||||
return post("/login", { token, email, name });
|
||||
}
|
||||
|
||||
function logout() {
|
||||
return post("/logout", {});
|
||||
}
|
||||
|
||||
function getRemoteVaults() {
|
||||
return fetchJson("/remote-vaults");
|
||||
}
|
||||
|
||||
function setupSync(vaultId, remoteVault, opts = {}) {
|
||||
return post("/setup", { vaultId, remoteVault, ...opts });
|
||||
}
|
||||
|
||||
function startSync(vaultId) {
|
||||
return post("/start", { vaultId });
|
||||
}
|
||||
|
||||
function stopSync(vaultId) {
|
||||
return post("/stop", { vaultId });
|
||||
}
|
||||
|
||||
function getVaults() {
|
||||
return fetchJson("/vaults");
|
||||
}
|
||||
|
||||
function getLogs(vaultId, limit = 100) {
|
||||
return fetchJson(`/logs?vaultId=${encodeURIComponent(vaultId)}&limit=${limit}`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getStatus,
|
||||
login,
|
||||
logout,
|
||||
getRemoteVaults,
|
||||
setupSync,
|
||||
startSync,
|
||||
stopSync,
|
||||
getVaults,
|
||||
getLogs,
|
||||
};
|
||||
Reference in New Issue
Block a user