server/frontend/submit.go

35 lines
1007 B
Go

package main
import (
"fmt"
"net/http"
"path"
"strconv"
"time"
fronttime "srs.epita.fr/fic-server/frontend/time"
)
func SubmissionHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) {
if time.Now().Sub(fronttime.ChallengeEnd) > 0 {
http.Error(w, "{\"errmsg\":\"Vous ne pouvez plus soumettre, le challenge est terminé.\"}", http.StatusForbidden)
return
}
if len(sURL) != 1 {
http.Error(w, "{\"errmsg\":\"Arguments manquants.\"}", http.StatusBadRequest)
return
}
// Check exercice validity then save the submission
if pex, err := strconv.Atoi(sURL[0]); err != nil {
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
return
} else if exercice := fmt.Sprintf("%d", pex); len(exercice) < 1 {
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
return
} else if saveTeamFile(path.Join(team, exercice), w, r) {
http.Error(w, "{\"errmsg\":\"Son traitement est en cours...\"}", http.StatusAccepted)
}
}