feat(source link): record downloads for redirected source link

This commit is contained in:
HFO4 2022-10-29 11:08:16 +08:00
parent 8d7ecedf47
commit 1c25232b06
2 changed files with 7 additions and 0 deletions

View file

@ -23,6 +23,7 @@ func ValidateSourceLink() gin.HandlerFunc {
return
}
sourceLink.Downloaded()
c.Set("source_link", sourceLink)
c.Next()
}

View file

@ -39,3 +39,9 @@ func GetSourceLinkByID(id interface{}) (*SourceLink, error) {
return link, result.Error
}
// Viewed 增加访问次数
func (s *SourceLink) Downloaded() {
s.Downloads++
DB.Model(s).UpdateColumn("downloads", gorm.Expr("downloads + ?", 1))
}