40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type HintHandler struct {}
|
||
|
|
||
|
func (h HintHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||
|
log.Printf("Handling %s opening hint request from %s: %s [%s]\n", r.Method, r.RemoteAddr, r.URL.Path, r.UserAgent())
|
||
|
|
||
|
w.Header().Set("Content-Type", "application/json")
|
||
|
|
||
|
// Check request type and size
|
||
|
if r.Method != "POST" {
|
||
|
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
||
|
return
|
||
|
} else if r.ContentLength <= 0 || r.ContentLength > 1023 {
|
||
|
http.Error(w, "{\"errmsg\":\"Requête trop longue ou de taille inconnue\"}", http.StatusRequestEntityTooLarge)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// Extract URL arguments
|
||
|
var sURL = strings.Split(r.URL.Path, "/")
|
||
|
|
||
|
if len(sURL) != 1 && len(sURL) != 2 {
|
||
|
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
team := sURL[0]
|
||
|
|
||
|
// Enqueue file for backend treatment
|
||
|
if saveTeamFile(SubmissionDir, team, "hint", w, r) {
|
||
|
http.Error(w, "{\"errmsg\":\"Demande d'astuce acceptée...\"}", http.StatusAccepted)
|
||
|
}
|
||
|
}
|