Feat: support custom office preview service (Fix #1050)

pull/1073/head
HFO4 3 years ago
parent 9fc08292a0
commit 7fd984f95d

@ -1 +1 @@
Subproject commit 18bb1b01b24c25ce070a2027fe362985d4866932
Subproject commit 6b2a820a0c194c5dfb8069a4f4fcede5dd8d7b12

@ -189,6 +189,7 @@ Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; verti
{Name: "pwa_display", Value: "standalone", Type: "pwa"},
{Name: "pwa_theme_color", Value: "#000000", Type: "pwa"},
{Name: "pwa_background_color", Value: "#ffffff", Type: "pwa"},
{Name: "office_preview_service", Value: "https://view.officeapps.live.com/op/view.aspx?src={$src}", Type: "preview"},
}
for _, value := range defaultSettings {

@ -2,8 +2,10 @@ package explorer
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/cloudreve/Cloudreve/v3/pkg/util"
"io/ioutil"
"net/http"
"net/url"
@ -222,15 +224,15 @@ func (service *FileIDService) CreateDocPreviewSession(ctx context.Context, c *gi
}
// 生成最终的预览器地址
// TODO 从配置文件中读取
viewerBase, _ := url.Parse("https://view.officeapps.live.com/op/view.aspx")
params := viewerBase.Query()
params.Set("src", downloadURL)
viewerBase.RawQuery = params.Encode()
srcB64 := base64.StdEncoding.EncodeToString([]byte(downloadURL))
srcEncoded := url.QueryEscape(downloadURL)
srcB64Encoded := url.QueryEscape(srcB64)
return serializer.Response{
Code: 0,
Data: viewerBase.String(),
Data: util.Replace(map[string]string{
"{$src}": srcEncoded,
"{$srcB64}": srcB64Encoded,
}, model.GetSettingByName("office_preview_service")),
}
}

Loading…
Cancel
Save