Feature: default save office documents to a 'Documents' folder
All checks were successful
Automated Container Build / build-and-push (push) Successful in 53s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 53s
This commit is contained in:
parent
ffa2954cd9
commit
e9d1ef0ad6
1 changed files with 12 additions and 4 deletions
|
|
@ -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++
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue