Implement HEAD for views (#695)
* Implement HEAD for /view/{id} Implement HEAD for the torrent view route by calling GetRawTorrentById. Run gofmt on the file while we are here. * Implement HEAD for /api/view/{id} Implement HEAD in the same way as /view/{id} Also run gofmt on the api_handler.go
Cette révision appartient à :
Parent
38f331a32e
révision
af2850518c
3 fichiers modifiés avec 43 ajouts et 7 suppressions
|
@ -14,8 +14,8 @@ import (
|
|||
"github.com/NyaaPantsu/nyaa/model"
|
||||
"github.com/NyaaPantsu/nyaa/service"
|
||||
"github.com/NyaaPantsu/nyaa/service/api"
|
||||
"github.com/NyaaPantsu/nyaa/service/upload"
|
||||
"github.com/NyaaPantsu/nyaa/service/torrent"
|
||||
"github.com/NyaaPantsu/nyaa/service/upload"
|
||||
"github.com/NyaaPantsu/nyaa/util"
|
||||
"github.com/NyaaPantsu/nyaa/util/log"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -102,6 +102,23 @@ func ApiViewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func ApiViewHeadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
id, err := strconv.ParseInt(vars["id"], 10, 32)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = torrentService.GetRawTorrentById(uint(id))
|
||||
|
||||
if err != nil {
|
||||
NotFoundHandler(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(nil)
|
||||
}
|
||||
|
||||
func ApiUploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
token := r.Header.Get("Authorization")
|
||||
user := model.User{}
|
||||
|
|
|
@ -46,12 +46,14 @@ func init() {
|
|||
Router.Handle("/api", wrapHandler(gzipAPIHandler)).Methods("GET")
|
||||
Router.Handle("/api/{page:[0-9]*}", wrapHandler(gzipAPIHandler)).Methods("GET")
|
||||
Router.Handle("/api/view/{id}", wrapHandler(gzipAPIViewHandler)).Methods("GET")
|
||||
Router.HandleFunc("/api/view/{id}", ApiViewHeadHandler).Methods("HEAD")
|
||||
Router.HandleFunc("/api/upload", ApiUploadHandler).Methods("POST")
|
||||
Router.HandleFunc("/api/update", ApiUpdateHandler).Methods("PUT")
|
||||
Router.HandleFunc("/faq", FaqHandler).Name("faq")
|
||||
Router.HandleFunc("/feed", RSSHandler).Name("feed")
|
||||
Router.HandleFunc("/feed/{page}", RSSHandler).Name("feed_page")
|
||||
Router.Handle("/view/{id}", wrapHandler(gzipViewHandler)).Methods("GET").Name("view_torrent")
|
||||
Router.HandleFunc("/view/{id}", ViewHeadHandler).Methods("HEAD")
|
||||
Router.HandleFunc("/view/{id}", PostCommentHandler).Methods("POST").Name("post_comment")
|
||||
Router.HandleFunc("/upload", UploadHandler).Name("upload")
|
||||
Router.HandleFunc("/user/register", UserRegisterFormHandler).Name("user_register").Methods("GET")
|
||||
|
|
|
@ -25,13 +25,13 @@ func ViewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
messages := msg.GetMessages(r)
|
||||
user := GetUser(r)
|
||||
|
||||
if (r.URL.Query()["success"] != nil) {
|
||||
if r.URL.Query()["success"] != nil {
|
||||
messages.AddInfo("infos", "Torrent uploaded successfully!")
|
||||
}
|
||||
|
||||
torrent, err := torrentService.GetTorrentById(id)
|
||||
|
||||
if (r.URL.Query()["notif"] != nil) {
|
||||
|
||||
if r.URL.Query()["notif"] != nil {
|
||||
notifierService.ToggleReadNotification(torrent.Identifier(), user.ID)
|
||||
}
|
||||
|
||||
|
@ -52,12 +52,29 @@ func ViewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func ViewHeadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
id, err := strconv.ParseInt(vars["id"], 10, 32)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = torrentService.GetRawTorrentById(uint(id))
|
||||
|
||||
if err != nil {
|
||||
NotFoundHandler(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(nil)
|
||||
}
|
||||
|
||||
func PostCommentHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
id := vars["id"]
|
||||
|
||||
torrent, err := torrentService.GetTorrentById(id)
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
NotFoundHandler(w, r)
|
||||
return
|
||||
}
|
||||
|
@ -93,7 +110,7 @@ func PostCommentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
messages.ImportFromError("errors", err)
|
||||
}
|
||||
}
|
||||
ViewHandler(w,r)
|
||||
ViewHandler(w, r)
|
||||
}
|
||||
|
||||
func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -123,5 +140,5 @@ func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
messages.ImportFromError("errors", err)
|
||||
}
|
||||
}
|
||||
ViewHandler(w,r)
|
||||
ViewHandler(w, r)
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket