This repository has been archived on 2025-06-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
server/frontend/submit.go

34 lines
1,007 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)
}
}