feat: automatic file organization based on rules, close #28

This commit is contained in:
krau
2025-04-12 14:27:13 +08:00
parent 3bdef20e85
commit 166c27c70f
9 changed files with 345 additions and 43 deletions

View File

@@ -41,3 +41,7 @@ func GetDirsByUserIDAndStorageName(userID uint, storageName string) ([]Dir, erro
func DeleteDirForUser(userID uint, storageName, path string) error {
return db.Unscoped().Where("user_id = ? AND storage_name = ? AND path = ?", userID, storageName, path).Delete(&Dir{}).Error
}
func DeleteDirByID(id uint) error {
return db.Unscoped().Delete(&Dir{}, id).Error
}

22
dao/rule.go Normal file
View File

@@ -0,0 +1,22 @@
package dao
func CreateRule(rule *Rule) error {
return db.Create(rule).Error
}
func DeleteRule(ruleID uint) error {
return db.Unscoped().Delete(&Rule{}, ruleID).Error
}
func UpdateUserApplyRule(chatID int64, applyRule bool) error {
return db.Model(&User{}).Where("chat_id = ?", chatID).Update("apply_rule", applyRule).Error
}
func GetRulesByUserChatID(chatID int64) ([]Rule, error) {
var rules []Rule
err := db.Where("user_id = (SELECT id FROM users WHERE chat_id = ?)", chatID).Find(&rules).Error
if err != nil {
return nil, err
}
return rules, nil
}