From e9d1ef0ad6692f98327a2231bdc7e49751215f7b Mon Sep 17 00:00:00 2001 From: Elijah Date: Mon, 25 May 2026 16:20:46 -0700 Subject: [PATCH] Feature: default save office documents to a 'Documents' folder --- backend/handlers/onlyoffice.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/handlers/onlyoffice.go b/backend/handlers/onlyoffice.go index e804a2d..a98260b 100644 --- a/backend/handlers/onlyoffice.go +++ b/backend/handlers/onlyoffice.go @@ -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++ }