mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 17:41:57 +08:00
Modify: clean modals
This commit is contained in:
@@ -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++
|
||||
|
||||
Reference in New Issue
Block a user