Fix UI issues and add Pins and Templates
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m38s

This commit is contained in:
Elijah 2026-05-24 19:30:17 -07:00
parent a361848216
commit 617f8160b2
10 changed files with 281 additions and 59 deletions

7
backend/create_blanks.go Normal file
View file

@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("Running...")
}

View file

@ -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 {

View file

@ -193,6 +193,7 @@ func main() {
// OnlyOffice
protected.Post("/onlyoffice/create", onlyOfficeHandler.CreateBlank)
protected.Post("/onlyoffice/template", onlyOfficeHandler.CreateFromTemplate)
protected.Post("/onlyoffice/sign", onlyOfficeHandler.SignConfig)
protected.Get("/onlyoffice/files", onlyOfficeHandler.ListOfficeFiles)

View file

@ -0,0 +1,7 @@
<html>
<head>
<META NAME="robots" CONTENT="noindex,nofollow">
<script src="/_Incapsula_Resource?SWJIYLWA=5074a744e2e3d891814e9a2dace20bd4,719d34d31c8e3a6e6fffd425f7e032f3">
</script>
<body>
</body></html>

View file

@ -0,0 +1,7 @@
<html>
<head>
<META NAME="robots" CONTENT="noindex,nofollow">
<script src="/_Incapsula_Resource?SWJIYLWA=5074a744e2e3d891814e9a2dace20bd4,719d34d31c8e3a6e6fffd425f7e032f3">
</script>
<body>
</body></html>