Files
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

49 lines
1.4 KiB
Go

package store
import (
"errors"
"net/url"
"strings"
)
// DomainLink renders an address relative only when it remains in the source
// Domain. Cross-Domain and cross-instance addresses always carry an origin.
func (s *Store) DomainLink(sourceDomainUUID, destinationDomainUUID, address, scheme string) (string, error) {
address = strings.TrimSpace(address)
if address == "" {
return "", errors.New("link address is required")
}
isObjectAddress := false
for _, prefix := range []string{"uuid:", "rev:", "asset:"} {
isObjectAddress = isObjectAddress || strings.HasPrefix(address, prefix)
}
if parsed, err := url.Parse(address); !isObjectAddress && err == nil && parsed.IsAbs() {
return parsed.String(), nil
}
if !strings.HasPrefix(address, "/") {
for _, prefix := range []string{"uuid:", "rev:", "asset:"} {
if strings.HasPrefix(address, prefix) {
address = "/o/" + address
break
}
}
}
if !strings.HasPrefix(address, "/") {
return "", errors.New("semantic links must be root-relative")
}
if sourceDomainUUID == destinationDomainUUID {
return address, nil
}
if scheme == "" {
scheme = "https"
}
if scheme != "https" && scheme != "http" {
return "", errors.New("link scheme must be http or https")
}
host, err := s.GetDomainEffectiveHost(destinationDomainUUID)
if err != nil {
return "", err
}
return (&url.URL{Scheme: scheme, Host: host, Path: address}).String(), nil
}