0a765b5589
* Add new followers directly to user.Followers * Update user.go * Remove useless condition * Query an update of user followers if at 0 when looking at his profile * Fix comment not appearing until you refreshed the torrent page * call ViewHandler so that comments visually update properly * Remove now useless imports * Add "uploader" userstatus in comment * GetLikings() & GetFollowers() now return count too * Don't update follower count here * Update follower count directly here * show liking count * Update user.go * Update profile.jet.html * Update torrentParam.go * Fix locked torrents that were shown even when they should not * Update torrentParam_test.go * remove inline styling * Update main.css * Update upload.jet.html * Update main.css * Update tomorrow.css * Update classic.css * Update classic_colors.css * Update index_site.jet.html * Make announcements support markdown * Add markdown form to announcement creation * fix "report" text position * Add exclude search option to exclude words * Make sure the "NameLike" value is the search query because we edit it during a search * Show search content in page title for /feed too * rollback * Add "Search" variable that shows exactly what is being searched * Use "Search.Search" variable here instead of NameLike because NameLike is edited * Update torrentParam_test.go * Update torrentParam.go * remove redundant spaces from NameLike * Update torrentParam.go * Update torrentParam.go * Update torrentParam.go * Update torrentParam.go * turn date input into type date * bigger date inputs * add support for YYYY-MM-DD dates * rollback this change * rollback * Update search.jet.html * Update helpers.go * Update template_functions.go * Update torrentParam.go * only uploader & staff can comment on locked torrents * Add "Upload to Nyaa/Sukebei" button for mods * Update torrentlist.jet.html * Update view.jet.html * Update view.jet.html * fix wrong page title for notifications page
96 lignes
2,6 Kio
Go
96 lignes
2,6 Kio
Go
package search
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// DateFilter date to filter for
|
|
type DateFilter string
|
|
|
|
// ParseOld parses a date to a datefilter object and return true if it succeeded
|
|
// Deprecated: This function will be removed in 1.2, please use Parse
|
|
func (d *DateFilter) ParseOld(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
|
|
}
|
|
|
|
// Parse parses a date to a datefilter object and return true if it succeeded
|
|
// This function accept dates formatted in these way YYYY/MM/DD AND YYYY-MM-DD
|
|
func (d *DateFilter) Parse(s string) bool {
|
|
if s == "" {
|
|
*d = ""
|
|
return false
|
|
}
|
|
date, err := time.Parse("2006/01/02", s)
|
|
if err != nil {
|
|
date, err = time.Parse("2006-01-02", s)
|
|
if err != nil {
|
|
*d = ""
|
|
return false
|
|
}
|
|
}
|
|
*d = DateFilter(date.Format("2006-01-02"))
|
|
return true
|
|
}
|
|
|
|
// ToESQuery convert DateFilter type to ES query format
|
|
func (d DateFilter) ToESQuery() string {
|
|
if d != "" {
|
|
return string(d)
|
|
}
|
|
return "*"
|
|
}
|
|
|
|
// ToDBQuery convert DateFilter type to ES query format
|
|
func (d DateFilter) ToDBQuery() string {
|
|
if d != "" {
|
|
return string(d)
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func backwardCompatibility(max string, from string, to string, dtype string) (DateFilter, DateFilter) {
|
|
fromDate, toDate := DateFilter(""), DateFilter("")
|
|
maxage, err := strconv.Atoi(max)
|
|
if err != nil {
|
|
// if we can't convert it, this means maxage was not provided or wrongly, so we try to filter the query with other date filter args
|
|
// Deprecated : We have to give backward compatibility here to dateType
|
|
// This will be removed on 1.2, please remove from using it and go to maxage or Date argument
|
|
if dtype != "" {
|
|
// if to xxx is not provided, fromDate is equal to from xxx
|
|
if to != "" {
|
|
fromDate.ParseOld(to, dtype)
|
|
toDate.ParseOld(from, dtype)
|
|
return fromDate, toDate
|
|
}
|
|
|
|
fromDate.ParseOld(from, dtype)
|
|
return fromDate, toDate
|
|
}
|
|
// This will be the future default behavior
|
|
// We only try to parse the dates sent and if it works we assign them
|
|
fromDate.Parse(from)
|
|
toDate.Parse(to)
|
|
return fromDate, toDate
|
|
}
|
|
// Maxage behavior where we convert the substracted date to string
|
|
fromDate = DateFilter(time.Now().AddDate(0, 0, -maxage).Format("2006-01-02"))
|
|
return fromDate, toDate
|
|
}
|