ultisuite-backend/internal/nextcloud/ultidoc_paths.go
R3D347HR4Y 0466a1c169
Some checks are pending
CI / Go tests (push) Waiting to run
CI / Integration tests (push) Waiting to run
CI / DB migrations (push) Waiting to run
wow
2026-06-11 01:22:52 +02:00

30 lines
793 B
Go

package nextcloud
import "strings"
// SidecarPathForSource maps a source document to its TipTap sidecar path,
// e.g. /docs/report.docx → /docs/report.ultidoc.json.
func SidecarPathForSource(sourcePath string) string {
sourcePath = NormalizeClientPath(sourcePath)
dir := "/"
name := strings.TrimPrefix(sourcePath, "/")
if i := strings.LastIndex(name, "/"); i >= 0 {
dir = "/" + name[:i]
name = name[i+1:]
}
base := name
if dot := strings.LastIndex(name, "."); dot > 0 {
base = name[:dot]
}
sidecar := base + ultidocSidecarSuffix
if dir == "/" {
return "/" + sidecar
}
return dir + "/" + sidecar
}
// IsUltidocSidecarPath reports whether path ends with .ultidoc.json.
func IsUltidocSidecarPath(path string) bool {
return IsUltidocSidecarName(fileNameFromPath(path))
}