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)
|
return exercice.ImportFile(pathname, uf.URI)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCloudFile(pathname string, dest string) (error) {
|
func getCloudFile(pathname string, dest string) error {
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
if req, err := http.NewRequest("GET", CloudDAVBase+pathname, nil); err != nil {
|
if req, err := http.NewRequest("GET", CloudDAVBase+pathname, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -58,7 +58,7 @@ func getCloudFile(pathname string, dest string) (error) {
|
|||||||
if fd, err := os.Create(dest); err != nil {
|
if fd, err := os.Create(dest); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
defer fd.Close();
|
defer fd.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return errors.New(resp.Status)
|
return errors.New(resp.Status)
|
||||||
|
@ -17,14 +17,14 @@ var ApiThemesRouting = map[string]DispatchFunction{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type exportedExercice struct {
|
type exportedExercice struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Gain int64 `json:"gain"`
|
Gain int64 `json:"gain"`
|
||||||
Solved int64 `json:"solved"`
|
Solved int64 `json:"solved"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type exportedTheme struct {
|
type exportedTheme struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Authors string `json:"authors"`
|
Authors string `json:"authors"`
|
||||||
Exercices map[string]exportedExercice `json:"exercices"`
|
Exercices map[string]exportedExercice `json:"exercices"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
type staticRouting struct{
|
type staticRouting struct {
|
||||||
StaticDir string
|
StaticDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func genTeamMyFile(team fic.Team) error {
|
|||||||
|
|
||||||
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||||
os.MkdirAll(dirPath, 0777)
|
os.MkdirAll(dirPath, 0777)
|
||||||
} else if ! s.IsDir() {
|
} else if !s.IsDir() {
|
||||||
return errors.New("dirPath is not a directory")
|
return errors.New("dirPath is not a directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ func touchStartedFile(startSub time.Duration) {
|
|||||||
func main() {
|
func main() {
|
||||||
var bind = flag.String("bind", "0.0.0.0:8080", "Bind port/socket")
|
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 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 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 duration = flag.Duration("duration", 180*time.Minute, "Challenge duration")
|
||||||
flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files")
|
flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files")
|
||||||
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
|
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SubmissionHandler struct{
|
type SubmissionHandler struct {
|
||||||
ChallengeEnd time.Time
|
ChallengeEnd time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,7 +20,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
|
||||||
// Check request type and size
|
// Check request type and size
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
||||||
@ -30,7 +29,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Extract URL arguments
|
// Extract URL arguments
|
||||||
var sURL = strings.Split(r.URL.Path, "/")
|
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
|
// Previous submission not treated
|
||||||
if _, err := os.Stat(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); !os.IsNotExist(err) {
|
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)
|
http.Error(w, "{\"errmsg\":\"Du calme ! une tentative est déjà en cours de traitement.\"}", http.StatusPaymentRequired)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Read request body
|
// Read request body
|
||||||
var body []byte
|
var body []byte
|
||||||
if r.ContentLength > 0 {
|
if r.ContentLength > 0 {
|
||||||
@ -84,7 +80,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Store content in file
|
// Store content in file
|
||||||
if file, err := os.Create(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); err != nil {
|
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)
|
log.Println("Unable to open exercice file:", err)
|
||||||
|
@ -7,15 +7,15 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TimeHandler struct{
|
type TimeHandler struct {
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type timeObject struct {
|
type timeObject struct {
|
||||||
Started int64 `json:"st"`
|
Started int64 `json:"st"`
|
||||||
Time int64 `json:"cu"`
|
Time int64 `json:"cu"`
|
||||||
Duration int `json:"du"`
|
Duration int `json:"du"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (t TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
32
libfic/db.go
32
libfic/db.go
@ -23,8 +23,8 @@ CREATE TABLE IF NOT EXISTS themes(
|
|||||||
authors VARCHAR(255) NOT NULL
|
authors VARCHAR(255) NOT NULL
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS teams(
|
CREATE TABLE IF NOT EXISTS teams(
|
||||||
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
@ -32,8 +32,8 @@ CREATE TABLE IF NOT EXISTS teams(
|
|||||||
color INTEGER NOT NULL
|
color INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS team_members(
|
CREATE TABLE IF NOT EXISTS team_members(
|
||||||
id_member INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
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)
|
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercices(
|
CREATE TABLE IF NOT EXISTS exercices(
|
||||||
id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
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)
|
FOREIGN KEY(depend) REFERENCES exercices(id_exercice)
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercice_files(
|
CREATE TABLE IF NOT EXISTS exercice_files(
|
||||||
id_file INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
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)
|
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercice_keys(
|
CREATE TABLE IF NOT EXISTS exercice_keys(
|
||||||
id_key INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
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)
|
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercice_solved(
|
CREATE TABLE IF NOT EXISTS exercice_solved(
|
||||||
id_exercice INTEGER NOT NULL,
|
id_exercice INTEGER NOT NULL,
|
||||||
@ -97,8 +97,8 @@ CREATE TABLE IF NOT EXISTS exercice_solved(
|
|||||||
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS exercice_tries(
|
CREATE TABLE IF NOT EXISTS exercice_tries(
|
||||||
id_exercice INTEGER NOT NULL,
|
id_exercice INTEGER NOT NULL,
|
||||||
@ -108,8 +108,8 @@ CREATE TABLE IF NOT EXISTS exercice_tries(
|
|||||||
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user