Adds a calllback function on type to update anidbid when a tag is accepted
Cette révision appartient à :
Parent
6f983260ae
révision
a456abe06e
1 fichiers modifiés avec 17 ajouts et 0 suppressions
|
@ -3,12 +3,15 @@ package tags
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/NyaaPantsu/nyaa/models/torrents"
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/config"
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
"github.com/NyaaPantsu/nyaa/models"
|
"github.com/NyaaPantsu/nyaa/models"
|
||||||
"github.com/NyaaPantsu/nyaa/models/users"
|
"github.com/NyaaPantsu/nyaa/models/users"
|
||||||
"github.com/NyaaPantsu/nyaa/utils/log"
|
"github.com/NyaaPantsu/nyaa/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Filter check if a tag type has reached the maximal votes and removes the other tag of the same type
|
||||||
func Filter(tag string, tagType string, torrentID uint) bool {
|
func Filter(tag string, tagType string, torrentID uint) bool {
|
||||||
if torrentID == 0 || tagType == "" || tag == "" {
|
if torrentID == 0 || tagType == "" || tag == "" {
|
||||||
return false
|
return false
|
||||||
|
@ -42,8 +45,22 @@ func Filter(tag string, tagType string, torrentID uint) bool {
|
||||||
tagSum.UserID = 0 // System ID
|
tagSum.UserID = 0 // System ID
|
||||||
tagSum.Weight = config.Get().Torrents.Tags.MaxWeight // Overriden to the maximal value
|
tagSum.Weight = config.Get().Torrents.Tags.MaxWeight // Overriden to the maximal value
|
||||||
models.ORM.Save(&tagSum) // We only add back the tag accepted
|
models.ORM.Save(&tagSum) // We only add back the tag accepted
|
||||||
|
callbackOnType(&tagSum)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func callbackOnType(tag *models.Tag) {
|
||||||
|
switch tag.Type {
|
||||||
|
case "anidbid", "vndbid":
|
||||||
|
if tag.Accepted && tag.TorrentID > 0 {
|
||||||
|
torrent, err := torrents.FindByID(tag.TorrentID)
|
||||||
|
if err == nil {
|
||||||
|
torrent.DbID = tag.Tag
|
||||||
|
torrent.Update(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Référencer dans un nouveau ticket