new api
This commit is contained in:
@@ -1,16 +1,15 @@
|
|||||||
/* ─── Constants ──────────────────────────────────────────────────── */
|
/* ─── Constants ──────────────────────────────────────────────────── */
|
||||||
const WEBHOOK_URL =
|
const API_BASE = "https://admin.derez.ai";
|
||||||
"https://n8n.derez.ai/webhook/4ad0c89f-ab8c-45ee-bad1-9321ce94dd64";
|
|
||||||
const INSTANCES_URL =
|
/* ─── API route paths ────────────────────────────────────────────── */
|
||||||
"https://n8n.derez.ai/webhook/bb369f27-244c-4f8a-869b-f787050619a2";
|
const ROUTES = {
|
||||||
const BACKUP_URL =
|
auth: "/account/login",
|
||||||
"https://n8n.derez.ai/webhook/69c0c632-df3b-457f-affe-b725f217f9a2";
|
dns: "/admin/dns",
|
||||||
const SERVERS_URL =
|
instances: "/admin/instance",
|
||||||
"https://n8n.derez.ai/webhook/78c0c2b8-e497-4d44-8f26-fec34217513c";
|
backup: "/admin/backup-repo",
|
||||||
const KEYS_URL =
|
servers: "/admin/server",
|
||||||
"https://n8n.derez.ai/webhook/a001374f-d8c0-4430-9b47-9f1e9ab134c3";
|
keys: "/admin/key",
|
||||||
const AUTH_URL =
|
};
|
||||||
"https://n8n.derez.ai/webhook/e256310a-6627-45ba-a221-599751943fe6";
|
|
||||||
|
|
||||||
/* ─── State ──────────────────────────────────────────────────────── */
|
/* ─── State ──────────────────────────────────────────────────────── */
|
||||||
let dnsRecords = [];
|
let dnsRecords = [];
|
||||||
@@ -55,8 +54,11 @@ async function apiFetch(url, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ─── API helpers ────────────────────────────────────────────────── */
|
/* ─── API helpers ────────────────────────────────────────────────── */
|
||||||
function getApiUrl() {
|
function getApiBase() {
|
||||||
return localStorage.getItem("al_url") || WEBHOOK_URL;
|
return (localStorage.getItem("al_url") || API_BASE).replace(/\/$/, "");
|
||||||
|
}
|
||||||
|
function apiUrl(route) {
|
||||||
|
return getApiBase() + route;
|
||||||
}
|
}
|
||||||
function apiHeaders() {
|
function apiHeaders() {
|
||||||
return { "Content-Type": "application/json" };
|
return { "Content-Type": "application/json" };
|
||||||
@@ -108,7 +110,7 @@ async function doSignIn() {
|
|||||||
btn.innerHTML = `<div class="spinner" style="width:14px;height:14px;"></div> Signing in…`;
|
btn.innerHTML = `<div class="spinner" style="width:14px;height:14px;"></div> Signing in…`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(AUTH_URL, {
|
const res = await fetch(apiUrl(ROUTES.auth), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ email, password }),
|
body: JSON.stringify({ email, password }),
|
||||||
@@ -139,7 +141,7 @@ async function doSignIn() {
|
|||||||
/* ─── Sign Out ───────────────────────────────────────────────────── */
|
/* ─── Sign Out ───────────────────────────────────────────────────── */
|
||||||
function doSignOut() {
|
function doSignOut() {
|
||||||
if (currentSession) {
|
if (currentSession) {
|
||||||
fetch(AUTH_URL, {
|
fetch(apiUrl(ROUTES.auth), {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -269,7 +271,7 @@ async function dnsLoadRecords() {
|
|||||||
const tbody = document.getElementById("dns-table-body");
|
const tbody = document.getElementById("dns-table-body");
|
||||||
tbody.innerHTML = `<tr><td colspan="6"><div class="empty-state"><div class="spinner"></div><p style="margin-top:12px;">Loading…</p></div></td></tr>`;
|
tbody.innerHTML = `<tr><td colspan="6"><div class="empty-state"><div class="spinner"></div><p style="margin-top:12px;">Loading…</p></div></td></tr>`;
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(getApiUrl(), {
|
const res = await apiFetch(apiUrl(ROUTES.dns), {
|
||||||
headers: apiHeaders(),
|
headers: apiHeaders(),
|
||||||
});
|
});
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||||
@@ -383,7 +385,7 @@ async function dnsDeleteRecord(btn) {
|
|||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(getApiUrl(), {
|
const res = await apiFetch(apiUrl(ROUTES.dns), {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: apiHeaders(),
|
headers: apiHeaders(),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -421,7 +423,7 @@ async function dnsAddRecord() {
|
|||||||
btn.innerHTML = `<div class="spinner" style="width:14px;height:14px;"></div> Adding…`;
|
btn.innerHTML = `<div class="spinner" style="width:14px;height:14px;"></div> Adding…`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(getApiUrl(), {
|
const res = await apiFetch(apiUrl(ROUTES.dns), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: apiHeaders(),
|
headers: apiHeaders(),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -452,13 +454,17 @@ function settingsSave() {
|
|||||||
const url = document.getElementById("setting-url").value.trim();
|
const url = document.getElementById("setting-url").value.trim();
|
||||||
if (url) {
|
if (url) {
|
||||||
localStorage.setItem("al_url", url);
|
localStorage.setItem("al_url", url);
|
||||||
toast("Webhook URL saved", "success");
|
toast("API base URL saved", "success");
|
||||||
} else toast("Enter a URL to save", "warning");
|
} else {
|
||||||
|
localStorage.removeItem("al_url");
|
||||||
|
document.getElementById("setting-url").value = "";
|
||||||
|
toast("Reverted to default: " + API_BASE, "info");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function settingsTest() {
|
async function settingsTest() {
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(getApiUrl(), {
|
const res = await apiFetch(apiUrl(ROUTES.dns), {
|
||||||
headers: apiHeaders(),
|
headers: apiHeaders(),
|
||||||
});
|
});
|
||||||
if (res.ok) toast("Connection OK — HTTP " + res.status, "success");
|
if (res.ok) toast("Connection OK — HTTP " + res.status, "success");
|
||||||
@@ -521,7 +527,9 @@ async function instancesLoadRecords() {
|
|||||||
const tbody = document.getElementById("inst-table-body");
|
const tbody = document.getElementById("inst-table-body");
|
||||||
tbody.innerHTML = `<tr><td colspan="9"><div class="empty-state"><div class="spinner"></div><p style="margin-top:12px;">Loading…</p></div></td></tr>`;
|
tbody.innerHTML = `<tr><td colspan="9"><div class="empty-state"><div class="spinner"></div><p style="margin-top:12px;">Loading…</p></div></td></tr>`;
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(INSTANCES_URL, { headers: apiHeaders() });
|
const res = await apiFetch(apiUrl(ROUTES.instances), {
|
||||||
|
headers: apiHeaders(),
|
||||||
|
});
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
// Normalise: [{data:[...]}, ...], plain array, {data:[...]}, or single object
|
// Normalise: [{data:[...]}, ...], plain array, {data:[...]}, or single object
|
||||||
@@ -663,7 +671,7 @@ async function instancesDelete(btn) {
|
|||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(INSTANCES_URL, {
|
const res = await apiFetch(apiUrl(ROUTES.instances), {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: apiHeaders(),
|
headers: apiHeaders(),
|
||||||
body: JSON.stringify({ uuid }),
|
body: JSON.stringify({ uuid }),
|
||||||
@@ -721,7 +729,7 @@ async function instancesSaveEdit() {
|
|||||||
btn.innerHTML = `<div class="spinner" style="width:14px;height:14px;"></div> Saving…`;
|
btn.innerHTML = `<div class="spinner" style="width:14px;height:14px;"></div> Saving…`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(INSTANCES_URL, {
|
const res = await apiFetch(apiUrl(ROUTES.instances), {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: apiHeaders(),
|
headers: apiHeaders(),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -753,7 +761,9 @@ async function backupLoadRecords() {
|
|||||||
const tbody = document.getElementById("backup-table-body");
|
const tbody = document.getElementById("backup-table-body");
|
||||||
tbody.innerHTML = `<tr><td colspan="7"><div class="empty-state"><div class="spinner"></div><p style="margin-top:12px;">Loading…</p></div></td></tr>`;
|
tbody.innerHTML = `<tr><td colspan="7"><div class="empty-state"><div class="spinner"></div><p style="margin-top:12px;">Loading…</p></div></td></tr>`;
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(BACKUP_URL, { headers: apiHeaders() });
|
const res = await apiFetch(apiUrl(ROUTES.backup), {
|
||||||
|
headers: apiHeaders(),
|
||||||
|
});
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
// Normalise:
|
// Normalise:
|
||||||
@@ -848,7 +858,7 @@ async function backupDelete(btn) {
|
|||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(BACKUP_URL, {
|
const res = await apiFetch(apiUrl(ROUTES.backup), {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: apiHeaders(),
|
headers: apiHeaders(),
|
||||||
body: JSON.stringify({ id }),
|
body: JSON.stringify({ id }),
|
||||||
@@ -886,7 +896,9 @@ async function serversLoadData() {
|
|||||||
document.getElementById("server-dashboard").innerHTML =
|
document.getElementById("server-dashboard").innerHTML =
|
||||||
`<div class="empty-state"><div class="spinner"></div><p style="margin-top:12px">Loading…</p></div>`;
|
`<div class="empty-state"><div class="spinner"></div><p style="margin-top:12px">Loading…</p></div>`;
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(SERVERS_URL, { headers: apiHeaders() });
|
const res = await apiFetch(apiUrl(ROUTES.servers), {
|
||||||
|
headers: apiHeaders(),
|
||||||
|
});
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
const raw = Array.isArray(json) ? json : [json];
|
const raw = Array.isArray(json) ? json : [json];
|
||||||
@@ -1255,7 +1267,7 @@ async function keysLoadRecords() {
|
|||||||
const tbody = document.getElementById("keys-table-body");
|
const tbody = document.getElementById("keys-table-body");
|
||||||
tbody.innerHTML = `<tr><td colspan="8"><div class="empty-state"><div class="spinner"></div><p style="margin-top:12px;">Loading…</p></div></td></tr>`;
|
tbody.innerHTML = `<tr><td colspan="8"><div class="empty-state"><div class="spinner"></div><p style="margin-top:12px;">Loading…</p></div></td></tr>`;
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(KEYS_URL, { headers: apiHeaders() });
|
const res = await apiFetch(apiUrl(ROUTES.keys), { headers: apiHeaders() });
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
// Support both [{data:[...]}, ...] and {data:[...]} and flat array
|
// Support both [{data:[...]}, ...] and {data:[...]} and flat array
|
||||||
@@ -1335,7 +1347,7 @@ async function keysDelete(btn) {
|
|||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch(KEYS_URL, {
|
const res = await apiFetch(apiUrl(ROUTES.keys), {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: apiHeaders(),
|
headers: apiHeaders(),
|
||||||
body: JSON.stringify({ name }),
|
body: JSON.stringify({ name }),
|
||||||
|
|||||||
+2
-2
@@ -676,11 +676,11 @@
|
|||||||
class="form-group"
|
class="form-group"
|
||||||
style="grid-column: 1/-1"
|
style="grid-column: 1/-1"
|
||||||
>
|
>
|
||||||
<label>Webhook Base URL</label>
|
<label>API Base URL</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="setting-url"
|
id="setting-url"
|
||||||
placeholder="https://…"
|
placeholder="https://admin.derez.ai"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user