Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: encode filename when using url prefix for resources (#2829)

Mudkipf654d3c90e67
diff --git a/plugin/storage/s3/s3.go b/plugin/storage/s3/s3.go
index e0a17d4a9..8618fd623 100644
--- a/plugin/storage/s3/s3.go
+++ b/plugin/storage/s3/s3.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
+ "net/url"
"strings"
"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
// If url prefix is set, use it as the file link.
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 == "" {
return "", errors.New("failed to get file link")