Example #1
0
func JudgeSubmission(w http.ResponseWriter, r *http.Request) {
	me, _ := context.Get(r, "me").(*data.Account)
	if me == nil || (me.Level != data.Judge && me.Level != data.Administrator) {
		http.Error(w, "", http.StatusForbidden)
		return
	}

	vars := mux.Vars(r)

	id, err := strconv.ParseInt(vars["id"], 10, 64)
	catch(err)
	subm, err := data.GetSubmission(id)
	catch(err)

	subm.Reset()
	err = subm.Put()
	catch(err)
	hub.Send([]interface{}{"SYNC", "submissions", subm.Id})

	exec := &data.Execution{
		SubmissionId: subm.Id,
		Apply:        true,
	}
	err = exec.Put()
	catch(err)

	belt.Push(exec)

	err = data.NewActivity(me, fmt.Sprintf("judged submission %d", subm.Id)).Put()
	catch(err)
	hub.Send([]interface{}{"SYNC", "activities"})
}
Example #2
0
func UpdateSubmission(w http.ResponseWriter, r *http.Request) {
	me, _ := context.Get(r, "me").(*data.Account)
	if me == nil || (me.Level != data.Judge && me.Level != data.Administrator) {
		http.Error(w, "", http.StatusForbidden)
		return
	}

	vars := mux.Vars(r)

	id, err := strconv.ParseInt(vars["id"], 10, 64)
	catch(err)
	subm, err := data.GetSubmission(id)
	catch(err)

	body := struct {
		Verdict data.Verdict `json:"verdict"`
	}{}
	err = json.NewDecoder(r.Body).Decode(&body)
	catch(err)

	subm.Tamper(body.Verdict)
	err = subm.Put()
	catch(err)

	err = json.NewEncoder(w).Encode(subm)
	catch(err)
	hub.Send([]interface{}{"SYNC", "submissions", subm.Id})

	err = data.NewActivity(me, fmt.Sprintf("updated submission %d", subm.Id)).Put()
	catch(err)
	hub.Send([]interface{}{"SYNC", "activities"})
}
Example #3
0
func ServeSubmissionTestOutput(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	id, err := strconv.ParseInt(vars["id"], 10, 64)
	catch(err)
	subm, err := data.GetSubmission(id)
	catch(err)

	no, err := strconv.ParseInt(vars["no"], 10, 64)
	catch(err)
	test := subm.Tests[no-1]

	w.Header().Add("Content-Type", "text/plain")

	if r.FormValue("download") == "yes" {
		acc, err := data.GetAccount(subm.AuthorId)
		catch(err)

		prob, err := data.GetProblem(subm.ProblemId)
		catch(err)

		w.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%d-%s-%s-%d.out"`, subm.Id, acc.Handle, strings.ToLower(prob.Char), no))
	}

	blob, err := data.Blobs.Get(test.OutputKey)
	catch(err)
	_, err = io.Copy(w, blob)
	catch(err)
	err = blob.Close()
	catch(err)
}
Example #4
0
func CreateExecution(w http.ResponseWriter, r *http.Request) {
	me, _ := context.Get(r, "me").(*data.Account)
	if me == nil || (me.Level != data.Judge && me.Level != data.Administrator) {
		http.Error(w, "", http.StatusForbidden)
		return
	}

	body := struct {
		SubmissionId int64 `json:"submissionId"`
	}{}
	err := json.NewDecoder(r.Body).Decode(&body)
	catch(err)

	subm, err := data.GetSubmission(body.SubmissionId)
	catch(err)

	exec := &data.Execution{
		SubmissionId: subm.Id,
	}
	err = exec.Put()
	catch(err)

	belt.Push(exec)

	err = json.NewEncoder(w).Encode(exec)
	catch(err)

	err = data.NewActivity(me, fmt.Sprintf("created execution %d for submission %d", exec.Id, subm.Id)).Put()
	catch(err)
	hub.Send([]interface{}{"SYNC", "activities"})
}
Example #5
0
func ServeSubmission(w http.ResponseWriter, r *http.Request) {
	me, _ := context.Get(r, "me").(*data.Account)
	if me == nil {
		http.Error(w, "", http.StatusForbidden)
		return
	}

	vars := mux.Vars(r)

	id, err := strconv.ParseInt(vars["id"], 10, 64)
	catch(err)
	subm, err := data.GetSubmission(id)
	catch(err)

	if me.Level != data.Judge && me.Level != data.Administrator && me.Id != subm.AuthorId {
		http.Error(w, "", http.StatusForbidden)
		return
	}

	err = json.NewEncoder(w).Encode(subm)
	catch(err)
}