add env vars for configuring onion and I2P urls

Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
ngn
2025-04-07 04:46:47 +03:00
parent 4eb5ad6ef3
commit 0134bd2ab1
15 changed files with 62 additions and 30 deletions

View File

@ -1,4 +1,6 @@
import { locale_from_browser } from "$lib/locale.js";
import { browser } from "$app/environment";
import { page } from "$app/state";
const colors = [
"yellow",
@ -19,7 +21,7 @@ function color() {
}
function click() {
let audio = new Audio("/click.wav");
let audio = new Audio("/assets/click.wav");
audio.play();
}
@ -39,8 +41,18 @@ function urljoin(url, path = null, query = {}) {
return url.href;
}
function env_url(prefix) {
let host = "";
if (browser) host = window.location.hostname;
if (host.endsWith(".onion")) return import.meta.env["WEBSITE_" + prefix + "_URL_ONION"];
else if (host.endsWith(".i2p")) return import.meta.env["WEBSITE_" + prefix + "_URL_I2P"];
else return import.meta.env["WEBSITE_" + prefix + "_URL_CLEAR"];
}
function app_url(path = null, query = {}) {
return urljoin(import.meta.env.WEBSITE_APP_URL, path, query);
return urljoin(env_url("APP"), path, query);
}
function time_from_ts(ts) {
@ -68,4 +80,4 @@ function date_from_ts(ts) {
}).format(new Date(ts * 1000));
}
export { color, click, urljoin, app_url, time_from_ts, date_from_ts };
export { color, click, urljoin, env_url, app_url, time_from_ts, date_from_ts };