Modify: clean modals

This commit is contained in:
HFO4
2020-03-11 15:22:21 +08:00
parent 4d70f9fa3e
commit 4ba24e0cf1
30 changed files with 22 additions and 598 deletions

View File

@@ -8,7 +8,6 @@ import (
"github.com/HFO4/cloudreve/pkg/util"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"math"
"strings"
"time"
)
@@ -24,7 +23,6 @@ type Share struct {
Downloads int // 下载数
RemainDownloads int // 剩余下载配额,负值标识无限制
Expires *time.Time // 过期时间,空值表示无过期时间
Score int // 每人次下载扣除积分
PreviewEnabled bool // 是否允许直接预览
SourceName string `gorm:"index:source"` // 用于搜索的字段
@@ -136,12 +134,6 @@ func (share *Share) CanBeDownloadBy(user *User) error {
}
return errors.New("您当前的用户组无权下载")
}
// 需要积分但未登录
if share.Score > 0 && user.IsAnonymous() {
return errors.New("未登录用户无法下载")
}
return nil
}
@@ -156,12 +148,9 @@ func (share *Share) WasDownloadedBy(user *User, c *gin.Context) (exist bool) {
return exist
}
// DownloadBy 增加下载次数、检查积分等,匿名用户不会缓存
// DownloadBy 增加下载次数,匿名用户不会缓存
func (share *Share) DownloadBy(user *User, c *gin.Context) error {
if !share.WasDownloadedBy(user, c) {
if err := share.Purchase(user); err != nil {
return err
}
share.Downloaded()
if !user.IsAnonymous() {
cache.Set(fmt.Sprintf("share_%d_%d", share.ID, user.ID), true,
@@ -173,25 +162,6 @@ func (share *Share) DownloadBy(user *User, c *gin.Context) error {
return nil
}
// Purchase 使用积分购买分享
func (share *Share) Purchase(user *User) error {
// 不需要付积分
if share.Score == 0 || user.Group.OptionsSerialized.ShareFree || user.ID == share.UserID {
return nil
}
ok := user.PayScore(share.Score)
if !ok {
return errors.New("积分不足")
}
scoreRate := GetIntSetting("share_score_rate", 100)
gainedScore := int(math.Ceil(float64(share.Score*scoreRate) / 100))
share.Creator().AddScore(gainedScore)
return nil
}
// Viewed 增加访问次数
func (share *Share) Viewed() {
share.Views++