diff --git a/backend/handlers/onlyoffice.go b/backend/handlers/onlyoffice.go index 87357e5..da17478 100644 --- a/backend/handlers/onlyoffice.go +++ b/backend/handlers/onlyoffice.go @@ -362,12 +362,30 @@ func (h *OnlyOfficeHandler) ListOfficeFiles(c *fiber.Ctx) error { if strings.HasSuffix(strings.ToLower(info.Name()), ext) { relPath, _ := filepath.Rel(h.Config.StorageDir, path) relPathSlash := filepath.ToSlash(relPath) + + chk := checksums[relPathSlash] + if chk == "" { + // Fallback: the path in the database might have a different prefix format + // (e.g. "/test.docx", "./test.docx") or different casing. + cleanRel := filepath.ToSlash(filepath.Clean(relPathSlash)) + cleanRel = strings.TrimPrefix(cleanRel, "/") + + for k, v := range checksums { + cleanK := filepath.ToSlash(filepath.Clean(k)) + cleanK = strings.TrimPrefix(cleanK, "/") + if strings.EqualFold(cleanK, cleanRel) { + chk = v + break + } + } + } + results = append(results, OfficeFile{ Name: info.Name(), Path: relPathSlash, Size: info.Size(), ModTime: info.ModTime().UTC().Format("2006-01-02T15:04:05Z"), - Checksum: checksums[relPathSlash], + Checksum: chk, }) } return nil diff --git a/backend/scratch.go b/backend/scratch.go new file mode 100644 index 0000000..a29f5f2 --- /dev/null +++ b/backend/scratch.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "path/filepath" + "strings" +) + +func main() { + storageDir := `C:\Users\Elijah\Desktop\Drive\data` + path1 := `C:\Users\Elijah\Desktop\Drive\data\test.docx` + path2 := `C:\Users\Elijah\Desktop\Drive\data\folder\test.docx` + + relPath1, _ := filepath.Rel(storageDir, path1) + relPathSlash1 := filepath.ToSlash(relPath1) + + relPath2, _ := filepath.Rel(storageDir, path2) + relPathSlash2 := filepath.ToSlash(relPath2) + + fmt.Printf("Root file: %q -> %q\n", relPath1, relPathSlash1) + fmt.Printf("Sub file: %q -> %q\n", relPath2, relPathSlash2) + + fmt.Printf("Clean . : %q\n", filepath.Clean(".")) + fmt.Printf("Join . and file: %q\n", filepath.Join(".", "test.docx")) +} diff --git a/test_rel.go b/test_rel.go new file mode 100644 index 0000000..feb4d6a Binary files /dev/null and b/test_rel.go differ