diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go index 75d9e7ac9c..e21a66f6e5 100644 --- a/internal/http/services/appprovider/appprovider.go +++ b/internal/http/services/appprovider/appprovider.go @@ -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, @@ -481,6 +486,7 @@ func (s *svc) handleOpen(openMode int) http.HandlerFunc { switch openMode { case openModeNormal: + payload = openRes.AppUrl case openModeWeb: @@ -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 @@ -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) diff --git a/internal/http/services/appprovider/templates.go b/internal/http/services/appprovider/templates.go new file mode 100644 index 0000000000..0491a06a34 --- /dev/null +++ b/internal/http/services/appprovider/templates.go @@ -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 + } + } + } + } +}