fix (wopi): wopi config (#785)

This commit is contained in:
Mickael 2024-12-12 16:07:34 +11:00 committed by GitHub
parent b3a44918e1
commit 1d06c785bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 86 additions and 25 deletions

View file

@ -2,24 +2,33 @@ version: '2'
services: services:
app: app:
container_name: filestash container_name: filestash
image: machines/filestash image: machines/filestash:latest
restart: always restart: always
environment: environment:
- APPLICATION_URL= - APPLICATION_URL=127.0.0.1:8334
- GDRIVE_CLIENT_ID=<gdrive_client>
- GDRIVE_CLIENT_SECRET=<gdrive_secret>
- DROPBOX_CLIENT_ID=<dropbox_key>
- ONLYOFFICE_URL=http://onlyoffice
- CANARY=true - CANARY=true
- OFFICE_URL=http://127.0.0.1:9980
- OFFICE_FILESTASH_URL=http://app:8334
ports: ports:
- "8334:8334" - "8334:8334"
volumes: volumes:
- filestash:/app/data/state/ - filestash:/app/data/state/
onlyoffice: wopi_server:
container_name: filestash_oods container_name: filestash_wopi
image: onlyoffice/documentserver:7.1 image: collabora/code:24.04.10.2.1
restart: always restart: always
environment:
- "extra_params=--o:ssl.enable=false"
command:
- /bin/bash
- -c
- |
curl -o /usr/share/coolwsd/browser/dist/branding-desktop.css https://gist.githubusercontent.com/mickael-kerjean/bc1f57cd312cf04731d30185cc4e7ba2/raw/d706dcdf23c21441e5af289d871b33defc2770ea/destop.css
/bin/su -s /bin/bash -c '/start-collabora-online.sh' cool
user: root
ports:
- "9980:9980"
volumes: volumes:
filestash: {} filestash: {}

View file

@ -26,7 +26,6 @@ import (
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_storj" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_storj"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_tmp" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_tmp"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_webdav" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_webdav"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_editor_onlyoffice"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_editor_wopi" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_editor_wopi"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_console" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_console"
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_ascii" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_ascii"

View file

@ -14,7 +14,7 @@ func plugin_enable() bool {
} }
f.Name = "enable" f.Name = "enable"
f.Type = "enable" f.Type = "enable"
f.Target = []string{"office_server"} f.Target = []string{"office_server", "filestash_server", "rewrite_discovery_url"}
f.Description = "Enable/Disable the wopi office suite and options to manage word, excel and powerpoint documents." f.Description = "Enable/Disable the wopi office suite and options to manage word, excel and powerpoint documents."
f.Default = false f.Default = false
if u := os.Getenv("OFFICE_URL"); u != "" { if u := os.Getenv("OFFICE_URL"); u != "" {
@ -42,3 +42,41 @@ func server_url() string {
return f return f
}).String() }).String()
} }
func origin() string {
return Config.Get("features.office.filestash_server").Schema(func(f *FormElement) *FormElement {
if f == nil {
f = &FormElement{}
}
f.Id = "filestash_server"
f.Name = "filestash_server"
f.Type = "text"
f.Description = "Location of your Filestash server from the point of view of the office server. Keep blank if you don't use fancy networking via docker/k8s,..."
f.Default = "http://app:8334"
f.Placeholder = "Eg: http://app:8334"
if u := os.Getenv("OFFICE_FILESTASH_URL"); u != "" {
f.Default = u
f.Placeholder = fmt.Sprintf("Default: '%s'", u)
}
return f
}).String()
}
func rewrite_url() string {
return Config.Get("features.office.rewrite_discovery_url").Schema(func(f *FormElement) *FormElement {
if f == nil {
f = &FormElement{}
}
f.Id = "rewrite_discovery_url"
f.Name = "rewrite_discovery_url"
f.Type = "text"
f.Description = "Rewrite the discovery URL to something else. Typical example is a deployment via docker where your office server resolve via http://wopi_service:9980 but such URL would be unknown when given to a browser. Keep empty if you're not doing a docker / k8s deployment"
f.Default = ""
f.Placeholder = "Eg: http://localhost:9980"
if u := os.Getenv("OFFICE_REWRITE_URL"); u != "" {
f.Default = u
f.Placeholder = fmt.Sprintf("Default: '%s'", u)
}
return f
}).String()
}

View file

@ -43,7 +43,11 @@ var WOPIOverrides = `
` `
func WOPIHandler_CheckFileInfo(w http.ResponseWriter, r *http.Request) { func WOPIHandler_CheckFileInfo(w http.ResponseWriter, r *http.Request) {
WOPIExecute(w, r)(func(ctx *App, fullpath string) { if plugin_enable() == false {
SendErrorResult(w, ErrNotFound)
return
}
WOPIExecute(w, r)(func(ctx *App, fullpath string, w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(map[string]any{ if err := json.NewEncoder(w).Encode(map[string]any{
"BaseFileName": filepath.Base(fullpath), "BaseFileName": filepath.Base(fullpath),
@ -59,7 +63,7 @@ func WOPIHandler_CheckFileInfo(w http.ResponseWriter, r *http.Request) {
} }
func WOPIHandler_GetFile(w http.ResponseWriter, r *http.Request) { func WOPIHandler_GetFile(w http.ResponseWriter, r *http.Request) {
WOPIExecute(w, r)(func(ctx *App, fullpath string) { WOPIExecute(w, r)(func(ctx *App, fullpath string, w http.ResponseWriter) {
f, err := ctx.Backend.Cat(fullpath) f, err := ctx.Backend.Cat(fullpath)
if err != nil { if err != nil {
SendErrorResult(w, err) SendErrorResult(w, err)
@ -71,7 +75,7 @@ func WOPIHandler_GetFile(w http.ResponseWriter, r *http.Request) {
func WOPIHandler_PutFile(w http.ResponseWriter, r *http.Request) { func WOPIHandler_PutFile(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close() defer r.Body.Close()
WOPIExecute(w, r)(func(ctx *App, fullpath string) { WOPIExecute(w, r)(func(ctx *App, fullpath string, w http.ResponseWriter) {
err := ctx.Backend.Save(fullpath, r.Body) err := ctx.Backend.Save(fullpath, r.Body)
if err != nil { if err != nil {
SendErrorResult(w, err) SendErrorResult(w, err)
@ -81,8 +85,8 @@ func WOPIHandler_PutFile(w http.ResponseWriter, r *http.Request) {
}) })
} }
func WOPIExecute(w http.ResponseWriter, r *http.Request) func(func(*App, string)) { func WOPIExecute(w http.ResponseWriter, r *http.Request) func(func(*App, string, http.ResponseWriter)) {
return func(fn func(*App, string)) { return func(fn func(*App, string, http.ResponseWriter)) {
path64 := mux.Vars(r)["path64"] path64 := mux.Vars(r)["path64"]
p, err := base64.StdEncoding.DecodeString(path64) p, err := base64.StdEncoding.DecodeString(path64)
if err != nil { if err != nil {
@ -91,7 +95,7 @@ func WOPIExecute(w http.ResponseWriter, r *http.Request) func(func(*App, string)
} }
middleware.NewMiddlewareChain( middleware.NewMiddlewareChain(
func(ctx *App, w http.ResponseWriter, r *http.Request) { func(ctx *App, w http.ResponseWriter, r *http.Request) {
fn(ctx, string(p)) fn(ctx, string(p), w)
}, },
[]Middleware{middleware.SessionStart}, []Middleware{middleware.SessionStart},
App{}, App{},
@ -206,14 +210,23 @@ func wopiDiscovery(ctx *App, fullpath string) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
myURL := origin()
if myURL == "" {
myURL := "http://" myURL := "http://"
if Config.Get("general.force_ssl").Bool() { if Config.Get("general.force_ssl").Bool() {
myURL = "https://" myURL = "https://"
} }
myURL += Config.Get("general.host").String() myURL += Config.Get("general.host").String()
}
p := u.Query() p := u.Query()
p.Set("WOPISrc", myURL+"/api/wopi/files/"+base64.StdEncoding.EncodeToString([]byte(fullpath))) p.Set("WOPISrc", myURL+"/api/wopi/files/"+base64.StdEncoding.EncodeToString([]byte(fullpath)))
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 p, err := url.Parse(newHost); err == nil {
u.Host = p.Host
u.Scheme = p.Scheme
}
}
return u.String(), nil return u.String(), nil
} }

View file

@ -5,11 +5,13 @@ import (
) )
func init() { func init() {
Hooks.Register.HttpEndpoint(WOPIRoutes)
Hooks.Register.XDGOpen(WOPIOverrides)
Hooks.Register.Onload(func() { Hooks.Register.Onload(func() {
plugin_enable()
server_url() server_url()
}) origin()
rewrite_url()
if plugin_enable() {
Hooks.Register.XDGOpen(WOPIOverrides)
}
})
Hooks.Register.HttpEndpoint(WOPIRoutes)
} }