Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Refine form linked up & edited buildversion to commit hash (#1025)

Added the use of the new search form made by @kipukun
Buildversion are now commit hash. Please read the readme for new build
command (or just build using package.sh).
Cette révision appartient à :
akuma06 2017-06-20 02:06:01 +02:00 révisé par ewhal
Parent 0cfacdd48d
révision 9307087024
11 fichiers modifiés avec 121 ajouts et 44 suppressions

Voir le fichier

@ -23,9 +23,12 @@ All tested versions of Ubuntu fail to build, use a different OS or docker
Either use:
* `godep go build`
Or use this to have the build version in index.html:
* `godep go build -ldflags "-X main.buildversion=$(date -u +.%Y%m%d.%H%M%S)"`
* `godep go build -ldflags "-X main.buildversion=$(git rev-parse HEAD)"`
Or you can build using package.sh (Windows & Linux):
* `./package.sh`
* Download the DB and place it in your root folder named as "nyaa.db" (You want the merged.sqlite3 database, see the dev IRC for more info)
* `./nyaa`
* You can now access your local site over on [localhost:9999](http://localhost:9999)

Voir le fichier

@ -1,6 +1,9 @@
package common
import (
"math"
"time"
humanize "github.com/dustin/go-humanize"
"strconv"
@ -186,13 +189,51 @@ func ParseCategories(s string) []*Category {
type SizeBytes uint64
func (sz *SizeBytes) Parse(s string) bool {
func (sz *SizeBytes) Parse(s string, sizeType string) bool {
if s == "" {
*sz = 0
return false
}
var multiplier uint64
switch sizeType {
case "b":
multiplier = 1
case "k":
multiplier = uint64(math.Exp2(10))
case "m":
multiplier = uint64(math.Exp2(20))
case "g":
multiplier = uint64(math.Exp2(30))
}
size64, err := humanize.ParseBytes(s)
if err != nil {
*sz = 0
return false
}
*sz = SizeBytes(size64)
*sz = SizeBytes(size64 * multiplier)
return true
}
type DateFilter string
func (d *DateFilter) Parse(s string, dateType string) bool {
if s == "" {
*d = ""
return false
}
dateInt, err := strconv.Atoi(s)
if err != nil {
*d = ""
return false
}
switch dateType {
case "m":
*d = DateFilter(time.Now().AddDate(0, -dateInt, 0).Format("2006-01-02"))
case "y":
*d = DateFilter(time.Now().AddDate(-dateInt, 0, 0).Format("2006-01-02"))
default:
*d = DateFilter(time.Now().AddDate(0, 0, -dateInt).Format("2006-01-02"))
}
return true
}
@ -206,8 +247,8 @@ type SearchParam struct {
Status Status
Sort SortMode
Category Categories
FromDate string
ToDate string
FromDate DateFilter
ToDate DateFilter
Page int
UserID uint
Max uint

Voir le fichier

@ -28,8 +28,8 @@ type TorrentParam struct {
UserID uint32
TorrentID uint32
FromID uint32
FromDate string
ToDate string
FromDate DateFilter
ToDate DateFilter
NotNull string // csv
Null string // csv
NameLike string // csv
@ -67,11 +67,17 @@ func (p *TorrentParam) FromRequest(r *http.Request) {
status.Parse(r.URL.Query().Get("s"))
maxage, err := strconv.Atoi(r.URL.Query().Get("maxage"))
fromDate, toDate := DateFilter(""), DateFilter("")
if err != nil {
p.FromDate = r.URL.Query().Get("fromDate")
p.ToDate = r.URL.Query().Get("toDate")
// if to xxx is not provided, fromDate is equal to from xxx
if r.URL.Query().Get("toDate") != "" {
fromDate.Parse(r.URL.Query().Get("toDate"), r.URL.Query().Get("dateType"))
toDate.Parse(r.URL.Query().Get("fromDate"), r.URL.Query().Get("dateType"))
} else {
fromDate.Parse(r.URL.Query().Get("fromDate"), r.URL.Query().Get("dateType"))
}
} else {
p.FromDate = time.Now().AddDate(0, 0, -maxage).Format("2006-01-02")
fromDate = DateFilter(time.Now().AddDate(0, 0, -maxage).Format("2006-01-02"))
}
categories := ParseCategories(r.URL.Query().Get("c"))
@ -80,9 +86,10 @@ func (p *TorrentParam) FromRequest(r *http.Request) {
sortMode.Parse(r.URL.Query().Get("sort"))
var minSize SizeBytes
minSize.Parse(r.URL.Query().Get("minSize"))
var maxSize SizeBytes
maxSize.Parse(r.URL.Query().Get("maxSize"))
minSize.Parse(r.URL.Query().Get("minSize"), r.URL.Query().Get("sizeType"))
maxSize.Parse(r.URL.Query().Get("maxSize"), r.URL.Query().Get("sizeType"))
ascending := false
if r.URL.Query().Get("order") == "true" {
@ -103,6 +110,8 @@ func (p *TorrentParam) FromRequest(r *http.Request) {
p.Sort = sortMode
p.Category = categories
p.Language = language
p.FromDate = fromDate
p.ToDate = toDate
p.MinSize = minSize
p.MaxSize = maxSize
// FIXME 0 means no TorrentId defined
@ -149,11 +158,11 @@ func (p *TorrentParam) ToFilterQuery() string {
}
if p.FromDate != "" && p.ToDate != "" {
query += " date: [" + p.FromDate + " " + p.ToDate + "]"
query += " date: [" + string(p.FromDate) + " " + string(p.ToDate) + "]"
} else if p.FromDate != "" {
query += " date: [" + p.FromDate + " *]"
query += " date: [" + string(p.FromDate) + " *]"
} else if p.ToDate != "" {
query += " date: [* " + p.ToDate + "]"
query += " date: [* " + string(p.ToDate) + "]"
}
sMinSize := strconv.FormatUint(uint64(p.MinSize), 10)

Voir le fichier

@ -15,7 +15,7 @@ for i in "${OSes[@]}"; do
cc=${arr[1]}
rm -f nyaa nyaa.exe
echo -e "\nBuilding $os..."
echo GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v -ldflags="-X main.buildversion=$(date -u +.%Y%m%d.%H%M%S)"
GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v -ldflags="-X main.buildversion=$(date -u +.%Y%m%d.%H%M%S)"
echo GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v -ldflags="-X main.buildversion=`git rev-parse HEAD`"
GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v -ldflags="-X main.buildversion=$(git rev-parse HEAD)"
zip -9 -r dist/nyaa-${version}_${os}_amd64.zip os public templates service/user/locale *.md nyaa nyaa.exe
done

Voir le fichier

@ -106,8 +106,8 @@ func (f *ReassignForm) ExecuteAction() (int, error) {
// newPanelSearchForm : Helper that creates a search form without items/page field
// these need to be used when the templateVariables don't include `navigation`
func newPanelSearchForm() searchForm {
form := newSearchForm()
func newPanelSearchForm(r *http.Request) searchForm {
form := newSearchForm(r)
form.ShowItemsPerPage = false
return form
}
@ -116,7 +116,7 @@ func newPanelSearchForm() searchForm {
func newPanelCommonVariables(r *http.Request) commonTemplateVariables {
defer r.Body.Close()
common := newCommonVariables(r)
common.Search = newPanelSearchForm()
common.Search = newPanelSearchForm(r)
return common
}

Voir le fichier

@ -52,11 +52,7 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
if len(searchParam.Category) > 0 {
category = searchParam.Category[0].String()
}
commonVar.Search = searchForm{
SearchParam: searchParam,
Category: category,
ShowItemsPerPage: true,
}
commonVar.Search.SearchParam, commonVar.Search.Category = searchParam, category
htv := modelListVbs{commonVar, model.TorrentsToJSON(torrents), messages.GetAllErrors(), messages.GetAllInfos()}

Voir le fichier

@ -115,6 +115,12 @@ type searchForm struct {
common.SearchParam
Category string
ShowItemsPerPage bool
SizeType string
DateType string
MinSize string
MaxSize string
FromDate string
ToDate string
}
// Some Default Values to ease things out
@ -124,10 +130,21 @@ func newNavigation() navigation {
}
}
func newSearchForm() searchForm {
func newSearchForm(r *http.Request) searchForm {
sizeType := r.URL.Query().Get("sizeType")
if sizeType == "" {
sizeType = "m"
}
return searchForm{
Category: "_",
ShowItemsPerPage: true,
SizeType: sizeType,
DateType: r.URL.Query().Get("dateType"),
MinSize: r.URL.Query().Get("minSize"), // We need to overwrite the value here, since size are formatted
MaxSize: r.URL.Query().Get("maxSize"), // We need to overwrite the value here, since size are formatted
FromDate: r.URL.Query().Get("fromDate"), // We need to overwrite the value here, since we can have toDate instead and date are formatted
ToDate: r.URL.Query().Get("toDate"), // We need to overwrite the value here, since date are formatted
}
}
@ -146,7 +163,7 @@ func getUser(r *http.Request) *model.User {
func newCommonVariables(r *http.Request) commonTemplateVariables {
return commonTemplateVariables{
Navigation: newNavigation(),
Search: newSearchForm(),
Search: newSearchForm(r),
T: publicSettings.GetTfuncFromRequest(r),
Theme: publicSettings.GetThemeFromRequest(r),
Mascot: publicSettings.GetMascotFromRequest(r),

Voir le fichier

@ -39,25 +39,32 @@
{{end}}
{{define "search_refine"}}
<div style="text-align:left;" class="box">
<span>Between <input class="form-input" size="7" name="minSize" type="text"> and <input size="7" class="form-input" name="maxSize" type="text">
<form method="GET" action="">
<input type="hidden" name="s" value="{{.Search.Status}}"/>
<input type="hidden" name="c" value="{{.Search.Category}}"/>
<input type="hidden" name="max" value="{{.Navigation.MaxItemPerPage}}"/>
<input type="hidden" name="userID" value="{{.Search.UserID}}"/>
<input type="hidden" name="q" value="{{.Search.Query}}"/>
<span>Between <input class="form-input" size="7" name="minSize" type="text" value="{{.Search.MinSize}}"> and <input size="7" class="form-input" name="maxSize" type="text" value="{{.Search.MaxSize}}">
<select name="sizeType" class="form-input">
<option value="b">B</option>
<option value="k">KiB</option>
<option selected value="m">MiB</option>
<option value="g">GiB</option>
<option value="b"{{if eq .Search.SizeType "b"}} selected{{end}}>B</option>
<option value="k"{{if eq .Search.SizeType "k"}} selected{{end}}>KiB</option>
<option value="m"{{if eq .Search.SizeType "m"}} selected{{end}}>MiB</option>
<option value="g"{{if eq .Search.SizeType "g"}} selected{{end}}>GiB</option>
</select>
large.
</span>
<br>
<span>Between <input class="form-input" size="7" name="minDate" type="text"> and <input class="form-input" size="7" name="minDate" type="text">
<span>Between <input class="form-input" size="7" name="fromDate" type="text" value="{{.Search.FromDate}}"> and <input class="form-input" size="7" name="toDate" type="text" value="{{.Search.ToDate}}">
<select name="dateType" class="form-input">
<option value="d">days</option>
<option value="m">months</option>
<option value="y">years</option>
<option value="d"{{if eq .Search.DateType "d"}} selected{{end}}>days</option>
<option value="m"{{if eq .Search.DateType "m"}} selected{{end}}>months</option>
<option value="y"{{if eq .Search.DateType "y"}} selected{{end}}>years</option>
</select>
old.
</span>
<br>
<button style="margin-top:10px;" type="submit" class="form-input">Refine</button>
</form>
</div>
{{end}}

Voir le fichier

@ -91,7 +91,7 @@
<div class="footer-opt">
<p><a href="/settings">{{ call $.T "change_settings" }}</a></p>
</div>
<span><i>Powered by <a href="#">NyaaPantsu</a> v{{ .Config.Version }}{{ .Config.Build }}</i></span>
<span><i>Powered by <a href="#">NyaaPantsu</a> v{{ .Config.Version }} - commit {{ .Config.Build }}</i></span>
</div>
</footer>
</div>

Voir le fichier

@ -101,7 +101,7 @@
<div class="footer-opt">
<p><a href="/settings">{{ call $.T "change_settings" }}</a></p>
</div>
<span><i>Powered by <a href="#">NyaaPantsu</a> v{{ .Config.Version }}{{ .Config.Build }}</i></span>
<span><i>Powered by <a href="#">NyaaPantsu</a> v{{ .Config.Version }} - commit {{ .Config.Build }}</i></span>
</div>
</footer>
</div>

Voir le fichier

@ -129,16 +129,20 @@ func searchByQueryPostgres(r *http.Request, pagenum int, countAll bool, withUser
maxage, err := strconv.Atoi(r.URL.Query().Get("maxage"))
if err != nil {
search.FromDate = r.URL.Query().Get("fromDate")
search.ToDate = r.URL.Query().Get("toDate")
if r.URL.Query().Get("toDate") != "" {
search.FromDate.Parse(r.URL.Query().Get("toDate"), r.URL.Query().Get("dateType"))
search.ToDate.Parse(r.URL.Query().Get("fromDate"), r.URL.Query().Get("dateType"))
} else {
search.FromDate.Parse(r.URL.Query().Get("fromDate"), r.URL.Query().Get("dateType"))
}
} else {
search.FromDate = time.Now().AddDate(0, 0, -maxage).Format("2006-01-02")
search.FromDate = common.DateFilter(time.Now().AddDate(0, 0, -maxage).Format("2006-01-02"))
}
search.Category = common.ParseCategories(r.URL.Query().Get("c"))
search.Status.Parse(r.URL.Query().Get("s"))
search.Sort.Parse(r.URL.Query().Get("sort"))
search.MinSize.Parse(r.URL.Query().Get("minSize"))
search.MaxSize.Parse(r.URL.Query().Get("maxSize"))
search.MinSize.Parse(r.URL.Query().Get("minSize"), r.URL.Query().Get("sizeType"))
search.MaxSize.Parse(r.URL.Query().Get("maxSize"), r.URL.Query().Get("sizeType"))
orderBy := search.Sort.ToDBField()
if search.Sort == common.Date {