Run go fmt and add swap files to gitignore
Cette révision appartient à :
Parent
480064f3a2
révision
6adce8eda9
5 fichiers modifiés avec 118 ajouts et 112 suppressions
1
.gitignore
externe
1
.gitignore
externe
|
@ -5,3 +5,4 @@ nyaa
|
||||||
nyaa.exe
|
nyaa.exe
|
||||||
nyaa-master.exe
|
nyaa-master.exe
|
||||||
*.zip
|
*.zip
|
||||||
|
*.swp
|
||||||
|
|
12
main.go
12
main.go
|
@ -40,7 +40,7 @@ func checkErr(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func unZlib(description []byte) string {
|
func unZlib(description []byte) string {
|
||||||
if (len(description) > 0) {
|
if len(description) > 0 {
|
||||||
b := bytes.NewReader(description)
|
b := bytes.NewReader(description)
|
||||||
log.Println(b)
|
log.Println(b)
|
||||||
z, err := zlib.NewReader(b)
|
z, err := zlib.NewReader(b)
|
||||||
|
@ -112,7 +112,9 @@ func searchHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
maxPerPage = 50 // default Value maxPerPage
|
maxPerPage = 50 // default Value maxPerPage
|
||||||
}
|
}
|
||||||
pagenum, _ := strconv.Atoi(html.EscapeString(page))
|
pagenum, _ := strconv.Atoi(html.EscapeString(page))
|
||||||
if (pagenum == 0) { pagenum = 1 }
|
if pagenum == 0 {
|
||||||
|
pagenum = 1
|
||||||
|
}
|
||||||
searchQuery := r.URL.Query().Get("q")
|
searchQuery := r.URL.Query().Get("q")
|
||||||
cat := r.URL.Query().Get("c")
|
cat := r.URL.Query().Get("c")
|
||||||
stat := r.URL.Query().Get("s")
|
stat := r.URL.Query().Get("s")
|
||||||
|
@ -151,7 +153,6 @@ func searchHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
navigationTorrents := Navigation{nbTorrents, maxPerPage, pagenum, "search_page"}
|
navigationTorrents := Navigation{nbTorrents, maxPerPage, pagenum, "search_page"}
|
||||||
htv := HomeTemplateVariables{b, getAllCategories(false), searchQuery, stat, cat, sort, order, navigationTorrents, r.URL, mux.CurrentRoute(r)}
|
htv := HomeTemplateVariables{b, getAllCategories(false), searchQuery, stat, cat, sort, order, navigationTorrents, r.URL, mux.CurrentRoute(r)}
|
||||||
|
|
||||||
|
|
||||||
err := templates.ExecuteTemplate(w, "index.html", htv)
|
err := templates.ExecuteTemplate(w, "index.html", htv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
@ -246,7 +247,9 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
nbTorrents := 0
|
nbTorrents := 0
|
||||||
pagenum, _ := strconv.Atoi(html.EscapeString(page))
|
pagenum, _ := strconv.Atoi(html.EscapeString(page))
|
||||||
if (pagenum == 0) { pagenum = 1 }
|
if pagenum == 0 {
|
||||||
|
pagenum = 1
|
||||||
|
}
|
||||||
|
|
||||||
b := []TorrentsJson{}
|
b := []TorrentsJson{}
|
||||||
torrents, nbTorrents := getAllTorrents(maxPerPage, maxPerPage*(pagenum-1))
|
torrents, nbTorrents := getAllTorrents(maxPerPage, maxPerPage*(pagenum-1))
|
||||||
|
@ -289,7 +292,6 @@ func main() {
|
||||||
router.HandleFunc("/feed.xml", rssHandler)
|
router.HandleFunc("/feed.xml", rssHandler)
|
||||||
router.HandleFunc("/view/{id}", viewHandler).Name("view_torrent")
|
router.HandleFunc("/view/{id}", viewHandler).Name("view_torrent")
|
||||||
|
|
||||||
|
|
||||||
http.Handle("/", router)
|
http.Handle("/", router)
|
||||||
|
|
||||||
// Set up server,
|
// Set up server,
|
||||||
|
|
|
@ -90,7 +90,6 @@ type WhereParams struct {
|
||||||
params []interface{}
|
params []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Function to interact with Models
|
/* Function to interact with Models
|
||||||
*
|
*
|
||||||
* Get the torrents with where clause
|
* Get the torrents with where clause
|
||||||
|
@ -132,7 +131,7 @@ func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs
|
||||||
var torrents []Torrents
|
var torrents []Torrents
|
||||||
var dbQuery *gorm.DB
|
var dbQuery *gorm.DB
|
||||||
var count int
|
var count int
|
||||||
if (parameters != nil) { // if there is where parameters
|
if parameters != nil { // if there is where parameters
|
||||||
db.Model(&torrents).Where(parameters.conditions, parameters.params...).Count(&count)
|
db.Model(&torrents).Where(parameters.conditions, parameters.params...).Count(&count)
|
||||||
dbQuery = db.Model(&torrents).Where(parameters.conditions, parameters.params...)
|
dbQuery = db.Model(&torrents).Where(parameters.conditions, parameters.params...)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"math"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var funcMap = template.FuncMap{
|
var funcMap = template.FuncMap{
|
||||||
"min": math.Min,
|
"min": math.Min,
|
||||||
"genRoute": func(name string, params ...string) string {
|
"genRoute": func(name string, params ...string) string {
|
||||||
url, err := router.Get(name).URL(params...)
|
url, err := router.Get(name).URL(params...)
|
||||||
if (err == nil) {
|
if err == nil {
|
||||||
return url.String()
|
return url.String()
|
||||||
}
|
}
|
||||||
return "error"
|
return "error"
|
||||||
|
@ -27,17 +27,21 @@ var funcMap = template.FuncMap{
|
||||||
ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">«</span></a></li>"
|
ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">«</span></a></li>"
|
||||||
}
|
}
|
||||||
startValue := 1
|
startValue := 1
|
||||||
if (nav.CurrentPage > pagesSelectable) {
|
if nav.CurrentPage > pagesSelectable {
|
||||||
startValue = (int(math.Min((float64(nav.CurrentPage)+math.Floor(float64(pagesSelectable)/2)), maxPages)) - pagesSelectable + 1)
|
startValue = (int(math.Min((float64(nav.CurrentPage)+math.Floor(float64(pagesSelectable)/2)), maxPages)) - pagesSelectable + 1)
|
||||||
}
|
}
|
||||||
endValue := (startValue + pagesSelectable - 1)
|
endValue := (startValue + pagesSelectable - 1)
|
||||||
if (endValue > int(maxPages)) { endValue = int(maxPages) }
|
if endValue > int(maxPages) {
|
||||||
|
endValue = int(maxPages)
|
||||||
|
}
|
||||||
log.Println(nav.TotalItem)
|
log.Println(nav.TotalItem)
|
||||||
for i := startValue; i <= endValue; i++ {
|
for i := startValue; i <= endValue; i++ {
|
||||||
pageNum := strconv.Itoa(i)
|
pageNum := strconv.Itoa(i)
|
||||||
url, _ := route.URL("page", pageNum)
|
url, _ := route.URL("page", pageNum)
|
||||||
ret = ret + "<li"
|
ret = ret + "<li"
|
||||||
if (i == nav.CurrentPage) { ret = ret + " class=\"active\"" }
|
if i == nav.CurrentPage {
|
||||||
|
ret = ret + " class=\"active\""
|
||||||
|
}
|
||||||
|
|
||||||
ret = ret + "><a href=\"" + url.String() + "?" + currentUrl.RawQuery + "\">" + strconv.Itoa(i) + "</a></li>"
|
ret = ret + "><a href=\"" + url.String() + "?" + currentUrl.RawQuery + "\">" + strconv.Itoa(i) + "</a></li>"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* Each Page should have an object to pass to their own template
|
/* Each Page should have an object to pass to their own template
|
||||||
|
|
Référencer dans un nouveau ticket