mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-22 00:06:02 +01:00
fix (plugin): fix finding local ip for onlyoffice (#409)
This commit is contained in:
parent
110280e94b
commit
642f04c955
1 changed files with 20 additions and 3 deletions
|
|
@ -227,15 +227,32 @@ func IframeContentHandler(ctx App, res http.ResponseWriter, req *http.Request) {
|
|||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
maybeips := []string{}
|
||||
for _, address := range addrs {
|
||||
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
return ipnet.IP.String()
|
||||
maybeips = append(maybeips, ipnet.IP.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}()
|
||||
|
||||
// if there is just one interface, we can just pick that one
|
||||
if len(maybeips) == 1 {
|
||||
return maybeips[0]
|
||||
}
|
||||
|
||||
// if not, fallback to capturing our outgoing local ip
|
||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||
|
||||
return localAddr.IP.String()
|
||||
}()
|
||||
filestashServerLocation = fmt.Sprintf("http://%s:%d", localip, Config.Get("general.port").Int())
|
||||
contentType = func(p string) string {
|
||||
var (
|
||||
|
|
|
|||
Loading…
Reference in a new issue