format
This commit is contained in:
parent
8788eea4f0
commit
645f40f0c6
|
@ -44,7 +44,7 @@ func createExerciceFile(theme fic.Theme, exercice fic.Exercice, args []string, b
|
|||
return exercice.ImportFile(pathname, uf.URI)
|
||||
}
|
||||
|
||||
func getCloudFile(pathname string, dest string) (error) {
|
||||
func getCloudFile(pathname string, dest string) error {
|
||||
client := http.Client{}
|
||||
if req, err := http.NewRequest("GET", CloudDAVBase+pathname, nil); err != nil {
|
||||
return err
|
||||
|
@ -58,7 +58,7 @@ func getCloudFile(pathname string, dest string) (error) {
|
|||
if fd, err := os.Create(dest); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer fd.Close();
|
||||
defer fd.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return errors.New(resp.Status)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"path"
|
||||
)
|
||||
|
||||
type staticRouting struct{
|
||||
type staticRouting struct {
|
||||
StaticDir string
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ func genTeamMyFile(team fic.Team) error {
|
|||
|
||||
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||
os.MkdirAll(dirPath, 0777)
|
||||
} else if ! s.IsDir() {
|
||||
} else if !s.IsDir() {
|
||||
return errors.New("dirPath is not a directory")
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ func touchStartedFile(startSub time.Duration) {
|
|||
func main() {
|
||||
var bind = flag.String("bind", "0.0.0.0:8080", "Bind port/socket")
|
||||
var prefix = flag.String("prefix", "", "Request path prefix to strip (from proxy)")
|
||||
var start = flag.Int64("start", 0, fmt.Sprintf("Challenge start timestamp (in 2 minutes: %d)", time.Now().Unix() / 60 * 60 + 120))
|
||||
var duration = flag.Duration("duration", 180 * time.Minute, "Challenge duration")
|
||||
var start = flag.Int64("start", 0, fmt.Sprintf("Challenge start timestamp (in 2 minutes: %d)", time.Now().Unix()/60*60+120))
|
||||
var duration = flag.Duration("duration", 180*time.Minute, "Challenge duration")
|
||||
flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files")
|
||||
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
|
||||
flag.Parse()
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type SubmissionHandler struct{
|
||||
type SubmissionHandler struct {
|
||||
ChallengeEnd time.Time
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
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)
|
||||
|
@ -30,7 +29,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
// Extract URL arguments
|
||||
var sURL = strings.Split(r.URL.Path, "/")
|
||||
|
||||
|
@ -61,14 +59,12 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Previous submission not treated
|
||||
if _, err := os.Stat(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); !os.IsNotExist(err) {
|
||||
http.Error(w, "{\"errmsg\":\"Du calme ! une tentative est déjà en cours de traitement.\"}", http.StatusPaymentRequired)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Read request body
|
||||
var body []byte
|
||||
if r.ContentLength > 0 {
|
||||
|
@ -84,7 +80,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Store content in file
|
||||
if file, err := os.Create(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); err != nil {
|
||||
log.Println("Unable to open exercice file:", err)
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type TimeHandler struct{
|
||||
type TimeHandler struct {
|
||||
StartTime time.Time
|
||||
Duration time.Duration
|
||||
}
|
||||
|
|
16
libfic/db.go
16
libfic/db.go
|
@ -24,7 +24,7 @@ CREATE TABLE IF NOT EXISTS themes(
|
|||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS teams(
|
||||
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
|
@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS teams(
|
|||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS team_members(
|
||||
id_member INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
|
@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS team_members(
|
|||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS exercices(
|
||||
id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
|
@ -62,7 +62,7 @@ CREATE TABLE IF NOT EXISTS exercices(
|
|||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS exercice_files(
|
||||
id_file INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
|
@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS exercice_files(
|
|||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS exercice_keys(
|
||||
id_key INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
|
@ -87,7 +87,7 @@ CREATE TABLE IF NOT EXISTS exercice_keys(
|
|||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS exercice_solved(
|
||||
id_exercice INTEGER NOT NULL,
|
||||
|
@ -98,7 +98,7 @@ CREATE TABLE IF NOT EXISTS exercice_solved(
|
|||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS exercice_tries(
|
||||
id_exercice INTEGER NOT NULL,
|
||||
|
@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS exercice_tries(
|
|||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user