feat(wopi): change doc preview config based on WOPI discovery results

This commit is contained in:
HFO4
2023-01-09 19:36:41 +08:00
parent c39daeb0d0
commit 4541400755
7 changed files with 107 additions and 22 deletions

View File

@@ -4,7 +4,9 @@ import (
"encoding/xml"
"fmt"
"github.com/cloudreve/Cloudreve/v3/pkg/cache"
"github.com/cloudreve/Cloudreve/v3/pkg/util"
"net/http"
"strings"
)
type ActonType string
@@ -19,6 +21,27 @@ const (
DiscoverRefreshDuration = 24 * 3600 // 24 hrs
)
func (c *client) AvailableExts() []string {
if err := c.checkDiscovery(); err != nil {
util.Log().Error("Failed to check WOPI discovery: %s", err)
return nil
}
c.mu.RUnlock()
defer c.mu.RUnlock()
exts := make([]string, 0, len(c.actions))
for ext, actions := range c.actions {
_, previewable := actions[string(ActionPreview)]
_, editable := actions[string(ActionEdit)]
if previewable || editable {
exts = append(exts, strings.TrimPrefix(ext, "."))
}
}
return exts
}
// checkDiscovery checks if discovery content is needed to be refreshed.
// If so, it will refresh discovery content.
func (c *client) checkDiscovery() error {