fix(objectstore): decouple WebDAV targetPath from logical storage key and fix basePath duplication

- WebDAV Put now returns PutResult with driver-agnostic logical relative key (relKey), keeping database records decoupled from mount basePath.
- targetPath mounts logical keys to the remote WebDAV server path, and transparently handles legacy database records containing basePath or duplicate basePath prefixes.
- Make localBackend path resolution resilient to keys with leading slashes or legacy absolute paths outside local root by safely mounting them as relative paths.
- Add comprehensive unit tests for WebDAV targetPath, relKey, end-to-end roundtrip with in-memory WebDAV server, and local storage leading slash handling.
This commit is contained in:
ryan
2026-09-22 14:16:21 +08:00
parent 96abbf180d
commit aad059ab6e
4 changed files with 331 additions and 25 deletions
+15
View File
@@ -48,4 +48,19 @@ func TestLocalBackendRoundTrip(t *testing.T) {
if _, err := backend.Get(ctx, key); err == nil {
t.Errorf("Get(%q) after Delete() returned nil error", key)
}
// Test key with leading slash
slashKey := "/uploads/2026/06/13/slash_test.txt"
putSlashRes, err := backend.Put(ctx, slashKey, bytes.NewBufferString(content), int64(len(content)), "text/plain")
if err != nil {
t.Fatalf("Put(%q) returned error: %v", slashKey, err)
}
if putSlashRes.Key != slashKey {
t.Errorf("Put(%q) key = %q, want %q", slashKey, putSlashRes.Key, slashKey)
}
objSlash, err := backend.Get(ctx, slashKey)
if err != nil {
t.Fatalf("Get(%q) returned error: %v", slashKey, err)
}
_ = objSlash.Body.Close()
}