Merge branch 'master' of https://github.com/ewhal/nyaa
Conflicts: router/userHandler.go
Cette révision appartient à :
révision
e0743e4688
12 fichiers modifiés avec 75 ajouts et 28 suppressions
18
.travis.yml
18
.travis.yml
|
@ -3,12 +3,24 @@ go:
|
|||
- 1.x
|
||||
before_install:
|
||||
- sudo apt-get install gcc-mingw-w64 gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 binutils-mingw-w64-i686 binutils-mingw-w64-x86-64
|
||||
install:
|
||||
- go get github.com/tcnksm/ghr
|
||||
|
||||
script:
|
||||
# Downloads deps automatically. No need to add manually.
|
||||
- go list -f '{{.Deps}}' | tr "[" " " | tr "]" " " | xargs go list -e -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | grep -v 'github.com/ewhal/nyaa' | xargs go get -v
|
||||
- go get
|
||||
- go build
|
||||
- go vet
|
||||
- go test -v ./...
|
||||
before_deploy:
|
||||
- ./package.sh
|
||||
- ghr --username ewhal --token $GITHUB_TOKEN --replace --prerelease --debug pre-release dist/
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: Nz2M3ZbQumKGVga/nnZnz1VXikRkGoLXk5FoH4uOl6GF6rlUNmtvJYs34LWF0/CMswBXNhjCggEaMMtZC+j66ZjoAdHBXRfrOb6jisNJRF6FNk7Kob6W3itCEOTvEL/8a+k2fI95cLqOXDLR2tIX03nchb8rDmVALs7P4gQgy2Y7UAo/aa/0G+OhsSJrlQWt0MT9OKGoIXpeKZjOG3wO/YwqfDwRTItuA9DLFoMQ0gwQfgT58t1ullbpM+jISni7rwfK+jUnZHjUH/VHLguVFmL4A1DxWriJXNOrZR+i/eUJ94mWvfI08WR8Qh3UCr58FrKoWvPsu7HnCq0bn6RvQtCKqx5zgv+R+kxKIP+79SVjKZUi1ghswAuwx9+AT6vHgPLXjJLpZj9Ap/KhfnQR6VT3jBT+kEpmv3J+57JcJCyD4ZslT+LGW2ul0uWoGCVVMBdHqMzuC8OSxpKCw6bFNWnLq+JAU08zlJkAAllBKev+LZWiF8GBICKfynRgViy+MKNaMfzIUNlL9UDskaiWP+BL9RXGLJ2FVdeKkzqdAYdYlgdJChQ56KTtRukR7FlOqDXhszIPxJhU9wn9lNXmGvq1FJyo1LRY3HX+5o9lWw+enaswNxFxdLBMXPhF5jehMkImiR4/YS4WdlmHcEfsli9sBOjBQh1iIpCfme77PPU=
|
||||
script:
|
||||
- ./package.sh
|
||||
file: dist/*.zip
|
||||
skip_cleanup: true
|
||||
overwrite: true
|
||||
on:
|
||||
tags: true
|
||||
|
|
|
@ -102,4 +102,4 @@ func (config *Config) Pretty(output io.Writer) error {
|
|||
data = append(data, []byte("\n")...)
|
||||
_, err = output.Write(data)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,6 @@ package config
|
|||
const (
|
||||
// TorrentFileStorage = "/var/tmp/torrent_outgoing"
|
||||
TorrentFileStorage = ""
|
||||
//disable uploads by default
|
||||
UploadsDisabled = 1
|
||||
)
|
||||
|
|
2
main.go
2
main.go
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/router"
|
||||
"github.com/ewhal/nyaa/util/log"
|
||||
"github.com/ewhal/nyaa/util/search" // super hacky fix
|
||||
"github.com/ewhal/nyaa/util/signals"
|
||||
|
||||
"net/http"
|
||||
|
@ -59,6 +60,7 @@ func main() {
|
|||
if len(config.TorrentFileStorage) > 0 {
|
||||
os.MkdirAll(config.TorrentFileStorage, 0755)
|
||||
}
|
||||
search.Init(conf.DBType) // super hacky fix
|
||||
RunServer(conf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
.nightswitch {
|
||||
position: fixed;
|
||||
top: 12px;
|
||||
right: 48px;
|
||||
right: 12px;
|
||||
}
|
||||
.nightswitch > a > img {
|
||||
width: 24px;
|
||||
|
@ -43,7 +43,7 @@
|
|||
}
|
||||
#container.cont-view {
|
||||
background: #29363d url(/img/megumin.png) no-repeat;
|
||||
background-size: 75px, 100px;
|
||||
background-size: 75px;
|
||||
}
|
||||
|
||||
body {
|
||||
|
@ -178,6 +178,7 @@ div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-typ
|
|||
max-height: 80vh;
|
||||
}
|
||||
|
||||
/* the curved edges triggered my autism */
|
||||
.navbar {
|
||||
border-radius: 0px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
.nightswitch {
|
||||
position: fixed;
|
||||
top: 12px;
|
||||
right: 48px;
|
||||
right: 12px;
|
||||
}
|
||||
.nightswitch > a > img {
|
||||
width: 24px;
|
||||
|
@ -43,7 +43,7 @@
|
|||
}
|
||||
#container.cont-view {
|
||||
background: white url(/img/renchon.png) no-repeat;
|
||||
background-size: 75px, 100px;
|
||||
background-size: 61px;
|
||||
}
|
||||
|
||||
body {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/service/captcha"
|
||||
|
@ -14,6 +15,10 @@ import (
|
|||
)
|
||||
|
||||
func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if config.UploadsDisabled == 1 {
|
||||
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
var err error
|
||||
var uploadForm UploadForm
|
||||
if r.Method == "POST" {
|
||||
|
|
|
@ -21,7 +21,7 @@ func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
|||
b := form.RegistrationForm{}
|
||||
modelHelper.BindValueForm(&b, r)
|
||||
b.CaptchaID = captcha.GetID()
|
||||
languages.SetTranslation("en-us", viewRegisterTemplate)
|
||||
languages.SetTranslationFromRequest(viewRegisterTemplate, r, "en-us")
|
||||
htv := UserRegisterTemplateVariables{b, form.NewErrors(), NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
err := viewRegisterTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
|
@ -36,8 +36,10 @@ func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
|||
func UserLoginFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||
b := form.LoginForm{}
|
||||
modelHelper.BindValueForm(&b, r)
|
||||
languages.SetTranslation("en-us", viewLoginTemplate)
|
||||
|
||||
languages.SetTranslationFromRequest(viewLoginTemplate, r, "en-us")
|
||||
htv := UserLoginFormVariables{b, form.NewErrors(), NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
|
||||
err := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -75,7 +77,7 @@ func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if (len(err) == 0) {
|
||||
b := form.RegistrationForm{}
|
||||
languages.SetTranslation("en-us", viewRegisterSuccessTemplate)
|
||||
languages.SetTranslationFromRequest(viewRegisterSuccessTemplate, r, "en-us")
|
||||
htv := UserRegisterTemplateVariables{b, err, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
errorTmpl := viewRegisterSuccessTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if errorTmpl != nil {
|
||||
|
@ -87,7 +89,7 @@ func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if (len(err) > 0) {
|
||||
b.CaptchaID = captcha.GetID()
|
||||
languages.SetTranslation("en-us", viewRegisterTemplate)
|
||||
languages.SetTranslationFromRequest(viewRegisterTemplate, r, "en-us")
|
||||
htv := UserRegisterTemplateVariables{b, err, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
errorTmpl := viewRegisterTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if errorTmpl != nil {
|
||||
|
@ -104,7 +106,7 @@ func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if (errEmail != nil) {
|
||||
err["errors"] = append(err["errors"], errEmail.Error())
|
||||
}
|
||||
languages.SetTranslation("en-us", viewVerifySuccessTemplate)
|
||||
languages.SetTranslationFromRequest(viewVerifySuccessTemplate, r, "en-us")
|
||||
htv := UserVerifyTemplateVariables{err, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
errorTmpl := viewVerifySuccessTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if errorTmpl != nil {
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
<label for="solution">Captcha</label>
|
||||
<input type="text" name="captchaID" value="{{.CaptchaID}}" hidden>
|
||||
<img src="/captcha/{{.CaptchaID}}.png">
|
||||
<input type="number" name="solution" class="form-control" placeholder="Captcha" required>
|
||||
<input type="text" name="solution" class="form-control" placeholder="Captcha" required>
|
||||
</div>
|
||||
{{end}}
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
{{block "search_button" .}}{{end}}
|
||||
</div>
|
||||
</form>
|
||||
<div class="nightswitch" style="position:absolute;right:1em">
|
||||
<div class="nightswitch">
|
||||
<a href="javascript:toggleNightMode();" ><img id="nighticon" src="/img/moon.png"></a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,15 +1,27 @@
|
|||
package languages
|
||||
|
||||
import (
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
"html/template"
|
||||
)
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetTranslation(language string, tmpl *template.Template) {
|
||||
T, _ := i18n.Tfunc(language)
|
||||
tmpl.Funcs(map[string]interface{}{
|
||||
"T": func (str string) template.HTML {
|
||||
return template.HTML(T(str))
|
||||
},
|
||||
})
|
||||
}
|
||||
func SetTranslation(tmpl *template.Template, language string, languages ...string) {
|
||||
T, _ := i18n.Tfunc(language, languages...)
|
||||
tmpl.Funcs(map[string]interface{}{
|
||||
"T": func(str string) template.HTML {
|
||||
return template.HTML(T(str))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func SetTranslationFromRequest(tmpl *template.Template, r *http.Request, defaultLanguage string) {
|
||||
cookie, err := r.Cookie("lang")
|
||||
cookieLanguage := ""
|
||||
if err == nil {
|
||||
cookieLanguage = cookie.Value
|
||||
}
|
||||
// go-i18n supports the format of the Accept-Language header, thankfully.
|
||||
headerLanguage := r.Header.Get("Accept-Language")
|
||||
SetTranslation(tmpl, cookieLanguage, headerLanguage, defaultLanguage)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,17 @@ type SearchParam struct {
|
|||
Sort string
|
||||
}
|
||||
|
||||
|
||||
// super hacky fix:
|
||||
var search_op string
|
||||
func Init(backend string) {
|
||||
if backend == "postgres" {
|
||||
search_op = "ILIKE"
|
||||
} else {
|
||||
search_op = "LIKE"
|
||||
}
|
||||
}
|
||||
|
||||
func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents, int) {
|
||||
maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max"))
|
||||
if errConv != nil {
|
||||
|
@ -72,7 +83,7 @@ func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents,
|
|||
}
|
||||
searchQuerySplit := strings.Split(search_param.Query, " ")
|
||||
for i, _ := range searchQuerySplit {
|
||||
conditions = append(conditions, "torrent_name LIKE ?")
|
||||
conditions = append(conditions, "torrent_name " + search_op + " ?")
|
||||
parameters.Params = append(parameters.Params, "%"+searchQuerySplit[i]+"%")
|
||||
}
|
||||
|
||||
|
|
Référencer dans un nouveau ticket