Compare commits

...

2 Commits

Author SHA1 Message Date
krau
5f78db90c7 fix: webdav url escape 2025-05-07 12:05:10 +08:00
krau
c3a4702e79 fix: allow custom file name for cached files in FileFromMessage function 2025-05-07 11:38:56 +08:00
2 changed files with 13 additions and 2 deletions

View File

@@ -182,6 +182,9 @@ func FileFromMessage(ctx *ext.Context, chatID int64, messageID int, customFileNa
key := fmt.Sprintf("file:%d:%d", chatID, messageID)
cachedFile, err := common.CacheGet[*types.File](ctx, key)
if err == nil {
if customFileName != "" {
cachedFile.FileName = customFileName
}
return cachedFile, nil
}
common.Log.Debugf("Getting file: %s", key)

View File

@@ -5,6 +5,8 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"path"
"strings"
"github.com/krau/SaveAny-Bot/types"
@@ -113,8 +115,13 @@ func (c *Client) MkDir(ctx context.Context, dirPath string) error {
}
func (c *Client) WriteFile(ctx context.Context, remotePath string, content io.Reader) error {
url := c.BaseURL + remotePath
resp, err := c.doRequest(ctx, WebdavMethodPut, url, content)
u, err := url.Parse(c.BaseURL)
if err != nil {
return err
}
parts := strings.Split(strings.Trim(remotePath, "/"), "/")
u.Path = path.Join(u.Path, strings.Join(parts, "/"))
resp, err := c.doRequest(ctx, WebdavMethodPut, u.String(), content)
if err != nil {
return err
}
@@ -124,4 +131,5 @@ func (c *Client) WriteFile(ctx context.Context, remotePath string, content io.Re
return nil
}
return fmt.Errorf("PUT: %s", resp.Status)
}