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/utils/search/status.go
akuma06 38d3e45ef4 Fix search Status (#1467)
Should fix #1428 ?s=2 and others. Reason: the sql query wasn't correct when filtering (status >= ? = ?)
2017-09-03 10:11:19 +10:00

78 lignes
1,5 Kio
Go

package search
const (
// ShowAll by default show all torrents
ShowAll Status = iota
// Normal torrent
Normal
// FilterRemakes filter torrent remakes
FilterRemakes
// Trusted trusted torrents
Trusted
// APlus torrents not used anymore
APlus
)
// Status torrent status
type Status uint8
// String convert a status to a string
func (st *Status) String() string {
switch *st {
case Normal:
return "1"
case FilterRemakes:
return "2"
case Trusted:
return "3"
case APlus:
return "4"
}
return ""
}
// Parse a string to a status
func (st *Status) Parse(s string) {
switch s {
case "1":
*st = Normal
case "2":
*st = FilterRemakes
case "3":
*st = Trusted
case "4":
*st = APlus
default:
*st = ShowAll
}
}
// ToESQuery prepare an ES statement for status
func (st *Status) ToESQuery() string {
if *st != ShowAll {
if *st != FilterRemakes {
// Only show torrents with status over the one specified
return "status:>" + st.String()
}
/* From the old nyaa behavior, FilterRemake means everything BUT
* remakes
*/
return "!status:" + st.String()
}
return ""
}
// ToDBQuery prepare a DB statement for status
func (st *Status) ToDBQuery() (string, string) {
if *st != ShowAll {
if *st != FilterRemakes {
// Only show torrents with status over the one specified
return "status >= ?", st.String()
}
/* From the old nyaa behavior, FilterRemake means everything BUT
* remakes
*/
return "status <> ?", st.String()
}
return "", ""
}