documentation server and /doc route

Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
ngn
2025-01-16 07:46:27 +03:00
parent 5fb3c03e40
commit e87764a4c2
40 changed files with 1313 additions and 301 deletions

28
app/src/lib/doc.js Normal file
View File

@@ -0,0 +1,28 @@
import { urljoin } from "$lib/util.js";
function doc_urljoin(path = null, query = {}) {
return urljoin(import.meta.env.APP_DOC_URL, path, query);
}
function doc_check_err(json) {
if ("error" in json) throw new Error(`Documentation server returned an error: ${json["error"]}`);
}
async function doc_http_get(fetch, url) {
const res = await fetch(url);
const json = await res.json();
doc_check_err(json);
return json;
}
async function doc_get_list(fetch) {
return (await doc_http_get(fetch, doc_urljoin("/list")))["list"];
}
async function doc_get(fetch, name) {
let url = doc_urljoin("/get");
url = urljoin(url, name);
return await doc_http_get(fetch, url);
}
export { doc_urljoin, doc_get, doc_get_list };