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-01-19 12:08:38 +00:00
|
|
|
)
|
2016-12-30 11:45:14 +00:00
|
|
|
|
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) {
|
2018-12-01 17:26:11 +00:00
|
|
|
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 {
|
2016-12-09 08:36:18 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|