Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: indicate templates for weboffice #4882

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/template-conversions-for-apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Indicate template conversion capabilties on apps

We added information to the available app providers to indicate which mimetypes can be used for template conversion.

https://github.com/cs3org/reva/pull/4882
9 changes: 8 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 Down Expand Up @@ -567,7 +572,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 +604,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": {
micbar marked this conversation as resolved.
Show resolved Hide resolved
{
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
}
}
}
}
}
Loading