mirror of
https://github.com/cloudreve/cloudreve.git
synced 2025-11-03 12:27:03 +08:00
Feat: support custom office preview service (Fix #1050)
This commit is contained in:
2
assets
2
assets
Submodule assets updated: 18bb1b01b2...6b2a820a0c
@ -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_display", Value: "standalone", Type: "pwa"},
|
||||||
{Name: "pwa_theme_color", Value: "#000000", Type: "pwa"},
|
{Name: "pwa_theme_color", Value: "#000000", Type: "pwa"},
|
||||||
{Name: "pwa_background_color", Value: "#ffffff", 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 {
|
for _, value := range defaultSettings {
|
||||||
|
|||||||
@ -2,8 +2,10 @@ package explorer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/cloudreve/Cloudreve/v3/pkg/util"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -222,15 +224,15 @@ func (service *FileIDService) CreateDocPreviewSession(ctx context.Context, c *gi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 生成最终的预览器地址
|
// 生成最终的预览器地址
|
||||||
// TODO 从配置文件中读取
|
srcB64 := base64.StdEncoding.EncodeToString([]byte(downloadURL))
|
||||||
viewerBase, _ := url.Parse("https://view.officeapps.live.com/op/view.aspx")
|
srcEncoded := url.QueryEscape(downloadURL)
|
||||||
params := viewerBase.Query()
|
srcB64Encoded := url.QueryEscape(srcB64)
|
||||||
params.Set("src", downloadURL)
|
|
||||||
viewerBase.RawQuery = params.Encode()
|
|
||||||
|
|
||||||
return serializer.Response{
|
return serializer.Response{
|
||||||
Code: 0,
|
Code: 0,
|
||||||
Data: viewerBase.String(),
|
Data: util.Replace(map[string]string{
|
||||||
|
"{$src}": srcEncoded,
|
||||||
|
"{$srcB64}": srcB64Encoded,
|
||||||
|
}, model.GetSettingByName("office_preview_service")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user