Skip to content

Commit

Permalink
feat: add contest stage option to skip ranklist calculation (#103)
Browse files Browse the repository at this point in the history
* chore: update iaaa impl

* feat: add ranklistSkipCalculation

* chore: defered version bump
  • Loading branch information
thezzisu authored Aug 10, 2024
1 parent b4326ce commit c284305
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .yarn/versions/93c713c7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
releases:
"@aoi-js/frontend": patch
"@aoi-js/server": patch
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const keys: {
solutionShowOtherDetails: 'solution-show-other-details',
solutionShowOtherData: 'solution-show-other-data',
ranklistEnabled: 'ranklist-enabled',
ranklistSkipCalculation: 'ranklist-skip-calculation',
participantEnabled: 'participant-enabled'
}
Expand All @@ -62,6 +63,7 @@ en:
solution-show-other-details: Solution Allow Other Details
solution-show-other-data: Solution Allow Other Data
ranklist-enabled: Ranklist Enabled
ranklist-skip-calculation: Skip Ranklist Calculation
participant-enabled: Participant Enabled
contest-stage-settings-hint:
registration-enabled: Enable registration
Expand All @@ -75,6 +77,7 @@ en:
solution-show-other-details: Allow show other details
solution-show-other-data: Allow show other data
ranklist-enabled: Enable ranklist
ranklist-skip-calculation: Skip ranklist calculation
participant-enabled: Enable participant
zh-Hans:
contest-stage-settings:
Expand All @@ -89,6 +92,7 @@ zh-Hans:
solution-show-other-details: 允许展示他人提交记录细节
solution-show-other-data: 允许展示他人提交记录数据
ranklist-enabled: 启用排名
ranklist-skip-calculation: 跳过排名计算
participant-enabled: 启用参赛者
contest-stage-settings-hint:
registration-enabled: 开启后,选手才可以报名
Expand All @@ -102,5 +106,6 @@ zh-Hans:
solution-show-other-details: 开启后,选手可以查看他人提交详情
solution-show-other-data: 开启后,选手可以查看他人提交内容(代码、数据等)
ranklist-enabled: 开启后,选手才可以查看排行榜
ranklist-skip-calculation: 开启后,本阶段提交不计入排行榜(订正模式)
participant-enabled: 开启后,选手才可以查看参赛者列表
</i18n>
18 changes: 15 additions & 3 deletions apps/frontend/src/utils/user/iaaa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ const html = `
`

export async function getToken() {
const win = window.open('/auth/iaaa', 'iaaa', 'width=800,height=600')
const client = win?.window
const iframe = document.createElement('iframe')
iframe.style.background = 'white'
iframe.style.zIndex = '9999'
iframe.style.border = 'none'
iframe.style.position = 'fixed'
iframe.style.top = '0'
iframe.style.left = '0'
iframe.style.width = '100%'
iframe.style.height = '100%'
iframe.src = '/auth/iaaa'
document.body.appendChild(iframe)
// const win = window.open('/auth/iaaa', 'iaaa', 'width=800,height=600')
const client = iframe.contentWindow
if (!client) throw new Error('Failed to open IAAA window')
client.document.write(html)
client.document.forms[0].submit()
for (;;) {
try {
const token = new URLSearchParams(client.document.location.search).get('token')
if (token) {
win.close()
// win.close()
iframe.remove()
return token
}
} catch (err) {
Expand Down
28 changes: 27 additions & 1 deletion apps/server/src/routes/runner/ranklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
contestRanklistKey,
getUploadUrl
} from '../../index.js'
import { T } from '../../schemas/index.js'
import { SContestStage, T } from '../../schemas/index.js'
import { defineInjectionPoint } from '../../utils/inject.js'
import { defineRoutes, loadUUID, paramSchemaMerger } from '../common/index.js'

Expand Down Expand Up @@ -74,6 +74,32 @@ const runnerRanklistTaskRoutes = defineRoutes(async (s) => {
}
)

s.get(
'/contest',
{
schema: {
description: 'Get contest details',
response: {
200: T.Object({
_id: T.UUID(),
slug: T.String(),
title: T.String(),
description: T.String(),
tags: T.Array(T.String()),
stages: T.Array(SContestStage)
})
}
}
},
async (req, rep) => {
const ctx = req.inject(kRunnerRanklistContext)

const contest = await contests.findOne({ _id: ctx._contestId, ranklistTaskId: ctx._taskId })
if (!contest) return rep.notFound()
return contest
}
)

s.get(
'/problems',
{
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/schemas/contest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const SContestStage = T.StrictObject({
solutionShowOtherData: T.Boolean(),
// Enable function function to participants
ranklistEnabled: T.Boolean(),
// Skip ranklist calculation
ranklistSkipCalculation: T.Boolean(),
// Show participants panel
participantEnabled: T.Boolean(),
// Participant tag rules
Expand Down

0 comments on commit c284305

Please sign in to comment.