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

36 lignes
927 o
Go
Brut Vue normale Historique

2017-05-06 10:36:37 +02:00
package router
import (
"github.com/gorilla/mux"
"html/template"
"net/http"
)
func UploadHandler(w http.ResponseWriter, r *http.Request) {
var templates = template.Must(template.New("upload").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/upload.html"))
templates.ParseGlob("templates/_*.html") // common
var uploadForm UploadForm
if r.Method == "POST" {
err := r.ParseForm()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
uploadForm = UploadForm{
r.Form.Get("name"),
r.Form.Get("magnet"),
r.Form.Get("c"),
r.Form.Get("desc"),
}
//validate name + hash
//add to db and redirect depending on result
}
htv := UploadTemplateVariables{uploadForm, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
err := templates.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}