Files
filebrowser/http/craft_templates.go

61 lines
6.7 KiB
Go

package fbhttp
import (
"archive/zip"
"bytes"
"fmt"
"sort"
)
// Small standards-based packages, with no macros, external links or sample data.
func blankOfficeDocument(id string) ([]byte, error) {
const relsNS = `http://schemas.openxmlformats.org/package/2006/relationships`
const officeNS = `http://schemas.openxmlformats.org/officeDocument/2006/relationships/`
entries := map[string]string{}
main := "word/document.xml"
contentType := "wordprocessingml.document"
if id == "wordcraft" {
entries[main] = `<?xml version="1.0" encoding="UTF-8"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p/><w:sectPr><w:pgSz w:w="11906" w:h="16838"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"/></w:sectPr></w:body></w:document>`
} else {
main, contentType = "ppt/presentation.xml", "presentationml.presentation"
const pns = `xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"`
const tree = `<p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr></p:spTree>`
entries[main] = `<p:presentation ` + pns + `><p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst><p:sldIdLst><p:sldId id="256" r:id="rId2"/></p:sldIdLst><p:sldSz cx="12192000" cy="6858000"/><p:notesSz cx="6858000" cy="9144000"/></p:presentation>`
entries["ppt/_rels/presentation.xml.rels"] = `<Relationships xmlns="` + relsNS + `"><Relationship Id="rId1" Type="` + officeNS + `slideMaster" Target="slideMasters/slideMaster1.xml"/><Relationship Id="rId2" Type="` + officeNS + `slide" Target="slides/slide1.xml"/></Relationships>`
entries["ppt/slides/slide1.xml"] = `<p:sld ` + pns + `><p:cSld>` + tree + `</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sld>`
entries["ppt/slides/_rels/slide1.xml.rels"] = `<Relationships xmlns="` + relsNS + `"><Relationship Id="rId1" Type="` + officeNS + `slideLayout" Target="../slideLayouts/slideLayout1.xml"/></Relationships>`
entries["ppt/slideLayouts/slideLayout1.xml"] = `<p:sldLayout ` + pns + ` type="blank" preserve="1"><p:cSld name="Blank">` + tree + `</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sldLayout>`
entries["ppt/slideLayouts/_rels/slideLayout1.xml.rels"] = `<Relationships xmlns="` + relsNS + `"><Relationship Id="rId1" Type="` + officeNS + `slideMaster" Target="../slideMasters/slideMaster1.xml"/></Relationships>`
entries["ppt/slideMasters/slideMaster1.xml"] = `<p:sldMaster ` + pns + `><p:cSld>` + tree + `</p:cSld><p:clrMap accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" bg1="lt1" bg2="lt2" folHlink="folHlink" hlink="hlink" tx1="dk1" tx2="dk2"/><p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst><p:txStyles><p:titleStyle/><p:bodyStyle/><p:otherStyle/></p:txStyles></p:sldMaster>`
entries["ppt/slideMasters/_rels/slideMaster1.xml.rels"] = `<Relationships xmlns="` + relsNS + `"><Relationship Id="rId1" Type="` + officeNS + `slideLayout" Target="../slideLayouts/slideLayout1.xml"/><Relationship Id="rId2" Type="` + officeNS + `theme" Target="../theme/theme1.xml"/></Relationships>`
entries["ppt/theme/theme1.xml"] = `<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:srgbClr val="000000"/></a:dk1><a:lt1><a:srgbClr val="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="1F2937"/></a:dk2><a:lt2><a:srgbClr val="F3F4F6"/></a:lt2><a:accent1><a:srgbClr val="4472C4"/></a:accent1><a:accent2><a:srgbClr val="ED7D31"/></a:accent2><a:accent3><a:srgbClr val="A5A5A5"/></a:accent3><a:accent4><a:srgbClr val="FFC000"/></a:accent4><a:accent5><a:srgbClr val="5B9BD5"/></a:accent5><a:accent6><a:srgbClr val="70AD47"/></a:accent6><a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Arial"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Arial"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:fillStyleLst><a:lnStyleLst><a:ln w="12700"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="12700"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="12700"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>`
}
entries["_rels/.rels"] = `<Relationships xmlns="` + relsNS + `"><Relationship Id="rId1" Type="` + officeNS + `officeDocument" Target="` + main + `"/></Relationships>`
types := `<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="/` + main + `" ContentType="application/vnd.openxmlformats-officedocument.` + contentType + `.main+xml"/>`
if id == "deckcraft" {
for part, kind := range map[string]string{"slides/slide1.xml": "slide", "slideMasters/slideMaster1.xml": "slideMaster", "slideLayouts/slideLayout1.xml": "slideLayout"} {
types += fmt.Sprintf(`<Override PartName="/ppt/%s" ContentType="application/vnd.openxmlformats-officedocument.presentationml.%s+xml"/>`, part, kind)
}
types += `<Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>`
}
entries["[Content_Types].xml"] = types + `</Types>`
var output bytes.Buffer
writer := zip.NewWriter(&output)
keys := make([]string, 0, len(entries))
for name := range entries {
keys = append(keys, name)
}
sort.Strings(keys)
for _, name := range keys {
file, err := writer.Create(name)
if err != nil {
return nil, err
}
if _, err = file.Write([]byte(entries[name])); err != nil {
return nil, err
}
}
err := writer.Close()
return output.Bytes(), err
}