mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Add server download task creation and related UI components
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user