mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-10 17:52:44 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bd9b77856 |
12
common/os.go
12
common/os.go
@@ -33,6 +33,18 @@ func PurgeFile(path string) error {
|
|||||||
return RemoveEmptyDirectories(filepath.Dir(path))
|
return RemoveEmptyDirectories(filepath.Dir(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RmFileAfter(path string, td time.Duration) {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
logger.L.Errorf("Failed to create timer for %s: %s", path, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logger.L.Debugf("Remove file after %s: %s", td, path)
|
||||||
|
time.AfterFunc(td, func() {
|
||||||
|
PurgeFile(path)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 递归删除空目录
|
// 递归删除空目录
|
||||||
func RemoveEmptyDirectories(dirPath string) error {
|
func RemoveEmptyDirectories(dirPath string) error {
|
||||||
entries, err := os.ReadDir(dirPath)
|
entries, err := os.ReadDir(dirPath)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package core
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/amarnathcjd/gogram/telegram"
|
"github.com/amarnathcjd/gogram/telegram"
|
||||||
@@ -16,6 +17,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func processPendingTask(task types.Task) error {
|
func processPendingTask(task types.Task) error {
|
||||||
|
os.MkdirAll(config.Cfg.Temp.BasePath, os.ModePerm)
|
||||||
|
|
||||||
message, err := bot.Client.GetMessageByID(task.ChatID, task.MessageID)
|
message, err := bot.Client.GetMessageByID(task.ChatID, task.MessageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -33,9 +36,9 @@ func processPendingTask(task types.Task) error {
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if config.Cfg.Temp.CacheTTL > 0 {
|
if config.Cfg.Temp.CacheTTL > 0 {
|
||||||
common.PurgeFileAfter(dest, time.Duration(config.Cfg.Temp.CacheTTL)*time.Second)
|
common.RmFileAfter(dest, time.Duration(config.Cfg.Temp.CacheTTL)*time.Second)
|
||||||
} else {
|
} else {
|
||||||
if err := common.PurgeFile(dest); err != nil {
|
if err := os.Remove(dest); err != nil {
|
||||||
logger.L.Errorf("Failed to purge file: %s", err)
|
logger.L.Errorf("Failed to purge file: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user