Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/router/uploadHandler.go

47 lignes
1 Kio
Go
Brut Vue normale Historique

2017-05-06 10:36:37 +02:00
package router
import (
"html/template"
"net/http"
2017-05-07 10:25:09 +02:00
"github.com/ewhal/nyaa/service/captcha"
"github.com/gorilla/mux"
2017-05-06 10:36:37 +02:00
)
var uploadTemplate = template.Must(template.New("upload").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/upload.html"))
2017-05-07 01:20:13 +02:00
func init() {
template.Must(uploadTemplate.ParseGlob("templates/_*.html")) // common
}
2017-05-06 10:36:37 +02:00
func UploadHandler(w http.ResponseWriter, r *http.Request) {
var err error
2017-05-07 10:25:09 +02:00
switch r.Method {
case "POST":
var form UploadForm
defer r.Body.Close()
2017-05-07 10:25:09 +02:00
err = form.ExtractInfo(r)
if err == nil {
2017-05-07 10:25:09 +02:00
// validate name + hash
// authenticate captcha
// add to db and redirect depending on result
}
case "GET":
htv := UploadTemplateVariables{
Upload: UploadForm{
CaptchaID: captcha.GetID(r.RemoteAddr),
},
Search: NewSearchForm(),
URL: r.URL,
Route: mux.CurrentRoute(r),
2017-05-06 10:36:37 +02:00
}
err = uploadTemplate.ExecuteTemplate(w, "index.html", htv)
2017-05-07 10:25:09 +02:00
default:
w.WriteHeader(http.StatusMethodNotAllowed)
return
2017-05-06 10:36:37 +02:00
}
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}