Compare commits

..

6 Commits

Author SHA1 Message Date
krau
488d709d85 chore: update contributors section in README to remove specific name 2025-05-08 21:04:56 +08:00
krau
66454b082a fix: improve logger initialization and reduce cache TTL 2025-05-08 21:03:48 +08:00
Krau
70e83e62d9 Merge pull request #58 from AHCorn/main
fix: docker cache permission issue (#57)
2025-05-08 20:44:46 +08:00
安和
d2ddb9193a fix: docker cache permission issue (#57) 2025-05-08 18:38:28 +08:00
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
6 changed files with 37 additions and 18 deletions

View File

@@ -11,8 +11,17 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o saveany-bot .
FROM alpine:latest
RUN addgroup -S saveany && adduser -S saveany -G saveany
WORKDIR /app
RUN mkdir -p /app/data /app/downloads /app/cache && \
chown -R saveany:saveany /app
COPY --from=builder /app/saveany-bot .
CMD ["./saveany-bot"]
RUN chmod +x /app/saveany-bot
USER saveany
CMD ["./saveany-bot"]

View File

@@ -26,7 +26,7 @@
## Contributors
<!-- readme: contributors,AHCorn -start -->
<!-- readme: contributors -start -->
<table>
<tbody>
<tr>
@@ -61,7 +61,7 @@
</tr>
<tbody>
</table>
<!-- readme: contributors,AHCorn -end -->
<!-- readme: contributors -end -->
## Thanks

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

@@ -25,15 +25,16 @@ func InitLogger() {
}
}
consoleH := handler.NewConsoleHandler(logLevels)
fileH, err := handler.NewTimeRotateFile(
logFilePath,
rotatefile.EveryDay,
handler.WithLogLevels(slog.AllLevels),
handler.WithBackupNum(logBackupNum),
handler.WithBuffSize(0),
)
if err != nil {
panic(err)
Log.AddHandler(consoleH)
if logFilePath != "" && logBackupNum > 0 {
fileH, err := handler.NewTimeRotateFile(
logFilePath,
rotatefile.EveryDay,
handler.WithLogLevels(slog.AllLevels),
handler.WithBackupNum(logBackupNum))
if err != nil {
panic(err)
}
Log.AddHandler(fileH)
}
Log.AddHandlers(consoleH, fileH)
}

View File

@@ -90,11 +90,9 @@ func Init() error {
viper.SetDefault("telegram.rpc_retry", 5)
viper.SetDefault("temp.base_path", "cache/")
viper.SetDefault("temp.cache_ttl", 3600)
viper.SetDefault("temp.cache_ttl", 30)
viper.SetDefault("log.level", "INFO")
viper.SetDefault("log.file", "logs/saveany.log")
viper.SetDefault("log.backup_count", 7)
viper.SetDefault("db.path", "data/saveany.db")
viper.SetDefault("db.session", "data/session.db")

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)
}