feat(cses): implement submit via REST API (#299)
## Problem CSES submit was a stub returning "not yet implemented". ## Solution Authenticate via web login + API token bridge (POST `/login` form, then POST `/api/login` and confirm the auth page), submit source to `/api/courses/problemset/submissions` with base64-encoded content, and poll for verdict. Uses the same username/password credential model as AtCoder — no browser dependencies needed. Tested end-to-end with a real CSES account (verdict: `ACCEPTED`). Also updates `scraper.lua` to pass the full ndjson event object to `on_status` and handle `credentials` events for future platform use.
This commit is contained in:
parent
e674265527
commit
e9f72dfbbc
4 changed files with 210 additions and 9 deletions
|
|
@ -298,9 +298,12 @@ function M.submit(
|
|||
stdin = source_code,
|
||||
env_extra = { CP_CREDENTIALS = vim.json.encode(credentials) },
|
||||
on_event = function(ev)
|
||||
if ev.credentials ~= nil then
|
||||
require('cp.cache').set_credentials(platform, ev.credentials)
|
||||
end
|
||||
if ev.status ~= nil then
|
||||
if type(on_status) == 'function' then
|
||||
on_status(ev.status)
|
||||
on_status(ev)
|
||||
end
|
||||
elseif ev.success ~= nil then
|
||||
done = true
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ local function prompt_credentials(platform, callback)
|
|||
vim.fn.inputsave()
|
||||
local password = vim.fn.inputsecret(platform .. ' password: ')
|
||||
vim.fn.inputrestore()
|
||||
vim.cmd.redraw()
|
||||
if not password or password == '' then
|
||||
logger.log('Submit cancelled', vim.log.levels.WARN)
|
||||
return
|
||||
|
|
@ -64,9 +65,9 @@ function M.submit(opts)
|
|||
language,
|
||||
source_code,
|
||||
creds,
|
||||
function(status)
|
||||
function(ev)
|
||||
vim.schedule(function()
|
||||
vim.notify('[cp.nvim] ' .. (STATUS_MSGS[status] or status), vim.log.levels.INFO)
|
||||
vim.notify('[cp.nvim] ' .. (STATUS_MSGS[ev.status] or ev.status), vim.log.levels.INFO)
|
||||
end)
|
||||
end,
|
||||
function(result)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue