2023-06-04 04:28:07 +02:00
|
|
|
import { API_BASE } from "../utils/constants";
|
2023-06-09 20:27:27 +02:00
|
|
|
import { baseHeaders } from "../utils/request";
|
2023-06-04 04:28:07 +02:00
|
|
|
|
|
|
|
const System = {
|
|
|
|
ping: async function () {
|
|
|
|
return await fetch(`${API_BASE}/ping`)
|
|
|
|
.then((res) => res.ok)
|
|
|
|
.catch(() => false);
|
|
|
|
},
|
|
|
|
totalIndexes: async function () {
|
2023-06-09 20:27:27 +02:00
|
|
|
return await fetch(`${API_BASE}/system/system-vectors`, {
|
|
|
|
headers: baseHeaders(),
|
|
|
|
})
|
2023-06-04 04:28:07 +02:00
|
|
|
.then((res) => {
|
|
|
|
if (!res.ok) throw new Error("Could not find indexes.");
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((res) => res.vectorCount)
|
|
|
|
.catch(() => 0);
|
|
|
|
},
|
|
|
|
keys: async function () {
|
|
|
|
return await fetch(`${API_BASE}/setup-complete`)
|
|
|
|
.then((res) => {
|
|
|
|
if (!res.ok) throw new Error("Could not find setup information.");
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((res) => res.results)
|
|
|
|
.catch(() => null);
|
|
|
|
},
|
|
|
|
localFiles: async function () {
|
2023-06-09 20:27:27 +02:00
|
|
|
return await fetch(`${API_BASE}/system/local-files`, {
|
|
|
|
headers: baseHeaders(),
|
|
|
|
})
|
2023-06-04 04:28:07 +02:00
|
|
|
.then((res) => {
|
|
|
|
if (!res.ok) throw new Error("Could not find setup information.");
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((res) => res.localFiles)
|
|
|
|
.catch(() => null);
|
|
|
|
},
|
2023-06-09 20:27:27 +02:00
|
|
|
checkAuth: async function (currentToken = null) {
|
|
|
|
return await fetch(`${API_BASE}/system/check-token`, {
|
|
|
|
headers: baseHeaders(currentToken),
|
|
|
|
})
|
|
|
|
.then((res) => res.ok)
|
|
|
|
.catch(() => false);
|
|
|
|
},
|
|
|
|
requestToken: async function (body) {
|
|
|
|
return await fetch(`${API_BASE}/request-token`, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({ ...body }),
|
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
if (!res.ok) throw new Error("Could not validate login.");
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((res) => res)
|
|
|
|
.catch((e) => {
|
|
|
|
return { valid: false, message: e.message };
|
|
|
|
});
|
|
|
|
},
|
2023-06-17 01:01:27 +02:00
|
|
|
checkDocumentProcessorOnline: async () => {
|
|
|
|
return await fetch(`${API_BASE}/system/document-processing-status`, {
|
|
|
|
headers: baseHeaders(),
|
|
|
|
})
|
|
|
|
.then((res) => res.ok)
|
|
|
|
.catch(() => false);
|
|
|
|
},
|
|
|
|
acceptedDocumentTypes: async () => {
|
|
|
|
return await fetch(`${API_BASE}/system/accepted-document-types`, {
|
|
|
|
headers: baseHeaders(),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => res?.types)
|
|
|
|
.catch(() => null);
|
|
|
|
},
|
2023-06-26 20:38:38 +02:00
|
|
|
updateSystem: async (data) => {
|
|
|
|
return await fetch(`${API_BASE}/system/update-env`, {
|
|
|
|
method: "POST",
|
|
|
|
headers: baseHeaders(),
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
return { newValues: null, error: e.message };
|
|
|
|
});
|
|
|
|
},
|
2023-07-21 00:25:47 +02:00
|
|
|
updateSystemPassword: async (data) => {
|
|
|
|
return await fetch(`${API_BASE}/system/update-password`, {
|
|
|
|
method: "POST",
|
|
|
|
headers: baseHeaders(),
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
return { success: false, error: e.message };
|
|
|
|
});
|
|
|
|
},
|
2023-06-27 02:20:09 +02:00
|
|
|
deleteDocument: async (name, meta) => {
|
|
|
|
return await fetch(`${API_BASE}/system/remove-document`, {
|
|
|
|
method: "DELETE",
|
|
|
|
headers: baseHeaders(),
|
|
|
|
body: JSON.stringify({ name, meta }),
|
|
|
|
})
|
|
|
|
.then((res) => res.ok)
|
|
|
|
.catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
2023-07-15 02:32:30 +02:00
|
|
|
dataExport: async () => {
|
|
|
|
return await fetch(`${API_BASE}/system/data-export`, {
|
|
|
|
method: "GET",
|
|
|
|
headers: baseHeaders(),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => res)
|
|
|
|
.catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
return { filename: null, error: e.message };
|
|
|
|
});
|
|
|
|
},
|
|
|
|
importData: async (formData) => {
|
|
|
|
return await fetch(`${API_BASE}/system/data-import`, {
|
|
|
|
method: "POST",
|
|
|
|
body: formData,
|
|
|
|
headers: baseHeaders(),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => res)
|
|
|
|
.catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
return { success: false, error: e.message };
|
|
|
|
});
|
|
|
|
},
|
2023-06-04 04:28:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default System;
|