feat(wopi): adapt libreoffice online

pull/1626/head
HFO4 2 years ago
parent 1c922ac981
commit 5a8c86c72e

@ -97,6 +97,7 @@ type WopiFileInfo struct {
// Required // Required
BaseFileName string BaseFileName string
Version string Version string
Size int64
// Breadcrumb // Breadcrumb
BreadcrumbBrandName string BreadcrumbBrandName string
@ -117,6 +118,7 @@ type WopiFileInfo struct {
IsAnonymousUser bool IsAnonymousUser bool
UserFriendlyName string UserFriendlyName string
UserId string UserId string
OwnerId string
// Permission // Permission
ReadOnly bool ReadOnly bool

@ -13,6 +13,7 @@ type ActonType string
var ( var (
ActionPreview = ActonType("embedview") ActionPreview = ActonType("embedview")
ActionPreviewFallback = ActonType("view")
ActionEdit = ActonType("edit") ActionEdit = ActonType("edit")
) )
@ -33,8 +34,9 @@ func (c *client) AvailableExts() []string {
for ext, actions := range c.actions { for ext, actions := range c.actions {
_, previewable := actions[string(ActionPreview)] _, previewable := actions[string(ActionPreview)]
_, editable := actions[string(ActionEdit)] _, editable := actions[string(ActionEdit)]
_, previewableFallback := actions[string(ActionPreviewFallback)]
if previewable || editable { if previewable || editable || previewableFallback {
exts = append(exts, strings.TrimPrefix(ext, ".")) exts = append(exts, strings.TrimPrefix(ext, "."))
} }
} }

@ -58,7 +58,7 @@ const (
MethodRename = "RENAME_FILE" MethodRename = "RENAME_FILE"
wopiSrcPlaceholder = "WOPI_SOURCE" wopiSrcPlaceholder = "WOPI_SOURCE"
wopiSrcParamDefault = "wopisrc" wopiSrcParamDefault = "WOPISrc"
sessionExpiresPadding = 10 sessionExpiresPadding = 10
wopiHeaderPrefix = "X-WOPI-" wopiHeaderPrefix = "X-WOPI-"
) )
@ -67,6 +67,9 @@ const (
func Init() { func Init() {
settings := model.GetSettingByNames("wopi_endpoint", "wopi_enabled") settings := model.GetSettingByNames("wopi_endpoint", "wopi_enabled")
if !model.IsTrueVal(settings["wopi_enabled"]) { if !model.IsTrueVal(settings["wopi_enabled"]) {
DefaultMu.Lock()
Default = nil
DefaultMu.Unlock()
return return
} }
@ -126,12 +129,18 @@ func (c *client) NewSession(user *model.User, file *model.File, action ActonType
return nil, ErrActionNotSupported return nil, ErrActionNotSupported
} }
actionConfig, ok := availableActions[string(action)] var (
if !ok { actionConfig Action
// Preferred action not available, fallback to view only action )
if actionConfig, ok = availableActions[string(ActionPreview)]; !ok { fallbackOrder := []ActonType{action, ActionPreview, ActionPreviewFallback, ActionEdit}
return nil, ErrActionNotSupported 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 // Generate WOPI REST endpoint for given file

@ -93,6 +93,8 @@ func (service *WopiService) FileInfo(c *gin.Context) (*serializer.WopiFileInfo,
IsAnonymousUser: true, IsAnonymousUser: true,
ReadOnly: true, ReadOnly: true,
ClosePostMessage: true, ClosePostMessage: true,
Size: int64(fs.FileTarget[0].Size),
OwnerId: hashid.HashID(fs.FileTarget[0].UserID, hashid.UserID),
} }
if session.Action == wopi.ActionEdit { if session.Action == wopi.ActionEdit {

Loading…
Cancel
Save