diff --git a/pkg/serializer/explorer.go b/pkg/serializer/explorer.go index 4f94b09..be49edd 100644 --- a/pkg/serializer/explorer.go +++ b/pkg/serializer/explorer.go @@ -97,6 +97,7 @@ type WopiFileInfo struct { // Required BaseFileName string Version string + Size int64 // Breadcrumb BreadcrumbBrandName string @@ -117,6 +118,7 @@ type WopiFileInfo struct { IsAnonymousUser bool UserFriendlyName string UserId string + OwnerId string // Permission ReadOnly bool diff --git a/pkg/wopi/discovery.go b/pkg/wopi/discovery.go index 20467b1..d4f480f 100644 --- a/pkg/wopi/discovery.go +++ b/pkg/wopi/discovery.go @@ -12,8 +12,9 @@ import ( type ActonType string var ( - ActionPreview = ActonType("embedview") - ActionEdit = ActonType("edit") + ActionPreview = ActonType("embedview") + ActionPreviewFallback = ActonType("view") + ActionEdit = ActonType("edit") ) const ( @@ -33,8 +34,9 @@ func (c *client) AvailableExts() []string { for ext, actions := range c.actions { _, previewable := actions[string(ActionPreview)] _, editable := actions[string(ActionEdit)] + _, previewableFallback := actions[string(ActionPreviewFallback)] - if previewable || editable { + if previewable || editable || previewableFallback { exts = append(exts, strings.TrimPrefix(ext, ".")) } } diff --git a/pkg/wopi/wopi.go b/pkg/wopi/wopi.go index 6120cf3..bac734d 100644 --- a/pkg/wopi/wopi.go +++ b/pkg/wopi/wopi.go @@ -58,7 +58,7 @@ const ( MethodRename = "RENAME_FILE" wopiSrcPlaceholder = "WOPI_SOURCE" - wopiSrcParamDefault = "wopisrc" + wopiSrcParamDefault = "WOPISrc" sessionExpiresPadding = 10 wopiHeaderPrefix = "X-WOPI-" ) @@ -67,6 +67,9 @@ const ( func Init() { settings := model.GetSettingByNames("wopi_endpoint", "wopi_enabled") if !model.IsTrueVal(settings["wopi_enabled"]) { + DefaultMu.Lock() + Default = nil + DefaultMu.Unlock() return } @@ -126,14 +129,20 @@ func (c *client) NewSession(user *model.User, file *model.File, action ActonType return nil, ErrActionNotSupported } - actionConfig, ok := availableActions[string(action)] - if !ok { - // Preferred action not available, fallback to view only action - if actionConfig, ok = availableActions[string(ActionPreview)]; !ok { - return nil, ErrActionNotSupported + var ( + actionConfig Action + ) + fallbackOrder := []ActonType{action, ActionPreview, ActionPreviewFallback, ActionEdit} + for _, a := range fallbackOrder { + if actionConfig, ok = availableActions[string(a)]; ok { + break } } + if actionConfig.Urlsrc == "" { + return nil, ErrActionNotSupported + } + // Generate WOPI REST endpoint for given file baseURL := model.GetSiteURL() linkPath, err := url.Parse(fmt.Sprintf("/api/v3/wopi/files/%s", hashid.HashID(file.ID, hashid.FileID))) diff --git a/service/explorer/wopi.go b/service/explorer/wopi.go index d959b26..9ee7c30 100644 --- a/service/explorer/wopi.go +++ b/service/explorer/wopi.go @@ -93,6 +93,8 @@ func (service *WopiService) FileInfo(c *gin.Context) (*serializer.WopiFileInfo, IsAnonymousUser: true, ReadOnly: true, ClosePostMessage: true, + Size: int64(fs.FileTarget[0].Size), + OwnerId: hashid.HashID(fs.FileTarget[0].UserID, hashid.UserID), } if session.Action == wopi.ActionEdit {