Feature: default save office documents to a 'Documents' folder
All checks were successful
Automated Container Build / build-and-push (push) Successful in 53s

This commit is contained in:
Elijah 2026-05-25 16:20:46 -07:00
parent ffa2954cd9
commit e9d1ef0ad6

View file

@ -197,15 +197,19 @@ func (h *OnlyOfficeHandler) CreateBlank(c *fiber.Ctx) error {
req.Name += ext
}
// Create Documents directory if it doesn't exist
docsDir := filepath.Join(h.Config.StorageDir, "Documents")
os.MkdirAll(docsDir, 0755)
// Make sure the file name doesn't collide
basePath := filepath.Join(h.Config.StorageDir, req.Name)
basePath := filepath.Join(docsDir, req.Name)
finalPath := basePath
counter := 1
for {
if _, err := os.Stat(finalPath); os.IsNotExist(err) {
break
}
finalPath = filepath.Join(h.Config.StorageDir, fmt.Sprintf("%s (%d)%s", req.Name[:len(req.Name)-len(ext)], counter, ext))
finalPath = filepath.Join(docsDir, fmt.Sprintf("%s (%d)%s", req.Name[:len(req.Name)-len(ext)], counter, ext))
counter++
}
@ -253,13 +257,17 @@ func (h *OnlyOfficeHandler) CreateFromTemplate(c *fiber.Ctx) error {
baseName = "Resume"
}
finalPath := filepath.Join(h.Config.StorageDir, baseName+ext)
// Create Documents directory if it doesn't exist
docsDir := filepath.Join(h.Config.StorageDir, "Documents")
os.MkdirAll(docsDir, 0755)
finalPath := filepath.Join(docsDir, baseName+ext)
counter := 1
for {
if _, err := os.Stat(finalPath); os.IsNotExist(err) {
break
}
finalPath = filepath.Join(h.Config.StorageDir, fmt.Sprintf("%s (%d)%s", baseName, counter, ext))
finalPath = filepath.Join(docsDir, fmt.Sprintf("%s (%d)%s", baseName, counter, ext))
counter++
}