Unverified Commit 516c58b5 authored by Lemon-miaow's avatar Lemon-miaow
Browse files

feat(panel): 我的提交页上传前按服务端单次上限预检,超限提示显示文件大小与上限

parent 87dee3e5
Loading
Loading
Loading
Loading
+5 −0
Changes for panel/dev/mockApi.ts: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1735,6 +1735,11 @@ async function handleSubmissionRoute(ctx: SessionContext): Promise<boolean> {
    return true;
  }

  // GET /api/v1/me/submissions/limits — the Cloudflare-edge default.
  if (isMeSubmissions && is("GET", ctx) && ctx.parts.length === 5 && ctx.parts[4] === "limits") {
    sendJSON(ctx.res, 200, { max_context_bytes: 95 * 1024 * 1024 });
    return true;
  }
  // POST /api/v1/me/submissions
  if (isMeSubmissions && is("POST", ctx) && ctx.parts.length === 4) {
    const body = await readJSON<{ display_name?: string }>(ctx.req);
+1 −1
Changes for panel/src/i18n/resources/en-US/submissions.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@
  "search_no_results_hint": "Try a different search term or filter.",
  "search_placeholder": "Search submissions...",
  "error_file_type": "Please upload a valid .tar.gz file.",
  "error_file_size": "File exceeds the allowed size limit.",
  "error_file_size": "The file is {{size}}; one upload may be at most {{limit}}.",
  "error_name_required": "Display name is required.",
  "error_file_required": "Build context file is required.",
  "field_context_ref": "Context Reference",
+1 −1
Changes for panel/src/i18n/resources/zh-CN/submissions.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@
  "search_no_results_hint": "尝试更换搜索词或筛选条件。",
  "search_placeholder": "搜索提交记录...",
  "error_file_type": "请上传有效的 .tar.gz 压缩文件。",
  "error_file_size": "文件超过了允许的大小限制。",
  "error_file_size": "文件大小为 {{size}},单次上传最多 {{limit}}。",
  "error_name_required": "必须填写显示名称。",
  "error_file_required": "必须上传构建上下文文件。",
  "field_context_ref": "构建上下文引用",
+2 −0
Changes for panel/src/lib/api.ts: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -714,6 +714,8 @@ export const api = rejectingSync({
  },

  listMySubmissions: (params?: SubmissionListParams) => submissionPage("/me/submissions", params),
  /** The per-upload context cap, checked before a file is sent. */
  submissionLimits: () => request<{ max_context_bytes: number }>("GET", "/me/submissions/limits"),

  createSubmission: (displayName: string) =>
    request<Submission>("POST", "/me/submissions", { display_name: displayName }),
+45 −1
Changes for panel/src/lib/openapi.gen.ts: 45 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -1827,6 +1827,26 @@ export interface paths {
        patch?: never;
        trace?: never;
    };
    "/api/v1/me/submissions/limits": {
        parameters: {
            query?: never;
            header?: never;
            path?: never;
            cookie?: never;
        };
        /**
         * The per-upload build-context cap
         * @description The effective [registry] context_max_bytes: 1 GiB by default, 95 MiB behind the Cloudflare edge (its proxy refuses bodies over 100 MB before they reach the API). The panel checks a file against it before upload.
         */
        get: operations["submissionLimits"];
        put?: never;
        post?: never;
        delete?: never;
        options?: never;
        head?: never;
        patch?: never;
        trace?: never;
    };
    "/api/v1/me/submissions/{id}/context": {
        parameters: {
            query?: never;
@@ -1838,7 +1858,7 @@ export interface paths {
        put?: never;
        /**
         * Upload the modpack build context for your own pending submission (user side; user-directed lane over §16).
         * @description The request body IS the raw gzip build context (context.tar.gz) — not JSON, not multipart — streamed to the platform-derived, id-namespaced location Kaniko reads via --context. The submitter is taken from the principal; a submission the caller does not own is reported as 404, so this endpoint cannot upload to or probe another user's submission. Only a pending_review submission accepts a context (409 otherwise); a wrong-format or oversize body is rejected with 400, and an upload that would push the caller past their per-user stored-context budget is refused with 403 before the excess is persisted. Returns 503 when the deployment's context store has no implemented upload transport.
         * @description The request body IS the raw gzip build context (context.tar.gz) — not JSON, not multipart — streamed to the platform-derived, id-namespaced location Kaniko reads via --context. The submitter is taken from the principal; a submission the caller does not own is reported as 404, so this endpoint cannot upload to or probe another user's submission. Only a pending_review submission accepts a context (409 otherwise); a wrong-format or oversize body is rejected with 400 (the per-upload cap is [registry] context_max_bytes: 1 GiB by default and 95 MiB behind the Cloudflare edge, whose proxy refuses bodies over 100 MB with its own HTML 413 before they reach the API; GET /api/v1/me/submissions/limits reports the effective cap so a client can check a file before sending it), and an upload that would push the caller past their per-user stored-context budget is refused with 403 before the excess is persisted. Returns 503 when the deployment's context store has no implemented upload transport.
         */
        post: operations["uploadSubmissionContext"];
        delete?: never;
@@ -7160,6 +7180,30 @@ export interface operations {
            503: components["responses"]["ServiceUnavailable"];
        };
    };
    submissionLimits: {
        parameters: {
            query?: never;
            header?: never;
            path?: never;
            cookie?: never;
        };
        requestBody?: never;
        responses: {
            /** @description The cap. */
            200: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": {
                        /** Format: int64 */
                        max_context_bytes: number;
                    };
                };
            };
            503: components["responses"]["ServiceUnavailable"];
        };
    };
    uploadSubmissionContext: {
        parameters: {
            query?: never;
Loading