feat: add shared media assets and fix credit lifecycle
This commit is contained in:
+4
-2
@@ -33,7 +33,7 @@ func (a *App) reserveCredit(userID, taskID uint, amount int64) (*CreditReservati
|
||||
}
|
||||
}
|
||||
var existing CreditReservation
|
||||
if err := tx.Where("task_id = ?", taskID).First(&existing).Error; err == nil {
|
||||
if err := tx.Where("task_id = ? AND status = ?", taskID, "reserved").Order("id desc").First(&existing).Error; err == nil {
|
||||
reservation = existing
|
||||
return nil
|
||||
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@@ -106,7 +106,9 @@ func (a *App) refundCredit(task *Task) error {
|
||||
return nil
|
||||
}
|
||||
if r.Status == "committed" {
|
||||
return errReservationState
|
||||
// A committed reservation belongs to a completed download. A later
|
||||
// storage/retry error must never debit or refund it a second time.
|
||||
return nil
|
||||
}
|
||||
if r.Status != "reserved" {
|
||||
return errReservationState
|
||||
|
||||
Reference in New Issue
Block a user