Feat: recycling file storage and user capacity when uploading canceled

This commit is contained in:
HFO4
2019-11-18 14:06:15 +08:00
parent 160f964564
commit 631c23f065
9 changed files with 93 additions and 14 deletions

View File

@@ -54,8 +54,18 @@ type UserOption struct {
WebDAVKey string `json:"webdav_key"`
}
// DeductionCapacity 扣除用户容量配额
func (user *User) DeductionCapacity(size uint64) bool {
// DeductionStorage 减少用户已用容量
func (user *User) DeductionStorage(size uint64) bool {
if size <= user.Storage {
user.Storage -= size
DB.Save(user)
return true
}
return false
}
// IncreaseStorage 检查并增加用户已用容量
func (user *User) IncreaseStorage(size uint64) bool {
if size <= user.GetRemainingCapacity() {
user.Storage += size
DB.Save(user)