* refactor: a big refactor. wip * refactor: port handle file * refactor: place all handlers * fix: task info nil pointer * feat: enhance task progress tracking and context management * feat: cancel task * feat: stream mode * feat: silent mode * feat: dir cmd * refactor: remove unused old file * feat: rule cmd * feat: handle silent mode * feat: batch task * fix: batch task progress and temp file cleanup * refactor: update file creation and cleanup methods for better resource management * feat: add save command with silent mode handling * feat: message link * feat: update message prompts to include file count in storage selection * feat: slient save links * refactor: reduce dup code * feat: rule type * feat: chose dir * feat: refactor file handling and storage rules, improve error handling and logging * feat: rule mode * feat: telegraph pics * fix: tphpics nil pointer and inaccurate dirpath * feat: silent save telegraph * feat: add suffix to avoid file overwrite * feat: new storage telegram * chore: tidy go mod
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package database
|
|
|
|
import "context"
|
|
|
|
func CreateDirForUser(ctx context.Context, userID uint, storageName, path string) error {
|
|
dir := Dir{
|
|
UserID: userID,
|
|
StorageName: storageName,
|
|
Path: path,
|
|
}
|
|
return db.WithContext(ctx).Create(&dir).Error
|
|
}
|
|
|
|
func GetDirByID(ctx context.Context, id uint) (*Dir, error) {
|
|
dir := &Dir{}
|
|
err := db.WithContext(ctx).First(dir, id).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return dir, err
|
|
}
|
|
|
|
func GetUserDirs(ctx context.Context, userID uint) ([]Dir, error) {
|
|
var dirs []Dir
|
|
err := db.WithContext(ctx).Where("user_id = ?", userID).Find(&dirs).Error
|
|
return dirs, err
|
|
}
|
|
|
|
func GetUserDirsByChatID(ctx context.Context, chatID int64) ([]Dir, error) {
|
|
user, err := GetUserByChatID(ctx, chatID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return GetUserDirs(ctx, user.ID)
|
|
}
|
|
|
|
func GetDirsByUserIDAndStorageName(ctx context.Context, userID uint, storageName string) ([]Dir, error) {
|
|
var dirs []Dir
|
|
err := db.WithContext(ctx).Where("user_id = ? AND storage_name = ?", userID, storageName).Find(&dirs).Error
|
|
return dirs, err
|
|
}
|
|
|
|
func GetDirsByUserChatIDAndStorageName(ctx context.Context, chatID int64, storageName string) ([]Dir, error) {
|
|
user, err := GetUserByChatID(ctx, chatID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return GetDirsByUserIDAndStorageName(ctx, user.ID, storageName)
|
|
}
|
|
|
|
func DeleteDirForUser(ctx context.Context, userID uint, storageName, path string) error {
|
|
return db.WithContext(ctx).Unscoped().Where("user_id = ? AND storage_name = ? AND path = ?", userID, storageName, path).Delete(&Dir{}).Error
|
|
}
|
|
|
|
func DeleteDirByID(ctx context.Context, id uint) error {
|
|
return db.WithContext(ctx).Unscoped().Delete(&Dir{}, id).Error
|
|
}
|