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