This commit is contained in:
nemunaire 2016-01-23 13:19:28 +01:00
parent 8788eea4f0
commit 645f40f0c6
8 changed files with 32 additions and 37 deletions

View File

@ -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)

View File

@ -17,14 +17,14 @@ var ApiThemesRouting = map[string]DispatchFunction{
}
type exportedExercice struct {
Title string `json:"title"`
Gain int64 `json:"gain"`
Solved int64 `json:"solved"`
Title string `json:"title"`
Gain int64 `json:"gain"`
Solved int64 `json:"solved"`
}
type exportedTheme struct {
Name string `json:"name"`
Authors string `json:"authors"`
Name string `json:"name"`
Authors string `json:"authors"`
Exercices map[string]exportedExercice `json:"exercices"`
}

View File

@ -5,7 +5,7 @@ import (
"path"
)
type staticRouting struct{
type staticRouting struct {
StaticDir string
}

View File

@ -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")
}

View File

@ -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()

View File

@ -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)

View File

@ -7,15 +7,15 @@ import (
"time"
)
type TimeHandler struct{
type TimeHandler struct {
StartTime time.Time
Duration time.Duration
}
type timeObject struct {
Started int64 `json:"st"`
Time int64 `json:"cu"`
Duration int `json:"du"`
Started int64 `json:"st"`
Time int64 `json:"cu"`
Duration int `json:"du"`
}
func (t TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

View File

@ -23,8 +23,8 @@ CREATE TABLE IF NOT EXISTS themes(
authors VARCHAR(255) NOT NULL
);
`); err != nil {
return err
}
return err
}
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS teams(
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
@ -32,8 +32,8 @@ CREATE TABLE IF NOT EXISTS teams(
color INTEGER NOT NULL
);
`); err != nil {
return err
}
return err
}
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS team_members(
id_member INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
@ -45,8 +45,8 @@ CREATE TABLE IF NOT EXISTS team_members(
FOREIGN KEY(id_team) REFERENCES teams(id_team)
);
`); err != nil {
return err
}
return err
}
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS exercices(
id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
@ -61,8 +61,8 @@ CREATE TABLE IF NOT EXISTS exercices(
FOREIGN KEY(depend) REFERENCES exercices(id_exercice)
);
`); err != nil {
return err
}
return err
}
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS exercice_files(
id_file INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
@ -75,8 +75,8 @@ CREATE TABLE IF NOT EXISTS exercice_files(
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
);
`); err != nil {
return err
}
return err
}
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS exercice_keys(
id_key INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
@ -86,8 +86,8 @@ CREATE TABLE IF NOT EXISTS exercice_keys(
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
);
`); err != nil {
return err
}
return err
}
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS exercice_solved(
id_exercice INTEGER NOT NULL,
@ -97,8 +97,8 @@ CREATE TABLE IF NOT EXISTS exercice_solved(
FOREIGN KEY(id_team) REFERENCES teams(id_team)
);
`); err != nil {
return err
}
return err
}
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS exercice_tries(
id_exercice INTEGER NOT NULL,
@ -108,8 +108,8 @@ CREATE TABLE IF NOT EXISTS exercice_tries(
FOREIGN KEY(id_team) REFERENCES teams(id_team)
);
`); err != nil {
return err
}
return err
}
return nil
}