Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f78db90c7 | ||
|
|
c3a4702e79 |
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user