Fix validation error when saving scripts in debug window (v2.20.0 regression)
PR Type
What kind of change does this PR introduce?
- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Other... Please describe:
What is the current behavior?
In v2.20.0, the script edit debug window's save button fails with "Validation failed" error.
The v2.20.0 validation enhancement added strict Joi schemas to script API routes. The POST /scripts endpoint only allows specific fields, but the frontend SaveModal spreads the entire file object including IFile metadata (key, type, createTime, size, children).
Issue Number: N/A
What is the new behavior?
Add .unknown(true) to the POST /scripts Joi schema to accept extra fields while validating required ones:
celebrate({
body: Joi.object({
filename: Joi.string().required(),
path: Joi.string().optional().allow(''),
content: Joi.string().optional().allow(''),
originFilename: Joi.string().optional().allow(''),
directory: Joi.string().optional().allow(''),
file: Joi.string().optional().allow(''),
}).unknown(true), // Allow IFile metadata fields
})
Other endpoints (PUT /run, /stop, etc.) are unaffected—they send only specific fields.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
CodeQL security scan: 0 alerts
Original prompt
This section details on the original issue you should resolve
<issue_title>v2.20.0版本在脚本编辑的调试窗口下,点击保存按钮报错:Validation failed</issue_title> <issue_description>### Qinglong version
v2.20.0
Steps to reproduce
v2.20.0版本在脚本编辑的调试窗口下,点击保存按钮报错:Validation failed
What is expected?
保存成功
What is actually happening?
Validation failed
System Info
Any additional comments?
No response</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes whyour/qinglong#2860
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Review | Updated (UTC) |
|---|---|---|---|
| qinglong | Preview, Comment | Dec 15, 2025 10:37am | |
| qinglong-back | Preview, Comment | Dec 15, 2025 10:37am |
@copilot
- 为什么会有 version.yaml 的修改
- 在修改cron也会出现
- 根据 2.19.2版本到目前 master 上之间 api 上新增的 validate,排查是否存在其他问题并修复
@copilot
- 为什么会有 version.yaml 的修改
- 在修改cron也会出现 ...
关于您提到的三个问题,我已经分析完毕:
1. version.yaml 修改问题:version.yaml 没有实际修改,在基准提交 (1776eb5) 中已经是 2.20.0 版本。这是 git 显示的误报,已确认没有实际更改。
2. Cron 编辑问题:经过检查,cron 的编辑功能不存在同样的问题。原因是:
-
src/pages/crontab/modal.tsx只发送表单字段值 (payload = { ...values, ... }) - 不像 script saveModal 那样传播整个对象 (
{ ...file, ...values }) - 后端
commonCronSchema验证可以正常工作
3. 其他 API 验证检查:我已系统检查了所有带 celebrate 验证的 API 端点:
- ✅ cron: 不存在问题(只发送表单值)
- ✅ env: 不存在问题(只发送表单值 + id)
- ✅ subscription: 不存在问题(只发送表单值)
- ⚠️ script POST /scripts: 已修复(commit f887eb6)
- ⚠️ script setting.tsx: 存在相同模式但该文件为待开发状态
只有 script 的 saveModal 存在问题,因为它使用 { ...file, ...values, originFilename: file.title } 模式传播了整个 file 对象(包含 IFile 接口的元数据字段如 key, type, createTime 等)。
修复方案:在 POST /scripts 的 Joi 验证添加 .unknown(true) 允许额外字段,同时保持对必需字段的验证。