Initial xlxs support
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m25s

This commit is contained in:
Elijah 2026-05-25 09:57:09 -07:00
parent 2648a5ae84
commit 709c13995c
5 changed files with 164 additions and 22 deletions

View file

@ -127,12 +127,16 @@ func (h *OnlyOfficeHandler) CreateBlank(c *fiber.Ctx) error {
req.Name = "Untitled Document"
if req.Type == "slide" {
req.Name = "Untitled Presentation"
} else if req.Type == "cell" {
req.Name = "Untitled Spreadsheet"
}
}
ext := ".docx"
if req.Type == "slide" {
ext = ".pptx"
} else if req.Type == "cell" {
ext = ".xlsx"
}
// Add extension if missing
@ -227,13 +231,15 @@ func (h *OnlyOfficeHandler) CreateFromTemplate(c *fiber.Ctx) error {
})
}
// ListOfficeFiles returns all .docx or .pptx files across the entire storage directory.
// GET /api/onlyoffice/files?type=docx|pptx
// ListOfficeFiles returns all .docx, .pptx, or .xlsx files across the entire storage directory.
// GET /api/onlyoffice/files?type=docx|pptx|xlsx
func (h *OnlyOfficeHandler) ListOfficeFiles(c *fiber.Ctx) error {
fileType := c.Query("type", "docx") // "docx" or "pptx"
fileType := c.Query("type", "docx") // "docx", "pptx", or "xlsx"
ext := ".docx"
if fileType == "pptx" {
ext = ".pptx"
} else if fileType == "xlsx" {
ext = ".xlsx"
}
type OfficeFile struct {
@ -295,6 +301,8 @@ func createBlankOfficeFile(path string, ext string) error {
if ext == ".pptx" {
return writePptxContents(w)
} else if ext == ".xlsx" {
return writeXlsxContents(w)
}
return writeDocxContents(w)
}
@ -458,6 +466,46 @@ func writePptxContents(w *zip.Writer) error {
return nil
}
func writeXlsxContents(w *zip.Writer) error {
files := map[string]string{
"[Content_Types].xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
</Types>`,
"_rels/.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
</Relationships>`,
"xl/workbook.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<sheets>
<sheet name="Sheet1" sheetId="1" r:id="rId1"/>
</sheets>
</workbook>`,
"xl/_rels/workbook.xml.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>
</Relationships>`,
"xl/worksheets/sheet1.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<sheetData/>
</worksheet>`,
}
for name, content := range files {
fw, err := w.Create(name)
if err != nil {
return err
}
if _, err := fw.Write([]byte(content)); err != nil {
return err
}
}
return nil
}
// SignConfig takes the OnlyOffice configuration payload and signs it with the JWT secret
func (h *OnlyOfficeHandler) SignConfig(c *fiber.Ctx) error {
if h.Config.OnlyOfficeJWT == "" {