server/receiver/submit.go

33 lines
974 B
Go
Raw Normal View History

2016-01-06 18:30:57 +00:00
package main
import (
"fmt"
"net/http"
2017-11-22 00:52:08 +00:00
"path"
2016-01-06 18:30:57 +00:00
"strconv"
2016-01-23 11:26:20 +00:00
"time"
)
2017-11-22 00:52:08 +00:00
func SubmissionHandler(w http.ResponseWriter, r *http.Request, team string, sURL []string) {
2023-05-12 12:53:15 +00:00
if challengeEnd != nil && time.Now().After(*challengeEnd) {
http.Error(w, "{\"errmsg\":\"Vous ne pouvez plus soumettre, le challenge est terminé.\"}", http.StatusGone)
2016-01-06 18:30:57 +00:00
return
}
2017-11-22 00:52:08 +00:00
if len(sURL) != 1 {
http.Error(w, "{\"errmsg\":\"Arguments manquants.\"}", http.StatusBadRequest)
2016-01-23 11:26:20 +00:00
return
}
2017-11-22 00:52:08 +00:00
// Check exercice validity then save the submission
2018-12-01 15:15:28 +00:00
if pex, err := strconv.ParseInt(sURL[0], 10, 64); err != nil {
2017-11-22 00:52:08 +00:00
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
2016-01-06 18:30:57 +00:00
return
2017-11-22 00:52:08 +00:00
} else if exercice := fmt.Sprintf("%d", pex); len(exercice) < 1 {
2016-01-23 11:26:20 +00:00
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
2016-01-06 18:30:57 +00:00
return
2017-11-22 00:52:08 +00:00
} else if saveTeamFile(path.Join(team, exercice), w, r) {
http.Error(w, "{\"errmsg\":\"Son traitement est en cours...\"}", http.StatusAccepted)
2016-01-06 18:30:57 +00:00
}
}