Compare commits
6 Commits
aef5b2f3a2
...
8b3961e633
Author | SHA1 | Date | |
---|---|---|---|
8b3961e633 | |||
68c11932e1 | |||
61f8fb2765 | |||
e4fc2c01d0 | |||
e2881514d4 | |||
9b8e032f12 |
@ -37,6 +37,7 @@ func (h *handler) Search(c *gin.Context) {
|
||||
param := problem.QueryData{
|
||||
Keyword: req.Keyword,
|
||||
Tag: req.Tag,
|
||||
ShouldEnable: true,
|
||||
Offset: req.Offset,
|
||||
Limit: req.Limit,
|
||||
Count: &count,
|
||||
|
@ -3,7 +3,6 @@ package status
|
||||
import (
|
||||
"git.0x7f.app/WOJ/woj-server/internal/e"
|
||||
"git.0x7f.app/WOJ/woj-server/internal/model"
|
||||
"git.0x7f.app/WOJ/woj-server/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -58,7 +57,12 @@ func (h *handler) Query(c *gin.Context) {
|
||||
var response []*submissionWithScore
|
||||
for _, submission := range submissions {
|
||||
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{
|
||||
Submission: *submission,
|
||||
Point: point,
|
||||
|
@ -1,5 +1,9 @@
|
||||
# A+B Problem
|
||||
|
||||
## Tags
|
||||
|
||||
- Easy
|
||||
|
||||
## Description
|
||||
|
||||
Given two integers `a` and `b`, calculate the sum of them.
|
||||
|
@ -5,7 +5,6 @@ SCRIPT_PATH=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
function docker_run() {
|
||||
local timeout=${TIMEOUT:-10}
|
||||
local network=${NETWORK:-"none"}
|
||||
local memory=${MEMORY:-"256m"}
|
||||
local log_file=${LOG_FILE:-"/dev/stderr"}
|
||||
local log_limit=${LOG_LIMIT:-4K}
|
||||
@ -15,7 +14,7 @@ function docker_run() {
|
||||
sleep "$timeout"
|
||||
$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 $$
|
||||
$DOCKER kill "$CONTAINER_NAME" >/dev/null 2>&1
|
||||
return 0
|
||||
|
@ -9,13 +9,19 @@ if [ -z "$endpoint" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -p "Enter token: " -r token
|
||||
read -p "Enter Token: " -r token
|
||||
if [ -z "$token" ]; then
|
||||
log_error "[-] Token cannot be empty"
|
||||
exit 1
|
||||
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
|
||||
dir_name=$(basename "$problem")
|
||||
log_info "[+] Importing problem $dir_name"
|
||||
@ -37,21 +43,37 @@ for problem in "$WORKSPACE/problem/"*; do
|
||||
continue
|
||||
fi
|
||||
|
||||
#######################
|
||||
# Get Problem Details #
|
||||
#######################
|
||||
|
||||
title=$(head -n 1 "$problem/description.md" | sed -e 's/^# //' | xargs)
|
||||
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 "[*] Tags: $tags"
|
||||
|
||||
####################
|
||||
# Compress Problem #
|
||||
####################
|
||||
|
||||
zip_file=$(mktemp -u --suffix .zip)
|
||||
log_info "[*] Compressing $problem into $zip_file" >/dev/null
|
||||
cd "$problem" && zip -9rq "$zip_file" . -x ".mark.prebuild" && cd ..
|
||||
|
||||
############################
|
||||
# Create Problem Statement #
|
||||
############################
|
||||
|
||||
log_info "[*] Creating problem statement"
|
||||
|
||||
payload=$(jq -nc \
|
||||
--arg title "$title" \
|
||||
--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 \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: $token" \
|
||||
@ -69,7 +91,12 @@ for problem in "$WORKSPACE/problem/"*; do
|
||||
id=$(echo "$response" | jq -r '.body.meta.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 \
|
||||
-H "Authorization: $token" \
|
||||
-X POST \
|
||||
@ -84,6 +111,13 @@ for problem in "$WORKSPACE/problem/"*; do
|
||||
|
||||
upload_url=$(echo "$response" | jq -r '.body.url')
|
||||
storage_key=$(echo "$response" | jq -r '.body.key')
|
||||
|
||||
##################
|
||||
# Upload Problem #
|
||||
##################
|
||||
|
||||
log_info "[*] Uploading Problem Package"
|
||||
|
||||
curl -s -X PUT -T "$zip_file" "$upload_url"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -92,12 +126,17 @@ for problem in "$WORKSPACE/problem/"*; do
|
||||
continue
|
||||
fi
|
||||
|
||||
##########################
|
||||
# Create Problem Version #
|
||||
##########################
|
||||
|
||||
log_info "[*] Creating problem version"
|
||||
|
||||
payload=$(jq -nc \
|
||||
--argjson pid "$id" \
|
||||
--arg storage_key "$storage_key" \
|
||||
'{ pid: $pid, storage_key: $storage_key }')
|
||||
|
||||
log_info "[*] Creating problem version"
|
||||
response=$(curl -s \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: $token" \
|
||||
|
@ -17,7 +17,7 @@ fi
|
||||
|
||||
if [ ! -f "$WORKSPACE/problem/$1/judge/prebuild.Makefile" ]; then
|
||||
log_warn "Problem $1 does not have prebuild scripts"
|
||||
log_warn "$WORKSPACE/problem/$1/.mark.prebuild"
|
||||
touch "$WORKSPACE/problem/$1/.mark.prebuild"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user