Add server download task creation and related UI components

This commit is contained in:
2025-05-26 20:51:02 +08:00
parent 764ec5f38c
commit 7e612b3dd4
7 changed files with 324 additions and 18 deletions

View File

@@ -153,3 +153,19 @@ func SetFileStorageKey(id string, storageKey string) error {
}
return nil
}
func SetFileStorageKeyAndSize(id string, storageKey string, size int64) error {
f := &model.File{}
if err := db.Where("uuid = ?", id).First(f).Error; err != nil {
return err
}
f.StorageKey = storageKey
f.Size = size
if err := db.Save(f).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return model.NewNotFoundError("file not found")
}
return err
}
return nil
}

View File

@@ -1,17 +1,10 @@
package dao
import "nysoure/server/model"
func SetStatistic(key string, value int64) error {
statistic := &model.Statistic{
Key: key,
Value: value,
}
if err := db.Save(statistic).Error; err != nil {
return err
}
return nil
}
import (
"errors"
"gorm.io/gorm"
"nysoure/server/model"
)
func GetStatistic(key string) int64 {
statistic := &model.Statistic{}
@@ -22,3 +15,21 @@ func GetStatistic(key string) int64 {
}
return statistic.Value
}
func UpdateStatistic(key string, offset int64) error {
return db.Transaction(func(tx *gorm.DB) error {
statistic := &model.Statistic{}
if err := tx.Where(&model.Statistic{
Key: key,
}).First(statistic).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
statistic.Key = key
statistic.Value = offset
return tx.Create(statistic).Error
}
return err
}
statistic.Value += offset
return tx.Save(statistic).Error
})
}