fix (sharedlink): issue with ifram / wopi

This commit is contained in:
MickaelK
2025-01-24 13:59:06 +11:00
parent 9193c86266
commit 42fd37e2ec
2 changed files with 35 additions and 14 deletions

View File

@ -1,5 +1,6 @@
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect } from "../../lib/rx.js";
import { forwardURLParams } from "../../lib/path.js";
import { loadCSS } from "../../helpers/loader.js";
import notification from "../../components/notification.js";
import t from "../../locales/index.js";
@ -8,9 +9,10 @@ import ctrlError from "../ctrl_error.js";
import { getCurrentPath } from "./common.js";
export default function(render, { endpoint = "" }) {
const url = forwardURLParams(`${endpoint}?path=${encodeURIComponent(getCurrentPath())}`, ["share"]);
const $page = createElement(`
<div class="component_appframe">
<iframe style="width:100%;height:100%" src="${endpoint}?path=${encodeURIComponent(getCurrentPath())}" scrolling="no"></iframe>
<iframe style="width:100%;height:100%" src="${url}" scrolling="no"></iframe>
</div>
`);
render($page);

View File

@ -87,20 +87,34 @@ func WOPIHandler_PutFile(w http.ResponseWriter, r *http.Request) {
}
func WOPIExecute(w http.ResponseWriter, r *http.Request) func(func(*App, string, http.ResponseWriter)) {
return func(fn func(*App, string, http.ResponseWriter)) {
tmp := strings.SplitN(mux.Vars(r)["path64"], "::", 2)
if len(tmp) != 2 {
extractInfo := func(encodedString string) (path string, shareID string) {
tmp := strings.Split(encodedString, "::") // eg: backendID::b64(path)::shareID
if len(tmp) < 2 {
SendErrorResult(w, ErrNotValid)
return
}
p, err := base64.StdEncoding.DecodeString(tmp[1])
bpath, err := base64.StdEncoding.DecodeString(tmp[1])
if err != nil {
return "", ""
} else if len(tmp) > 2 {
shareID = tmp[2]
}
return string(bpath), shareID
}
return func(fn func(*App, string, http.ResponseWriter)) {
path, shareID := extractInfo(mux.Vars(r)["path64"])
if path == "" {
SendErrorResult(w, ErrNotValid)
return
}
if shareID != "" {
urlQuery := r.URL.Query()
urlQuery.Set("share", shareID)
r.URL.RawQuery = urlQuery.Encode()
}
middleware.NewMiddlewareChain(
func(ctx *App, w http.ResponseWriter, r *http.Request) {
fullpath, err := ctrl.PathBuilder(ctx, string(p))
fullpath, err := ctrl.PathBuilder(ctx, path)
if err != nil {
SendErrorResult(w, err)
return
@ -237,20 +251,25 @@ func wopiDiscovery(ctx *App, fullpath string) (string, error) {
if err != nil {
return "", err
}
myURL := origin()
if myURL == "" {
myURL := "http://"
wopiSRC := origin()
if wopiSRC == "" {
wopiSRC := "http://"
if Config.Get("general.force_ssl").Bool() {
myURL = "https://"
wopiSRC = "https://"
}
myURL += Config.Get("general.host").String()
wopiSRC += Config.Get("general.host").String()
}
p := u.Query()
backendID := GenerateID(map[string]string{
wopiSRC += "/api/wopi/files/"
wopiSRC += GenerateID(map[string]string{
"id": GenerateID(ctx.Session),
"path": fullpath,
})
p.Set("WOPISrc", myURL+"/api/wopi/files/"+backendID+"::"+base64.StdEncoding.EncodeToString([]byte(fullpath)))
wopiSRC += "::" + base64.StdEncoding.EncodeToString([]byte(fullpath))
if ctx.Share.Id != "" {
wopiSRC += "::" + ctx.Share.Id
}
p := u.Query()
p.Set("WOPISrc", wopiSRC)
p.Set("access_token", ctx.Authorization)
u.RawQuery = p.Encode()
if newHost := rewrite_url(); newHost != "" {