Skip to content

Commit

Permalink
feat: indicate templates for weboffice
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Barz <mbarz@owncloud.com>
  • Loading branch information
micbar committed Oct 15, 2024
1 parent 2a6fdbe commit fff9e17
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ func (s *svc) handleOpen(openMode int) http.HandlerFunc {
App: r.Form.Get("app_name"),
Opaque: utils.AppendPlainToOpaque(nil, "lang", lang),
}

templateID := r.Form.Get("template_id")
if templateID != "" {
openReq.Opaque = utils.AppendPlainToOpaque(openReq.Opaque, "template", templateID)
}
openRes, err := client.OpenInApp(ctx, &openReq)
if err != nil {
writeError(w, r, appErrorServerError,
Expand All @@ -481,6 +486,7 @@ func (s *svc) handleOpen(openMode int) http.HandlerFunc {

switch openMode {
case openModeNormal:

payload = openRes.AppUrl

case openModeWeb:
Expand Down Expand Up @@ -567,7 +573,8 @@ type MimeTypeInfo struct {
type ProviderInfo struct {
appregistry.ProviderInfo
// TODO make this part of the CS3 provider info
SecureView bool `json:"secure_view"`
SecureView bool `json:"secure_view"`
TargetExt string `json:"target_ext,omitempty"`
}

// buildApps rewrites the mime type info to only include apps that
Expand Down Expand Up @@ -598,6 +605,7 @@ func buildApps(mimeTypes []*appregistry.MimeTypeInfo, userAgent, secureViewAppAd
}
if len(apps) > 0 {
mt := &MimeTypeInfo{}
addTemplateInfo(m, apps)
proto.Merge(&mt.MimeTypeInfo, m)
mt.AppProviders = apps
res = append(res, mt)
Expand Down
90 changes: 90 additions & 0 deletions internal/http/services/appprovider/templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package appprovider

import (
"strings"

appregistry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
)

type TemplateList struct {
Templates map[string][]Template `json:"templates"`
}

type Template struct {
Extension string `json:"extension"`
MimeType string `json:"mime_type"`
TargetExtension string `json:"target_extension"`
}

var tl = TemplateList{
Templates: map[string][]Template{
"collabora": {
{
MimeType: "application/vnd.oasis.opendocument.spreadsheet-template",
TargetExtension: "ods",
},
{
MimeType: "application/vnd.oasis.opendocument.text-template",
TargetExtension: "odt",
},
{
MimeType: "application/vnd.oasis.opendocument.presentation-template",
TargetExtension: "odp",
},
},
"onlyoffice": {
{
MimeType: "application/vnd.ms-word.template.macroenabled.12",
TargetExtension: "docx",
},
{
MimeType: "application/vnd.oasis.opendocument.text-template",
TargetExtension: "docx",
},
{
MimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
TargetExtension: "docx",
},
{
MimeType: "application/vnd.oasis.opendocument.spreadsheet-template",
TargetExtension: "xlsx",
},
{
MimeType: "application/vnd.ms-excel.template.macroenabled.12",
TargetExtension: "xlsx",
},
{
MimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
TargetExtension: "xlsx",
},
{
MimeType: "application/vnd.oasis.opendocument.presentation-template",
TargetExtension: "pptx",
},
{
MimeType: "application/vnd.ms-powerpoint.template.macroenabled.12",
TargetExtension: "pptx",
},
{
MimeType: "application/vnd.openxmlformats-officedocument.presentationml.template",
TargetExtension: "pptx",
},
},
},
}

func addTemplateInfo(mt *appregistry.MimeTypeInfo, apps []*ProviderInfo) {
for _, app := range apps {
if tls, ok := tl.Templates[strings.ToLower(app.Name)]; ok {
for _, tmpl := range tls {
if tmpl.Extension != "" && tmpl.Extension == mt.Ext {
app.TargetExt = tmpl.TargetExtension
continue
}
if tmpl.MimeType == mt.MimeType {
app.TargetExt = tmpl.TargetExtension
}
}
}
}
}

0 comments on commit fff9e17

Please sign in to comment.