Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/models/tag/helpers.go

45 lignes
1,4 Kio
Go
Brut Vue normale Historique

2017-07-29 15:20:57 +02:00
package tags
import (
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/users"
"github.com/NyaaPantsu/nyaa/utils/log"
)
func Filter(tag string, tagType string, torrentID uint) bool {
2017-07-30 03:29:09 +02:00
if torrentID == 0 || tagType == "" || tag == "" {
return false
}
2017-07-29 15:20:57 +02:00
tagSum := models.Tag{}
if err := models.ORM.Select("tag, type, accepted, SUM(weight) as total").Where("torrent_id = ? AND tag = ? AND type = ?", torrentID, tag, tagType).Group("type, tag").Find(&tagSum).Error; err == nil {
if tagSum.Total > config.Get().Torrents.Tags.MaxWeight {
tags, err := FindAll(tagType, torrentID)
if err != nil {
return false
}
for _, toDelete := range tags {
user, _, err := users.FindRawByID(toDelete.UserID)
if err != nil {
log.CheckErrorWithMessage(err, "USER_NOT_FOUND: Couldn't update pantsu points!")
}
if toDelete.Tag == tag {
user.IncreasePantsu()
} else {
user.DecreasePantsu()
}
user.Update()
toDelete.Delete()
}
/* err := DeleteAllType(tagType, torrentID) // We can also delete them in batch
log.CheckError(err) */
tagSum.Accepted = true
tagSum.UserID = 0 // System ID
tagSum.Weight = config.Get().Torrents.Tags.MaxWeight // Overriden to the maximal value
models.ORM.Save(&tagSum) // We only add back the tag accepted
return true
}
}
return false
}