mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-30 05:01:56 +08:00
feat(wopi): change doc preview config based on WOPI discovery results
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user