Compare commits

...

6 Commits

6 changed files with 64 additions and 17 deletions

View File

@ -37,6 +37,7 @@ func (h *handler) Search(c *gin.Context) {
param := problem.QueryData{ param := problem.QueryData{
Keyword: req.Keyword, Keyword: req.Keyword,
Tag: req.Tag, Tag: req.Tag,
ShouldEnable: true,
Offset: req.Offset, Offset: req.Offset,
Limit: req.Limit, Limit: req.Limit,
Count: &count, Count: &count,

View File

@ -3,7 +3,6 @@ package status
import ( import (
"git.0x7f.app/WOJ/woj-server/internal/e" "git.0x7f.app/WOJ/woj-server/internal/e"
"git.0x7f.app/WOJ/woj-server/internal/model" "git.0x7f.app/WOJ/woj-server/internal/model"
"git.0x7f.app/WOJ/woj-server/pkg/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -58,7 +57,12 @@ func (h *handler) Query(c *gin.Context) {
var response []*submissionWithScore var response []*submissionWithScore
for _, submission := range submissions { for _, submission := range submissions {
cur, _ := h.statusService.Query(submission.ID, false) cur, _ := h.statusService.Query(submission.ID, false)
point := utils.If(cur == nil, -1, cur.Point)
point := int32(-1)
if cur != nil {
point = cur.Point
}
resp := &submissionWithScore{ resp := &submissionWithScore{
Submission: *submission, Submission: *submission,
Point: point, Point: point,

View File

@ -1,5 +1,9 @@
# A+B Problem # A+B Problem
## Tags
- Easy
## Description ## Description
Given two integers `a` and `b`, calculate the sum of them. Given two integers `a` and `b`, calculate the sum of them.

View File

@ -5,7 +5,6 @@ SCRIPT_PATH=$(cd "$(dirname "$0")" && pwd)
function docker_run() { function docker_run() {
local timeout=${TIMEOUT:-10} local timeout=${TIMEOUT:-10}
local network=${NETWORK:-"none"}
local memory=${MEMORY:-"256m"} local memory=${MEMORY:-"256m"}
local log_file=${LOG_FILE:-"/dev/stderr"} local log_file=${LOG_FILE:-"/dev/stderr"}
local log_limit=${LOG_LIMIT:-4K} local log_limit=${LOG_LIMIT:-4K}
@ -15,7 +14,7 @@ function docker_run() {
sleep "$timeout" sleep "$timeout"
$DOCKER kill "$CONTAINER_NAME" $DOCKER kill "$CONTAINER_NAME"
) & ) &
$DOCKER run --rm --name "$CONTAINER_NAME" --network "$network" --memory "$memory" "$@" 2>&1 | head -c "$log_limit" >"$log_file" $DOCKER run --rm --name "$CONTAINER_NAME" --memory "$memory" "$@" 2>&1 | head -c "$log_limit" >"$log_file"
pkill -P $$ pkill -P $$
$DOCKER kill "$CONTAINER_NAME" >/dev/null 2>&1 $DOCKER kill "$CONTAINER_NAME" >/dev/null 2>&1
return 0 return 0

View File

@ -9,13 +9,19 @@ if [ -z "$endpoint" ]; then
exit 1 exit 1
fi fi
read -p "Enter token: " -r token read -p "Enter Token: " -r token
if [ -z "$token" ]; then if [ -z "$token" ]; then
log_error "[-] Token cannot be empty" log_error "[-] Token cannot be empty"
exit 1 exit 1
fi fi
for problem in "$WORKSPACE/problem/"*; do read -p "Enter Directory: " -r directory
if [ ! -d "$directory" ]; then
log_error "[-] Not a Directory"
exit 1
fi
for problem in "$directory/"*; do
if [ -d "$problem" ]; then if [ -d "$problem" ]; then
dir_name=$(basename "$problem") dir_name=$(basename "$problem")
log_info "[+] Importing problem $dir_name" log_info "[+] Importing problem $dir_name"
@ -37,21 +43,37 @@ for problem in "$WORKSPACE/problem/"*; do
continue continue
fi fi
#######################
# Get Problem Details #
#######################
title=$(head -n 1 "$problem/description.md" | sed -e 's/^# //' | xargs) title=$(head -n 1 "$problem/description.md" | sed -e 's/^# //' | xargs)
description=$(cat "$problem/description.md") description=$(cat "$problem/description.md")
# TODO: extract tags tags=$(sed -n '/^## Tags/,/^##/p' "$problem/description.md" | grep -Ev '^##|^$' | sed -e 's/^- //' | xargs | jq -Rc 'split(" ")')
log_info "[*] Title: $title" log_info "[*] Title: $title"
log_info "[*] Tags: $tags"
####################
# Compress Problem #
####################
zip_file=$(mktemp -u --suffix .zip) zip_file=$(mktemp -u --suffix .zip)
log_info "[*] Compressing $problem into $zip_file" >/dev/null log_info "[*] Compressing $problem into $zip_file" >/dev/null
cd "$problem" && zip -9rq "$zip_file" . -x ".mark.prebuild" && cd .. cd "$problem" && zip -9rq "$zip_file" . -x ".mark.prebuild" && cd ..
############################
# Create Problem Statement #
############################
log_info "[*] Creating problem statement"
payload=$(jq -nc \ payload=$(jq -nc \
--arg title "$title" \ --arg title "$title" \
--arg description "$description" \ --arg description "$description" \
'{ pid: 0, title: $title, statement: $description, is_enable: false }') --argjson tags "$tags" \
'{ title: $title, statement: $description, tags: $tags }')
log_info "[*] Creating problem statement"
response=$(curl -s \ response=$(curl -s \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: $token" \ -H "Authorization: $token" \
@ -69,7 +91,12 @@ for problem in "$WORKSPACE/problem/"*; do
id=$(echo "$response" | jq -r '.body.meta.ID') id=$(echo "$response" | jq -r '.body.meta.ID')
log_info "[*] Problem statement created with id: $id" log_info "[*] Problem statement created with id: $id"
log_info "[*] Uploading problem package" ###################
# Get Storage URL #
###################
log_info "[*] Getting Upload URL"
response=$(curl -s \ response=$(curl -s \
-H "Authorization: $token" \ -H "Authorization: $token" \
-X POST \ -X POST \
@ -84,6 +111,13 @@ for problem in "$WORKSPACE/problem/"*; do
upload_url=$(echo "$response" | jq -r '.body.url') upload_url=$(echo "$response" | jq -r '.body.url')
storage_key=$(echo "$response" | jq -r '.body.key') storage_key=$(echo "$response" | jq -r '.body.key')
##################
# Upload Problem #
##################
log_info "[*] Uploading Problem Package"
curl -s -X PUT -T "$zip_file" "$upload_url" curl -s -X PUT -T "$zip_file" "$upload_url"
# shellcheck disable=SC2181 # shellcheck disable=SC2181
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -92,12 +126,17 @@ for problem in "$WORKSPACE/problem/"*; do
continue continue
fi fi
##########################
# Create Problem Version #
##########################
log_info "[*] Creating problem version"
payload=$(jq -nc \ payload=$(jq -nc \
--argjson pid "$id" \ --argjson pid "$id" \
--arg storage_key "$storage_key" \ --arg storage_key "$storage_key" \
'{ pid: $pid, storage_key: $storage_key }') '{ pid: $pid, storage_key: $storage_key }')
log_info "[*] Creating problem version"
response=$(curl -s \ response=$(curl -s \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: $token" \ -H "Authorization: $token" \

View File

@ -17,7 +17,7 @@ fi
if [ ! -f "$WORKSPACE/problem/$1/judge/prebuild.Makefile" ]; then if [ ! -f "$WORKSPACE/problem/$1/judge/prebuild.Makefile" ]; then
log_warn "Problem $1 does not have prebuild scripts" log_warn "Problem $1 does not have prebuild scripts"
log_warn "$WORKSPACE/problem/$1/.mark.prebuild" touch "$WORKSPACE/problem/$1/.mark.prebuild"
exit 0 exit 0
fi fi