mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-28 02:31:34 +08:00
refactor: update logging levels and remove unused code
This commit is contained in:
@@ -23,10 +23,6 @@ func initCache() {
|
||||
Cache = &CommonCache{cache: freecache.NewCache(10 * 1024 * 1024)}
|
||||
}
|
||||
|
||||
func GetCache() *CommonCache {
|
||||
return Cache
|
||||
}
|
||||
|
||||
func (c *CommonCache) Get(key string, value *types.File) error {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package common
|
||||
|
||||
func Init() {
|
||||
initClient()
|
||||
initCache()
|
||||
}
|
||||
|
||||
35
common/os.go
35
common/os.go
@@ -9,20 +9,6 @@ import (
|
||||
"github.com/krau/SaveAny-Bot/logger"
|
||||
)
|
||||
|
||||
// 创建文件, 自动创建目录
|
||||
func MkFile(path string, data []byte) error {
|
||||
err := os.MkdirAll(filepath.Dir(path), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, data, os.ModePerm)
|
||||
}
|
||||
|
||||
func FileExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// 删除文件, 并清理空目录. 如果文件不存在则返回 nil
|
||||
func PurgeFile(path string) error {
|
||||
if err := os.Remove(path); err != nil {
|
||||
@@ -60,24 +46,3 @@ func RemoveEmptyDirectories(dirPath string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 在指定时间后删除和清理文件 (定时器)
|
||||
func PurgeFileAfter(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("Purge file after %s: %s", td, path)
|
||||
time.AfterFunc(td, func() {
|
||||
PurgeFile(path)
|
||||
})
|
||||
}
|
||||
|
||||
func MkCache(path string, data []byte, td time.Duration) {
|
||||
if err := MkFile(path, data); err != nil {
|
||||
logger.L.Errorf("failed to save cache file: %s", err)
|
||||
} else {
|
||||
go PurgeFileAfter(path, td)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/krau/SaveAny-Bot/config"
|
||||
)
|
||||
|
||||
var ReqClient *req.Client
|
||||
|
||||
func initClient() {
|
||||
ReqClient = req.NewClient().SetOutputDirectory(config.Cfg.Temp.BasePath).SetTimeout(86400 * time.Second)
|
||||
}
|
||||
|
||||
func GetCacheFilePath(filename string) string {
|
||||
return filepath.Join(config.Cfg.Temp.BasePath, filename)
|
||||
}
|
||||
Reference in New Issue
Block a user