feat(api): 单次上传上限改为 context_max_bytes 可配,Cloudflare 边缘后默认 95Mi,新增 GET /me/submissions/limits 供面板预检

This commit is contained in:
Lemon-miaow committed 2026-09-25 18:31:10 +08:00
1 parent e7326e6315
commit 87dee3e5a5
10 files changed
+158 -2

No files matched your search

+24
View File
@@ -934,3 +934,27 @@ func TestUploadSubmissionContextRateLimited(t *testing.T) {
t.Fatalf("retry at the same instant after failure: code = %d, want 200 (%s)", w.Code, w.Body.String())
}
}
type limitedSubmissions struct {
*fakeSubmissions
limit int64
}
func (l limitedSubmissions) ContextLimit() int64 { return l.limit }
// The panel reads the per-upload cap before sending a file; a lane that cannot
// report one answers like any unwired submissions endpoint.
func TestSubmissionLimitsReportsTheContextCap(t *testing.T) {
api := appSubAPI(&fakeSubmissions{})
api.Submissions = limitedSubmissions{&fakeSubmissions{}, 99614720}
w := do(api.ExternalHandler(), "GET", "/api/v1/me/submissions/limits", "", nil)
if w.Code != 200 || strings.TrimSpace(w.Body.String()) != `{"max_context_bytes":99614720}` {
t.Fatalf("limits = %d %s", w.Code, w.Body.String())
}
api.Submissions = nil
w = do(api.ExternalHandler(), "GET", "/api/v1/me/submissions/limits", "", nil)
if w.Code != 503 {
t.Fatalf("unwired limits = %d %s", w.Code, w.Body.String())
}
}