Fix: add missing ListOfficeFiles handler
Some checks failed
Automated Container Build / build-and-push (push) Failing after 51s
Some checks failed
Automated Container Build / build-and-push (push) Failing after 51s
This commit is contained in:
parent
51850e75a2
commit
eaef97b70a
1 changed files with 53 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Reference in a new issue