Split post and get handlers for upload
This commit is contained in:
parent
fc50ba5fd6
commit
d8bfcb2ef2
2 changed files with 39 additions and 36 deletions
|
@ -126,7 +126,8 @@ func main() {
|
|||
r.HandleFunc("/", indexHandler)
|
||||
r.HandleFunc("/book/{id:[0-9a-fA-F]+}", bookHandler)
|
||||
r.HandleFunc("/search/", searchHandler)
|
||||
r.HandleFunc("/upload/", uploadHandler)
|
||||
r.HandleFunc("/upload/", uploadHandler).Methods("GET")
|
||||
r.HandleFunc("/upload/", uploadPostHandler).Methods("POST")
|
||||
r.HandleFunc("/login/", loginHandler).Methods("POST")
|
||||
r.HandleFunc("/logout/", logoutHandler)
|
||||
r.HandleFunc("/new/", newHandler)
|
||||
|
|
12
upload.go
12
upload.go
|
@ -10,8 +10,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
func uploadPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
sess := GetSession(r)
|
||||
|
||||
uploaded := ""
|
||||
|
@ -21,14 +20,14 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
log.Println("File uploaded:", f.Filename)
|
||||
file, err := f.Open()
|
||||
if err != nil {
|
||||
sess.Notify("Problem uploading!", "The file '" + f.Filename + "' is not a well formed epub: "+err.Error(), "error")
|
||||
sess.Notify("Problem uploading!", "The file '"+f.Filename+"' is not a well formed epub: "+err.Error(), "error")
|
||||
continue
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
epub, err := openMultipartEpub(file)
|
||||
if err != nil {
|
||||
sess.Notify("Problem uploading!", "The file '" + f.Filename + "' is not a well formed epub: "+err.Error(), "error")
|
||||
sess.Notify("Problem uploading!", "The file '"+f.Filename+"' is not a well formed epub: "+err.Error(), "error")
|
||||
continue
|
||||
}
|
||||
defer epub.Close()
|
||||
|
@ -48,8 +47,11 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if uploaded != "" {
|
||||
sess.Notify("Upload successful!", "Added the books:"+uploaded+". Thank you for your contribution", "success")
|
||||
}
|
||||
}
|
||||
|
||||
uploadHandler(w, r)
|
||||
}
|
||||
|
||||
func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var data uploadData
|
||||
data.S = GetStatus(w, r)
|
||||
data.S.Upload = true
|
||||
|
|
Reference in a new issue