diff --git a/pkg/crontab/init.go b/pkg/crontab/init.go index 1ead28f82a4224266f5b19f4377e6abecce62c64..72760fccfa1ecbbe17e0542c5a77f8eab7fd2f40 100644 --- a/pkg/crontab/init.go +++ b/pkg/crontab/init.go @@ -28,10 +28,6 @@ func Init() { switch k { case "cron_garbage_collect": handler = garbageCollect - case "cron_notify_user": - handler = notifyExpiredVAS - case "cron_ban_user": - handler = banOverusedUser default: util.Log().Warning("未知定时任务类型 [%s],跳过", k) continue @@ -42,6 +38,5 @@ func Init() { } } - banOverusedUser() Cron.Start() } diff --git a/pkg/crontab/vas.go b/pkg/crontab/vas.go deleted file mode 100644 index 3414469a47967f8e012ebc81197d9f12f02549c1..0000000000000000000000000000000000000000 --- a/pkg/crontab/vas.go +++ /dev/null @@ -1,83 +0,0 @@ -package crontab - -import ( - model "github.com/HFO4/cloudreve/models" - "github.com/HFO4/cloudreve/pkg/email" - "github.com/HFO4/cloudreve/pkg/util" -) - -func notifyExpiredVAS() { - checkStoragePack() - checkUserGroup() - util.Log().Info("定时任务 [cron_notify_user] 执行完毕") -} - -// banOverusedUser 封禁超出宽容期的用户 -func banOverusedUser() { - users := model.GetTolerantExpiredUser() - for _, user := range users { - - // 清除最后通知日期标记 - user.ClearNotified() - - // 检查容量是否超额 - if user.Storage > user.Group.MaxStorage+user.GetAvailablePackSize() { - // 封禁用户 - user.SetStatus(model.OveruseBaned) - } - } -} - -// checkUserGroup 检查已过期用户组 -func checkUserGroup() { - users := model.GetGroupExpiredUsers() - for _, user := range users { - - // 将用户回退到初始用户组 - user.GroupFallback() - - // 重新加载用户 - user, _ = model.GetUserByID(user.ID) - - // 检查容量是否超额 - if user.Storage > user.Group.MaxStorage+user.GetAvailablePackSize() { - // 如果超额,则通知用户 - sendNotification(&user, "用户组过期") - // 更新最后通知日期 - user.Notified() - } - } -} - -// checkStoragePack 检查已过期的容量包 -func checkStoragePack() { - packs := model.GetExpiredStoragePack() - for _, pack := range packs { - // 删除过期的容量包 - pack.Delete() - - //找到所属用户 - user, err := model.GetUserByID(pack.UserID) - if err != nil { - util.Log().Warning("[定时任务] 无法获取用户 [UID=%d] 信息, %s", pack.UserID, err) - continue - } - - // 检查容量是否超额 - if user.Storage > user.Group.MaxStorage+user.GetAvailablePackSize() { - // 如果超额,则通知用户 - sendNotification(&user, "容量包过期") - - // 更新最后通知日期 - user.Notified() - - } - } -} - -func sendNotification(user *model.User, reason string) { - title, body := email.NewOveruseNotification(user.Nick, reason) - if err := email.Send(user.Email, title, body); err != nil { - util.Log().Warning("无法发送通知邮件, %s", err) - } -}