mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-10 17:52:44 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed99a37831 | ||
|
|
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
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ func AddToQueue(ctx *ext.Context, update *ext.Update) error {
|
||||
if update.CallbackQuery.MsgID != record.ReplyMessageID {
|
||||
record.ReplyMessageID = update.CallbackQuery.MsgID
|
||||
if err := dao.SaveReceivedFile(record); err != nil {
|
||||
common.Log.Errorf("更新接收的文件失败: %s", err)
|
||||
common.Log.Errorf("更新记录失败: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,7 @@ func AddToQueue(ctx *ext.Context, update *ext.Update) error {
|
||||
task = types.Task{
|
||||
Ctx: ctx,
|
||||
Status: types.Pending,
|
||||
FileDBID: record.ID,
|
||||
File: file,
|
||||
StorageName: storageName,
|
||||
FileChatID: record.ChatID,
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -27,6 +27,13 @@ import (
|
||||
|
||||
func processPendingTask(task *types.Task) error {
|
||||
common.Log.Debugf("Start processing task: %s", task.String())
|
||||
|
||||
if task.FileName() != "" && !task.IsTelegraph && task.File.FileSize != 0 && task.FileDBID != 0 {
|
||||
ext := path.Ext(task.FileName())
|
||||
name := task.FileName()[:len(task.FileName())-len(ext)]
|
||||
task.File.FileName = fmt.Sprintf("%s_%d%s", name, task.FileDBID, ext)
|
||||
}
|
||||
|
||||
if task.FileName() == "" {
|
||||
task.File.FileName = fmt.Sprintf("%d_%d_%s", task.FileChatID, task.FileMessageID, task.File.Hash())
|
||||
}
|
||||
@@ -60,6 +67,7 @@ func processPendingTask(task *types.Task) error {
|
||||
|
||||
notsupportStreamStorage, notsupportStream := taskStorage.(storage.StorageNotSupportStream)
|
||||
cancelMarkUp := getCancelTaskMarkup(task)
|
||||
|
||||
if config.Cfg.Stream {
|
||||
if !notsupportStream {
|
||||
text, entities := buildProgressMessageEntity(task, 0, task.StartTime, 0)
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ type Task struct {
|
||||
StorageName string
|
||||
StoragePath string
|
||||
StartTime time.Time
|
||||
FileDBID uint
|
||||
|
||||
File *File
|
||||
FileMessageID int
|
||||
|
||||
Reference in New Issue
Block a user