Add username search (#1434)
* Add username search Quite simple, you need to provide ?user=xxxx * Add userID search + Changed name of input field Now ?user=xxx can also search userID. For that you need to prefix it with "#". Example: * ?user=akuma06 would search torrents based on username akuma06 * ?user=#123 would search torrents based on userID 123 (be aware that you have to encode the "#" in url format %23) * Update search.jet.html (#1436) * Update main.css (#1435)
Cette révision appartient à :
Parent
ed61de6276
révision
9bb26a7dbe
4 fichiers modifiés avec 28 ajouts et 3 suppressions
|
@ -368,8 +368,8 @@ select.form-input {
|
|||
width: 49px;
|
||||
}
|
||||
|
||||
.box.refine input[type="number"].refine-userid {
|
||||
width: 65px;
|
||||
.refine-user {
|
||||
width: 103px;
|
||||
}
|
||||
.box.refine .language {
|
||||
position: absolute;
|
||||
|
|
|
@ -32,6 +32,7 @@ type SearchForm struct {
|
|||
MaxSize string
|
||||
FromDate string
|
||||
ToDate string
|
||||
User string
|
||||
}
|
||||
|
||||
// NewNavigation return a navigation struct with
|
||||
|
@ -51,6 +52,7 @@ func NewSearchForm(c *gin.Context) SearchForm {
|
|||
ShowItemsPerPage: true,
|
||||
ShowRefine: false,
|
||||
SizeType: sizeType,
|
||||
User: c.Query("user"),
|
||||
DateType: c.Query("dateType"),
|
||||
MinSize: c.Query("minSize"), // We need to overwrite the value here, since size are formatted
|
||||
MaxSize: c.Query("maxSize"), // We need to overwrite the value here, since size are formatted
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
<option value="4" {{if Search.Status == 4}}selected{{end}}>A+</option>
|
||||
</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"/>
|
||||
From: <input type="text" name="user" placeholder="Username/ID" value="{{ Search.User }}" class="form-input refine-user"/>
|
||||
</span>
|
||||
<span class="form-refine">
|
||||
<span class="spacing">{{ T("between")}}</span>
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/models/users"
|
||||
|
||||
elastic "gopkg.in/olivere/elastic.v5"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/models"
|
||||
|
@ -121,6 +123,27 @@ func (p *TorrentParam) FromRequest(c *gin.Context) {
|
|||
// Get the user id from the url
|
||||
p.UserID = parseUInt(c, "userID")
|
||||
|
||||
// if userID is not provided and username is, we try to find the user ID with the username
|
||||
if username := c.Query("user"); username != "" && p.UserID == 0 {
|
||||
log.Info(fmt.Sprint(username[0]))
|
||||
if username[0] == '#' {
|
||||
log.Info(username[1:])
|
||||
u64, err := strconv.ParseUint(username[1:], 10, 32)
|
||||
if err == nil {
|
||||
p.UserID = uint32(u64)
|
||||
}
|
||||
} else {
|
||||
user, _, _, err := users.FindByUsername(username)
|
||||
if err == nil {
|
||||
p.UserID = uint32(user.ID)
|
||||
}
|
||||
}
|
||||
// For other functions, we need to set userID in the request query
|
||||
q := c.Request.URL.Query()
|
||||
q.Set("userID", fmt.Sprintf("%d", p.UserID))
|
||||
c.Request.URL.RawQuery = q.Encode()
|
||||
}
|
||||
|
||||
// Limit search to DbID
|
||||
// Get the id from the url
|
||||
p.AnidbID = parseUInt(c, "anidb")
|
||||
|
|
Référencer dans un nouveau ticket