mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: encode filename when using url prefix for resources (#2829)
* fix: encode filename when using url prefix for resources * fix: only encode the last parts of filename * fix: encode all parts in filepath
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
@@ -83,7 +84,11 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
|
|||||||
link := uploadOutput.Location
|
link := uploadOutput.Location
|
||||||
// If url prefix is set, use it as the file link.
|
// If url prefix is set, use it as the file link.
|
||||||
if client.Config.URLPrefix != "" {
|
if client.Config.URLPrefix != "" {
|
||||||
link = fmt.Sprintf("%s/%s%s", client.Config.URLPrefix, filename, client.Config.URLSuffix)
|
parts := strings.Split(filename, "/")
|
||||||
|
for i := range parts {
|
||||||
|
parts[i] = url.PathEscape(parts[i])
|
||||||
|
}
|
||||||
|
link = fmt.Sprintf("%s/%s%s", client.Config.URLPrefix, strings.Join(parts, "/"), client.Config.URLSuffix)
|
||||||
}
|
}
|
||||||
if link == "" {
|
if link == "" {
|
||||||
return "", errors.New("failed to get file link")
|
return "", errors.New("failed to get file link")
|
||||||
|
Reference in New Issue
Block a user