mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-03 13:11:46 +08:00
fix (sharedlink): issue with ifram / wopi
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import { createElement } from "../../lib/skeleton/index.js";
|
import { createElement } from "../../lib/skeleton/index.js";
|
||||||
import rxjs, { effect } from "../../lib/rx.js";
|
import rxjs, { effect } from "../../lib/rx.js";
|
||||||
|
import { forwardURLParams } from "../../lib/path.js";
|
||||||
import { loadCSS } from "../../helpers/loader.js";
|
import { loadCSS } from "../../helpers/loader.js";
|
||||||
import notification from "../../components/notification.js";
|
import notification from "../../components/notification.js";
|
||||||
import t from "../../locales/index.js";
|
import t from "../../locales/index.js";
|
||||||
@ -8,9 +9,10 @@ import ctrlError from "../ctrl_error.js";
|
|||||||
import { getCurrentPath } from "./common.js";
|
import { getCurrentPath } from "./common.js";
|
||||||
|
|
||||||
export default function(render, { endpoint = "" }) {
|
export default function(render, { endpoint = "" }) {
|
||||||
|
const url = forwardURLParams(`${endpoint}?path=${encodeURIComponent(getCurrentPath())}`, ["share"]);
|
||||||
const $page = createElement(`
|
const $page = createElement(`
|
||||||
<div class="component_appframe">
|
<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>
|
</div>
|
||||||
`);
|
`);
|
||||||
render($page);
|
render($page);
|
||||||
|
|||||||
@ -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)) {
|
func WOPIExecute(w http.ResponseWriter, r *http.Request) func(func(*App, string, http.ResponseWriter)) {
|
||||||
return func(fn func(*App, string, http.ResponseWriter)) {
|
extractInfo := func(encodedString string) (path string, shareID string) {
|
||||||
tmp := strings.SplitN(mux.Vars(r)["path64"], "::", 2)
|
tmp := strings.Split(encodedString, "::") // eg: backendID::b64(path)::shareID
|
||||||
if len(tmp) != 2 {
|
if len(tmp) < 2 {
|
||||||
SendErrorResult(w, ErrNotValid)
|
SendErrorResult(w, ErrNotValid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p, err := base64.StdEncoding.DecodeString(tmp[1])
|
bpath, err := base64.StdEncoding.DecodeString(tmp[1])
|
||||||
if err != nil {
|
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)
|
SendErrorResult(w, ErrNotValid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if shareID != "" {
|
||||||
|
urlQuery := r.URL.Query()
|
||||||
|
urlQuery.Set("share", shareID)
|
||||||
|
r.URL.RawQuery = urlQuery.Encode()
|
||||||
|
}
|
||||||
middleware.NewMiddlewareChain(
|
middleware.NewMiddlewareChain(
|
||||||
func(ctx *App, w http.ResponseWriter, r *http.Request) {
|
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 {
|
if err != nil {
|
||||||
SendErrorResult(w, err)
|
SendErrorResult(w, err)
|
||||||
return
|
return
|
||||||
@ -237,20 +251,25 @@ func wopiDiscovery(ctx *App, fullpath string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
myURL := origin()
|
wopiSRC := origin()
|
||||||
if myURL == "" {
|
if wopiSRC == "" {
|
||||||
myURL := "http://"
|
wopiSRC := "http://"
|
||||||
if Config.Get("general.force_ssl").Bool() {
|
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()
|
wopiSRC += "/api/wopi/files/"
|
||||||
backendID := GenerateID(map[string]string{
|
wopiSRC += GenerateID(map[string]string{
|
||||||
"id": GenerateID(ctx.Session),
|
"id": GenerateID(ctx.Session),
|
||||||
"path": fullpath,
|
"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)
|
p.Set("access_token", ctx.Authorization)
|
||||||
u.RawQuery = p.Encode()
|
u.RawQuery = p.Encode()
|
||||||
if newHost := rewrite_url(); newHost != "" {
|
if newHost := rewrite_url(); newHost != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user