Fix UI issues and add Pins and Templates
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m38s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m38s
This commit is contained in:
parent
a361848216
commit
617f8160b2
10 changed files with 281 additions and 59 deletions
|
|
@ -166,6 +166,67 @@ func (h *OnlyOfficeHandler) CreateBlank(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// POST /api/onlyoffice/template
|
||||
func (h *OnlyOfficeHandler) CreateFromTemplate(c *fiber.Ctx) error {
|
||||
var req struct {
|
||||
TemplateName string `json:"template"` // e.g., "apa.docx"
|
||||
}
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "invalid request"})
|
||||
}
|
||||
|
||||
srcPath := filepath.Join("templates", req.TemplateName)
|
||||
if _, err := os.Stat(srcPath); os.IsNotExist(err) {
|
||||
return c.Status(404).JSON(fiber.Map{"error": "template not found"})
|
||||
}
|
||||
|
||||
// Figure out a safe name in root directory
|
||||
baseName := "Untitled Document"
|
||||
ext := ".docx"
|
||||
if strings.HasSuffix(req.TemplateName, ".pptx") {
|
||||
baseName = "Untitled Presentation"
|
||||
ext = ".pptx"
|
||||
}
|
||||
if req.TemplateName == "apa.docx" {
|
||||
baseName = "APA Paper"
|
||||
} else if req.TemplateName == "resume.docx" {
|
||||
baseName = "Resume"
|
||||
}
|
||||
|
||||
finalPath := filepath.Join(h.Config.StorageDir, 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))
|
||||
counter++
|
||||
}
|
||||
|
||||
// Copy the template file
|
||||
srcFile, err := os.Open(srcPath)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "failed to open template"})
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
destFile, err := os.Create(finalPath)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "failed to create destination file"})
|
||||
}
|
||||
defer destFile.Close()
|
||||
|
||||
if _, err := io.Copy(destFile, srcFile); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "failed to copy template data"})
|
||||
}
|
||||
|
||||
relativePath, _ := filepath.Rel(h.Config.StorageDir, finalPath)
|
||||
return c.JSON(fiber.Map{
|
||||
"path": filepath.ToSlash(relativePath),
|
||||
"name": filepath.Base(finalPath),
|
||||
})
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
|
|
|||
Reference in a new issue