fix(submit): use file path over stdin; fix CF CodeMirror textarea (#305)
## Problem After the initial submit hardening, two issues remained: source code was read in Lua and piped as stdin to the scraper (unnecessary roundtrip since the file exists on disk), and CF's `page.fill()` timed out on the hidden `textarea[name="source"]` because CodeMirror owns the editor state. ## Solution Pass the source file path as a CLI arg instead — AtCoder calls `page.set_input_files(file_path)` directly, CF reads it with `Path(file_path).read_text()`. Fix CF source injection via `page.evaluate()` into the CodeMirror instance. Extract `BROWSER_SUBMIT_NAV_TIMEOUT` as a per-platform `defaultdict` (CF defaults to 2× nav timeout). Save the buffer with `vim.cmd.update()` before submitting.
This commit is contained in:
parent
127089c57f
commit
a202725cc5
28 changed files with 269 additions and 168 deletions
|
|
@ -19,7 +19,7 @@ local function prompt_credentials(platform, callback)
|
|||
end
|
||||
vim.ui.input({ prompt = platform .. ' username: ' }, function(username)
|
||||
if not username or username == '' then
|
||||
logger.log('Submit cancelled', vim.log.levels.WARN)
|
||||
logger.log('Submit cancelled', { level = vim.log.levels.WARN })
|
||||
return
|
||||
end
|
||||
vim.fn.inputsave()
|
||||
|
|
@ -27,7 +27,7 @@ local function prompt_credentials(platform, callback)
|
|||
vim.fn.inputrestore()
|
||||
vim.cmd.redraw()
|
||||
if not password or password == '' then
|
||||
logger.log('Submit cancelled', vim.log.levels.WARN)
|
||||
logger.log('Submit cancelled', { level = vim.log.levels.WARN })
|
||||
return
|
||||
end
|
||||
local creds = { username = username, password = password }
|
||||
|
|
@ -42,20 +42,21 @@ function M.submit(opts)
|
|||
local problem_id = state.get_problem_id()
|
||||
local language = (opts and opts.language) or state.get_language()
|
||||
if not platform or not contest_id or not problem_id or not language then
|
||||
logger.log('No active problem. Use :CP <platform> <contest> first.', vim.log.levels.ERROR)
|
||||
logger.log(
|
||||
'No active problem. Use :CP <platform> <contest> first.',
|
||||
{ level = vim.log.levels.ERROR }
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
local source_file = state.get_source_file()
|
||||
if not source_file or vim.fn.filereadable(source_file) ~= 1 then
|
||||
logger.log('Source file not found', vim.log.levels.ERROR)
|
||||
logger.log('Source file not found', { level = vim.log.levels.ERROR })
|
||||
return
|
||||
end
|
||||
|
||||
prompt_credentials(platform, function(creds)
|
||||
local source_lines = vim.fn.readfile(source_file)
|
||||
local source_code = table.concat(source_lines, '\n')
|
||||
|
||||
vim.cmd.update()
|
||||
vim.notify('[cp.nvim] Submitting...', vim.log.levels.INFO)
|
||||
|
||||
require('cp.scraper').submit(
|
||||
|
|
@ -63,7 +64,7 @@ function M.submit(opts)
|
|||
contest_id,
|
||||
problem_id,
|
||||
language,
|
||||
source_code,
|
||||
source_file,
|
||||
creds,
|
||||
function(ev)
|
||||
vim.schedule(function()
|
||||
|
|
@ -73,12 +74,13 @@ function M.submit(opts)
|
|||
function(result)
|
||||
vim.schedule(function()
|
||||
if result and result.success then
|
||||
logger.log('Submitted successfully', vim.log.levels.INFO, true)
|
||||
logger.log('Submitted successfully', { level = vim.log.levels.INFO, override = true })
|
||||
else
|
||||
logger.log(
|
||||
'Submit failed: ' .. (result and result.error or 'unknown error'),
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
local err = result and result.error or 'unknown error'
|
||||
if err:match('^Login failed') then
|
||||
cache.clear_credentials(platform)
|
||||
end
|
||||
logger.log('Submit failed: ' .. err, { level = vim.log.levels.ERROR })
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue