From a3a24e1cf44aa4e95a8684c86455a2b7064ac623 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 23 七月 2024 04:51:29 +0800
Subject: [PATCH] 定时删除本地存储的图片
---
service/clean.go | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/service/clean.go b/service/clean.go
index 985a281..f396ece 100644
--- a/service/clean.go
+++ b/service/clean.go
@@ -1,6 +1,14 @@
package service
-import "gat1400Exchange/models"
+import (
+ "os"
+ "path"
+ "path/filepath"
+ "time"
+
+ "gat1400Exchange/config"
+ "gat1400Exchange/models"
+)
func CleanExpireData() {
var pos models.Positions
@@ -8,4 +16,23 @@
var cache models.Cache
cache.Clean()
+
+ if config.ClientConf.UploadType == "url" {
+ imagePath := path.Join(config.LogConf.Path, "gat1400_face_images")
+ deleteOldFolders(imagePath)
+ }
+}
+
+func deleteOldFolders(root string) error {
+ return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ if info.IsDir() && time.Now().Sub(info.ModTime()) > 24*time.Hour {
+ return os.RemoveAll(path)
+ }
+
+ return nil
+ })
}
--
Gitblit v1.8.0