Merge branch 'master' of ssh://github.com/mickael-kerjean/filestash

This commit is contained in:
Mickael Kerjean 2021-09-29 00:11:53 +10:00
commit 01de913366
3 changed files with 39 additions and 6 deletions

View file

@ -2,7 +2,7 @@
position: fixed;
bottom: 20px;
left: 20px;
right: 0;
right: 70px;
font-size: 0.95em;
z-index: 1001;

View file

@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3/s3manager"
. "github.com/mickael-kerjean/filestash/server/common"
"io"
"net/url"
"os"
"path/filepath"
"strings"
@ -297,6 +298,9 @@ func (s S3Backend) Rm(path string) error {
func (s S3Backend) Mv(from string, to string) error {
f := s.path(from)
t := s.path(to)
if from == to {
return nil
}
client := s3.New(s.createSession(f.bucket))
if f.path == "" {
@ -306,7 +310,7 @@ func (s S3Backend) Mv(from string, to string) error {
// Move Single file
input := &s3.CopyObjectInput{
Bucket: aws.String(t.bucket),
CopySource: aws.String(f.bucket + "/" + f.path),
CopySource: aws.String(f.bucket + "/" + s.urlEncodedPath(f.path)),
Key: aws.String(t.path),
}
if s.params["encryption_key"] != "" {
@ -336,7 +340,7 @@ func (s S3Backend) Mv(from string, to string) error {
},
func(objs *s3.ListObjectsV2Output, lastPage bool) bool {
for _, obj := range objs.Contents {
from := f.bucket + "/" + *obj.Key
from := f.bucket + "/" + s.urlEncodedPath(*obj.Key)
toKey := t.path + strings.TrimPrefix(*obj.Key, f.path)
input := &s3.CopyObjectInput{
CopySource: aws.String(from),
@ -477,3 +481,15 @@ func (s S3Backend) path(p string) S3Path {
path,
}
}
func (s S3Backend) urlEncodedPath(path string) string {
sp := strings.Split(path, "/")
var pathElements []string
for _, x := range sp {
pathElements = append(pathElements, url.QueryEscape(x))
}
encodedPath := strings.Join(pathElements, "/")
return encodedPath
}

View file

@ -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 (