79 lines
3.5 KiB
Go
79 lines
3.5 KiB
Go
package web
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-controller/internal/infra"
|
|
)
|
|
|
|
// FileBrowser Quantum deep links (R-75).
|
|
//
|
|
// The template is taken VERBATIM from the shipped frontend router (SPIKE P2, read out of the
|
|
// bundle), not guessed:
|
|
//
|
|
// function Ms(n,t,…){ … let a=q2(t), s=`/files/${encodeURIComponent(n)}${a}` … }
|
|
// q2 = … .map(r=>encodeURIComponent(r)).join("/") // per-SEGMENT encoding
|
|
// function H2(n){ t=i.split("/")[2]; … } // source is the 3rd path segment
|
|
//
|
|
// So a link is constructible server-side from (sourceName, relPath) alone — no internal id, no
|
|
// index, no client-side state.
|
|
//
|
|
// A cold link (no FileBrowser session) is NOT lost: the router guard redirects to
|
|
// /login?redirect=<fullPath> and the login handler navigates back to it. The customer may still have
|
|
// to sign in, which is why the UI copy must not promise one click.
|
|
|
|
// fbSourceRoot is the FileBrowser origin for a customer domain. FileBrowser is published at
|
|
// files.<domain> by the base-infra traefik labels.
|
|
func fbSourceRoot(domain string) string {
|
|
return "https://files." + domain
|
|
}
|
|
|
|
// fileBrowserLink builds a deep link into a named FileBrowser source at relPath.
|
|
//
|
|
// ENCODING TRAP, measured in SPIKE P2 — use url.PathEscape, NEVER url.QueryEscape:
|
|
//
|
|
// "Média & könyvtár" PathEscape=M%C3%A9dia%20&%20k%C3%B6nyvt%C3%A1r QueryEscape=M%C3%A9dia+%26+k%C3%B6nyvt%C3%A1r
|
|
// "a+b" PathEscape=a+b QueryEscape=a%2Bb
|
|
//
|
|
// QueryEscape encodes a space as "+", which inside a PATH segment means a literal plus and breaks
|
|
// the link. PathEscape leaves "&" unescaped, which is correct here: "&" is a legal path sub-delim,
|
|
// and html/template escapes it to "&" in the href attribute, which the browser decodes back to
|
|
// "&". The two escapings compose — so do NOT pre-escape for HTML here.
|
|
//
|
|
// Source names cannot contain "/" (they come from filepath.Base or the ASCII import constant), which
|
|
// is what keeps the router's split("/")[2] round-trip intact.
|
|
func fileBrowserLink(domain, sourceName, relPath string) string {
|
|
var b strings.Builder
|
|
b.WriteString(fbSourceRoot(domain))
|
|
b.WriteString("/files/")
|
|
b.WriteString(url.PathEscape(sourceName))
|
|
for _, seg := range strings.Split(strings.Trim(relPath, "/"), "/") {
|
|
if seg == "" {
|
|
continue
|
|
}
|
|
b.WriteString("/")
|
|
b.WriteString(url.PathEscape(seg))
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
// importFolderLink is the deep link to a drop-zone app's folder inside the canonical import source (through the
|
|
// dashboard's pass, R-1100).
|
|
func importFolderLink(domain, appDir string) string {
|
|
return fileBrowserOpenLink(domain, infra.FileBrowserImportLabel, appDir)
|
|
}
|
|
|
|
// fileBrowserOpenLink is what a dashboard page links to for a FileBrowser folder since R-1100: the dashboard's
|
|
// GET /__files/open, which hands the household's signed-in browser a one-time pass to the file manager, so FileBrowser
|
|
// opens at the folder without its own login (files_sso.go). The folder is fileBrowserLink's path, carried in `to`
|
|
// (query-escaped as a whole; the path keeps its own PathEscape inside). Pinned by TestFileBrowserOpenLink_R1100_*.
|
|
func fileBrowserOpenLink(domain, sourceName, relPath string) string {
|
|
return filesOpenURL(domain, fileBrowserLink(domain, sourceName, relPath))
|
|
}
|
|
|
|
// filesOpenURL turns a files.<domain> link into the dashboard's pass link for the same FileBrowser path.
|
|
func filesOpenURL(domain, link string) string {
|
|
return "https://felhom." + domain + filesOpenPath + "?" + url.Values{"to": {filesPathOf(link, "files."+domain)}}.Encode()
|
|
}
|