remove bloat fonts, get rid of svelte-i18n

Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
ngn
2025-07-24 06:15:19 +03:00
parent bf95c575eb
commit e3692f90b1
53 changed files with 1965 additions and 2616 deletions

View File

@@ -1,51 +1,59 @@
import { browser } from "$app/environment";
import { urljoin } from "$lib/util.js";
const api_version = "v1";
class API {
constructor() {
this.version = "v1";
}
function api_urljoin(path = null, query = {}) {
let api_url = "";
// join given path and queries into an API URL
join(path = null, query = {}) {
let base = "";
if (browser) api_url = urljoin(import.meta.env.WEBSITE_API_PATH, api_version);
else api_url = urljoin(import.meta.env.WEBSITE_API_URL, api_version);
if (browser) {
base = urljoin(import.meta.env.WEBSITE_API_PATH, this.version);
} else {
base = urljoin(import.meta.env.WEBSITE_API_URL, this.version);
}
return urljoin(api_url, path, query);
return urljoin(base, path, query);
}
// check given JSON body for errors
check_err(json) {
if (!("error" in json))
throw new Error('API response is missing the "error" key');
if (json["error"] != "")
throw new Error(`API returned an error: ${json["error"]}`);
if (!("result" in json))
throw new Error('API response is missing the "result" key');
}
// make a HTTP GET request to the given URL
async GET(fetch, url) {
const res = await fetch(url);
const json = await res.json();
this.check_err(json);
return json["result"];
}
// get visitor metrics
async metrics(fetch) {
return await this.GET(fetch, this.join("/metrics"));
}
// get service list
async services(fetch) {
return await this.GET(fetch, this.join("/services"));
}
// get projects list
async projects(fetch) {
return await this.GET(fetch, this.join("/projects"));
}
}
function api_check_err(json) {
if (!("error" in json))
throw new Error('API response is missing the "error" key');
if (json["error"] != "")
throw new Error(`API returned an error: ${json["error"]}`);
if (!("result" in json))
throw new Error('API response is missing the "result" key');
}
async function api_http_get(fetch, url) {
const res = await fetch(url);
const json = await res.json();
api_check_err(json);
return json["result"];
}
async function api_get_metrics(fetch) {
return await api_http_get(fetch, api_urljoin("/metrics"));
}
async function api_get_services(fetch) {
return await api_http_get(fetch, api_urljoin("/services"));
}
async function api_get_projects(fetch) {
return await api_http_get(fetch, api_urljoin("/projects"));
}
export {
api_version,
api_urljoin,
api_get_metrics,
api_get_services,
api_get_projects,
};
const api = new API();
export default api;