Fix: add missing ListOfficeFiles handler
Some checks failed
Automated Container Build / build-and-push (push) Failing after 51s

This commit is contained in:
Elijah 2026-05-24 13:19:40 -07:00
parent 51850e75a2
commit eaef97b70a

View file

@ -165,6 +165,59 @@ func (h *OnlyOfficeHandler) CreateBlank(c *fiber.Ctx) error {
})
}
// ListOfficeFiles returns all .docx or .pptx files across the entire storage directory.
// GET /api/onlyoffice/files?type=docx|pptx
func (h *OnlyOfficeHandler) ListOfficeFiles(c *fiber.Ctx) error {
fileType := c.Query("type", "docx") // "docx" or "pptx"
ext := ".docx"
if fileType == "pptx" {
ext = ".pptx"
}
type OfficeFile struct {
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
ModTime string `json:"mod_time"`
}
var results []OfficeFile
filepath.Walk(h.Config.StorageDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if info.IsDir() {
base := filepath.Base(path)
if strings.HasPrefix(base, ".") && path != h.Config.StorageDir {
return filepath.SkipDir
}
return nil
}
if strings.HasSuffix(strings.ToLower(info.Name()), ext) {
relPath, _ := filepath.Rel(h.Config.StorageDir, path)
results = append(results, OfficeFile{
Name: info.Name(),
Path: filepath.ToSlash(relPath),
Size: info.Size(),
ModTime: info.ModTime().UTC().Format("2006-01-02T15:04:05Z"),
})
}
return nil
})
if results == nil {
results = []OfficeFile{}
}
return c.JSON(fiber.Map{
"files": results,
"count": len(results),
})
}
// createBlankOfficeFile creates a minimal valid .docx or .pptx file.
// These formats are ZIP archives containing XML files following the
// Office Open XML (OOXML) standard.