Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Exclude User Search argument (#1399)

Now you can exclude a particular user from search by putting in the url ?nuserID=xxxx
As asked in #528
Cette révision appartient à :
akuma06 2017-08-26 04:28:34 +02:00 révisé par ewhal
Parent b3e3ec6083
révision 0e4f194b32
2 fichiers modifiés avec 66 ajouts et 12 suppressions

Voir le fichier

@ -38,6 +38,7 @@
</select>
Limit: <input type="number" name="limit" value="{{ Navigation.MaxItemPerPage }}" class="form-input spacing" min="1" max="300"/>
From: <input type="number" name="userID" placeholder="UserID" value="{{ Search.UserID > 0 ? Search.UserID : ""}}" class="form-input refine-userid"/>
Exclude: <input type="number" name="nuserID" placeholder="UserID" value="" class="form-input refine-userid"/>
</span>
<span class="form-refine">
<span class="spacing">{{ T("between")}}</span>

Voir le fichier

@ -182,13 +182,39 @@ func (p *TorrentParam) toESQuery(c *gin.Context) *Query {
}
if c.Query("userID") != "" {
if p.UserID > 0 {
query.Append("uploader_id:" + strconv.FormatInt(int64(p.UserID), 10))
if p.Hidden {
query.Append("hidden:false")
if !strings.Contains(c.Query("userID"), ",") {
if p.UserID > 0 {
query.Append("uploader_id:" + strconv.FormatInt(int64(p.UserID), 10))
if p.Hidden {
query.Append("hidden:false")
}
} else if p.UserID == 0 {
query.Append(fmt.Sprintf("(uploader_id: %d OR hidden:%t)", p.UserID, true))
}
} else {
userIDs := strings.Split(c.Query("userID"), ",")
for _, str := range userIDs {
if userID, err := strconv.Atoi(str); err == nil && userID >= 0 {
if userID > 0 {
query.Append(fmt.Sprintf("(uploader_id:%d AND hidden:false)", userID))
} else {
query.Append(fmt.Sprintf("(uploader_id:%d OR hidden:%t)", userID, true))
}
}
}
}
}
if c.Query("nuserID") != "" {
nuserID := strings.Split(c.Query("nuserID"), ",")
for _, str := range nuserID {
if userID, err := strconv.Atoi(str); err == nil && userID >= 0 {
if userID > 0 {
query.Append(fmt.Sprintf("NOT(uploader_id:%d AND hidden:false)", userID))
} else {
query.Append(fmt.Sprintf("NOT(uploader_id:%d AND hidden:false) !hidden:true", userID))
}
}
} else if p.UserID == 0 {
query.Append(fmt.Sprintf("(uploader_id: %d OR hidden:%t)", p.UserID, true))
}
}
@ -295,15 +321,42 @@ func (p *TorrentParam) toDBQuery(c *gin.Context) *Query {
}
if c.Query("userID") != "" {
if p.UserID > 0 {
query.Append("uploader", p.UserID)
if p.Hidden {
query.Append("hidden", false)
if !strings.Contains(c.Query("userID"), ",") {
if p.UserID > 0 {
query.Append("uploader", p.UserID)
if p.Hidden {
query.Append("hidden", false)
}
} else if p.UserID == 0 {
query.Append("(uploader = ? OR hidden = ?)", p.UserID, true)
}
} else {
userIDs := strings.Split(c.Query("userID"), ",")
for _, str := range userIDs {
if userID, err := strconv.Atoi(str); err == nil && userID >= 0 {
if userID > 0 {
query.Append("(uploader = ? AND hidden = ?)", userID, false)
} else {
query.Append("(uploader = ? OR hidden = ?)", userID, true)
}
}
}
} else if p.UserID == 0 {
query.Append("(uploader = ? OR hidden = ?)", p.UserID, true)
}
}
if c.Query("nuserID") != "" {
nuserID := strings.Split(c.Query("nuserID"), ",")
for _, str := range nuserID {
if userID, err := strconv.Atoi(str); err == nil && userID >= 0 {
if userID > 0 {
query.Append("NOT(uploader = ? AND hidden = ?)", userID, false)
} else {
query.Append("uploader <> ? AND hidden != ?", userID, true)
}
}
}
}
if p.FromID != 0 {
query.Append("torrent_id > ?", p.FromID)
}