fix: atto links (relative)

This commit is contained in:
trisua 2025-07-12 00:07:37 -04:00
parent 4d49fc3cdf
commit 6af56ed2b2

View file

@ -31,7 +31,9 @@ function fix_atto_links() {
if (TETRATTO_LINK_HANDLER_CTX === "embed") {
// relative links for embeds
const path = window.location.pathname.slice("/api/v1/net/".length);
const path = window.location.pathname
.replace("atto://", "")
.slice("/api/v1/net/".length);
function fix_element(
selector = "a",
@ -43,15 +45,19 @@ function fix_atto_links() {
continue;
}
let x = new URL(y[property]).pathname;
const p = new URL(y[property]).pathname.replace("atto://", "");
let x = p.startsWith("/api/v1/net/")
? p.replace("/api/v1/net/", "")
: p.startsWith("/")
? `${path.split("/")[0]}${p}`
: p;
if (!x.includes(".html")) {
x = `${x}/index.html`;
}
if (relative) {
y[property] =
`atto://${path.replace("atto://", "").split("/")[0]}${x}`;
y[property] = `atto://${x}`;
} else {
y[property] =
`/api/v1/net/${path.replace("atto://", "").split("/")[0]}${x}?s=${globalThis.SECRET_SESSION}`;
@ -107,7 +113,6 @@ function fix_atto_links() {
}
const href = structuredClone(anchor.href);
anchor.addEventListener("click", () => {
if (TETRATTO_LINK_HANDLER_CTX === "net") {
window.location.href = `/net/${href.replace("atto://", "")}`;