Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
488d709d85 | ||
|
|
66454b082a | ||
|
|
70e83e62d9 | ||
|
|
d2ddb9193a | ||
|
|
5f78db90c7 | ||
|
|
c3a4702e79 |
11
Dockerfile
11
Dockerfile
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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