mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-14 03:49:36 +08:00
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)
|
key := fmt.Sprintf("file:%d:%d", chatID, messageID)
|
||||||
cachedFile, err := common.CacheGet[*types.File](ctx, key)
|
cachedFile, err := common.CacheGet[*types.File](ctx, key)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if customFileName != "" {
|
||||||
|
cachedFile.FileName = customFileName
|
||||||
|
}
|
||||||
return cachedFile, nil
|
return cachedFile, nil
|
||||||
}
|
}
|
||||||
common.Log.Debugf("Getting file: %s", key)
|
common.Log.Debugf("Getting file: %s", key)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/krau/SaveAny-Bot/types"
|
"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 {
|
func (c *Client) WriteFile(ctx context.Context, remotePath string, content io.Reader) error {
|
||||||
url := c.BaseURL + remotePath
|
u, err := url.Parse(c.BaseURL)
|
||||||
resp, err := c.doRequest(ctx, WebdavMethodPut, url, content)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -124,4 +131,5 @@ func (c *Client) WriteFile(ctx context.Context, remotePath string, content io.Re
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("PUT: %s", resp.Status)
|
return fmt.Errorf("PUT: %s", resp.Status)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user