Skip to content

Commit a8261ce

Browse files
fix(service-storage)!: every upload bound resolves by one precedence, and unset never means unlimited (#33883)
Clause-②: no (narrowing) Metadata-protocol: none Skills-docs: none — no published skill names the storage upload bound, the storage plugin's options or `max_upload_mb` ## 维护者速读 - 改了什么:存储的上传上限改为三个 Limits 键共用的同一条优先级(已保存的设置 > 宿主选项 > 清单默认值 > 内置默认 100 MB),新增宿主选项 `maxUploadMb`(数字或显式的 `'unlimited'`),「未设置」不再等于「不限」。 - 为什么改:规则要求每个上传入口在任何组合下都有上限;不限只能由宿主以 `maxUploadMb: 'unlimited'` 明确选择,并在启动时以 warn 宣告;宿主传错值则拒绝启动。 - 风险与回滚:上述组合(以及已保存但无效的 `max_upload_mb`)的上传从不限变为 100 MB(BREAKING,changeset 与 README 里有「Who moves」与逐行修复,含 DevPlugin 的具体步骤);默认 `os serve`(绑定设置、未保存)本来就是 100 MB,不变。回滚即还原本 PR。 - 先看:`packages/services/service-storage/src/storage-limits.ts`(`pickLayer` 与 `resolveStorageLimits` 的上传层、`parseHostMaxUploadMb`),`storage-service-plugin.ts`(构造函数校验与启动行钩子),`mount-storage-routes.ts`。 - 两分钟验证:`pnpm --filter @objectstack/service-storage exec vitest run --maxWorkers=2 src/storage-limits.test.ts`,预期 43 个测试全绿。 - 需要你做的:无,席位落地 ## What changes Every storage upload bound now resolves by one precedence, the same for all three storage Limits keys (`presigned_ttl`, `session_ttl`, `max_upload_mb`): **saved setting > host option > manifest default > built-in default**. Unset never means unlimited. - **Built-in default.** `DEFAULT_MAX_UPLOAD_MB = 100` (`storage-limits.ts`), held equal to the settings manifest's declared `max_upload_mb` default by a drift pin. - **Host option.** `maxUploadMb` on the `StorageServicePlugin` constructor, on `MountStorageRoutesOptions` and on `StorageRoutesOptions`: the host layer, through the same `pickLayer` the TTLs use. It takes a positive number of MB, or `'unlimited'`. Anything else throws `InvalidMaxUploadMbError` at construction or mount (`parseHostMaxUploadMb`). - **Failure paths.** A settings read that fails, and a saved value that is present but invalid (dropped by `readStorageLimits`), fall to the host option or else the built-in default. - **Coverage.** The bound applies wherever `maxUploadBytes` is read: the byte doors (chunk `PUT`, presigned local raw `PUT`, upload-link `PUT` and its several-file form), the declared-size doors (presign, chunked start), and the server-side verbs (`field-file-service.ts`, `file-attachment-service.ts`, `record-file-access.ts`), which now take the plugin's host option as `hostMaxUploadMb`. - **Boot line.** Each host door says once the bound in force and the layer it came from: the plugin (a `kernel:ready` hook registered after the settings binding, through its logger), `mountStorageRoutes` and `registerStorageRoutes` (through the `logger` they are given, `announceUploadBound`). It is a `warn` when there is no bound, which only an explicit host `'unlimited'` reaches, and that `warn` is said on `console.warn` when the door was given no logger. - **Host bound edges.** A host number must floor to a finite bound of at least one byte: a number too small to bound one byte, or too large to be a finite byte bound, is refused like any other malformed value. The file verbs (`FieldFileService`, `FileAttachmentService`, `RecordFileAccess`) judge a host bound handed to them at construction too. - **Entry exports.** `HostMaxUploadMb` (type) and `InvalidMaxUploadMbError` are exported from the package entry, so a host can type the option and recognise the refusal by class. - The upload refusal's message also names the host option, for hosts with no storage settings. - Docs: the service-storage README Limits section and the error catalog's `PAYLOAD_TOO_LARGE` entry state the rule. The stale comment in `request-body-limit-upload-doors.dogfood.test.ts` now names the built-in bound. - Test wiring: `@objectstack/service-settings` joins service-storage's devDependencies and its vitest source aliases, so the drift pin reads the manifest from source. **BREAKING, who moves:** a DevPlugin-composed server; `--preset minimal` with storage; `mountStorageRoutes` hosts over a bare adapter or an unbound plugin; `bindToSettings: false` embedders; settings-bound hosts during a settings fault; a host whose saved or env-sourced `max_upload_mb` is present but not a positive number. Each moves from no bound to 100 MB. Remedies: a host that constructs the plugin passes `maxUploadMb: 500` or `maxUploadMb: 'unlimited'`; a DevPlugin-composed server turns DevPlugin's storage toggle off and mounts the plugin itself (`new DevPlugin({ services: { storage: false }, extraPlugins: [new StorageServicePlugin({ maxUploadMb: 500 })] })`, or the instance in the stack's `plugins`); a host with an invalid saved value corrects it, because the saved layer cannot spell "no bound", and to accept any size removes it and passes the host's `'unlimited'`. The settings manifest's default value is unchanged. ## Tests `packages/services/service-storage/src/storage-limits.test.ts` §5 and `record-file-access.integration.test.ts`: - **Rule pins.** Each unset path resolves to 100 MB: resolution with no snapshot; a plugin with no settings service; a settings read that fails; a dropped saved value; `mountStorageRoutes` over a bare adapter and over an unbound plugin's service; `bindToSettings: false`. The host option overrides the manifest default, on the plugin and on `mountStorageRoutes`. An explicit `'unlimited'` is honoured and announced at `warn`: by the plugin, by the mount with a logger and with none (on `console.warn`), and by `registerStorageRoutes` with a logger and with none; a bounded mount or registration with no logger writes nothing to `console.warn`, and a bounded registration names its bound and layer to its logger. A malformed host option (`0`, `-1`, `NaN`, `Infinity`, `1e-9`, `Number.MAX_VALUE`, `'100'`, `'Unlimited'`, `'none'`, `null`, `true`, `{}`) refuses the plugin, the mount and the route registrar, with no route registered, and the file verbs refuse one handed to them; a bound of exactly one byte (`1 / MiB`) constructs and resolves to 1 byte. A saved setting still wins over a host `'unlimited'`. The drift pin. - **Door pins** (no settings bound). A declared 101 MB body is refused unread, and an undeclared one is read under the built-in bound and refused, at the local raw `PUT`, the chunk `PUT`, the upload-link `PUT` and its several-file form. A presign and a chunked start for 101 MB are refused. A 101 MB file inside a several-file form within its form limit is refused by the link verb, with the link unspent. `field-files` and `file-attachments` refuse a 101 MB file before the engine is reached. - **Controls.** Exactly 100 MB is accepted. A settings-bound plugin with nothing saved holds the declared 100 MB, 3600 s and 86400 s, as before (the default `os serve` composition). The host's explicit `'unlimited'` states no bound and relays a host size refusal in its own words. Under `'unlimited'` the server verbs pass the size verdict. - **Flipped controls.** The no-settings, `bindToSettings: false` and "states no bound" controls now assert the built-in bound. The two "a host size refusal is not the door's own" cases moved to the explicit `'unlimited'` mount, which is the only no-bound path left. ## Acceptance notes - `mountStorageRoutes`' `maxUploadMb` bounds that mount's doors. The server-side verbs on the kernel take the storage plugin's own `maxUploadMb`. A host that passes a larger bound to the mount than to the plugin gets the tighter of the two on the upload-link spend, which is judged again in the verb. - The released 18.5.0 changelog note "with `max_upload_mb` unset a byte door states no bound" no longer holds. The new changeset says so; the released entry is not edited. - Importer packages' suites (cli, runtime, mailbox, organizations, plugin-dev and others) were not re-run locally. No test outside this package sends more than 100 MB through a storage door (grep of the test tree), and CI runs them. ## Verification <details><summary>Package test and typecheck, head 667098e</summary> ``` pnpm --filter @objectstack/service-storage exec vitest run --maxWorkers=2 Test Files 86 passed (86) Tests 1672 passed | 1 skipped (1673) pnpm --filter @objectstack/service-storage typecheck check:test-typecheck: OK — 0 file(s) / 0 error(s) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablation 1: the built-in layer resolved to no bound, then restored</summary> `node scripts/ablation-replace.mjs` on `storage-limits.ts`, anchor hit 1 -> 0, replacement 0 -> 1, run of `storage-limits.test.ts` and `record-file-access.integration.test.ts` (head 92e01a9): ``` Tests 18 failed | 113 passed (131) ablation-replace: ok restored: blob == HEAD (c44e644) and `git diff HEAD` is empty ``` </details> <details><summary>Ablation 2: the no-logger announcement removed, then restored</summary> `node scripts/ablation-replace.mjs` on `storage-limits.ts` (`announceUploadBound` says nothing without a logger), anchor hit 1 -> 0, run of `storage-limits.test.ts` (head 667098e): ``` × mountStorageRoutes with no logger still announces 'unlimited' at warn, on console × registerStorageRoutes announces the bound in force: 'unlimited' at warn, with a logger or, without one, on console Tests 2 failed | 41 passed (43) ablation-replace: ok restored: blob == HEAD (9ffe93f) and `git diff HEAD` is empty ``` </details> <details><summary>Derived gate families, head 667098e</summary> `node scripts/pm/dispatch-gates.mjs --commands`: 121 derived, 121 run (`--ran`: 121 accounted for). 118 exit 0, including `check-adr-0087-registration --base origin/main`, `check-changeset-no-major`, `check-empty-changeset`, `check:changeset-fixed`, `check:cross-package-test-inputs`, `check:test-source-alias`, `check:doc-authoring`, `check:i18n` and `check:nul-bytes`. The derivation warned that the tree is 21 commits behind `origin/main`, with 6 derivation inputs changed in that range; main was not merged, because there is no conflict and no main-caused red. NOT MEASURED, left to CI: `@objectstack/spec check:skill-examples` and `check:dual-build-cjs-loads` (exit 3, PREREQUISITE NOT MET: a whole-workspace build), and `check:type-check-debt` (exit 124: the local 600 s timeout expired while its closure build waited for the verify lock behind the dogfood battery). CI's Type Check lanes cover all three. </details> <details><summary>Dogfood battery, final head 667098e</summary> ``` pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' build && pnpm --filter @objectstack/dogfood test os-verify-lock: VERDICT command-exit 0 · held the lock 2163s Test Files 467 passed | 3 skipped (470) Tests 3959 passed | 42 skipped (4001) ``` The first head (14805de) gave the same counts: 467 passed | 3 skipped files, 3959 passed | 42 skipped tests. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f)_ <!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6f9a2e8 commit a8261ce

17 files changed

Lines changed: 976 additions & 90 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
'@objectstack/service-storage': patch
3+
---
4+
5+
fix(service-storage)!: every upload bound resolves by one precedence, and unset never means unlimited
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any authorable schema is added, removed, renamed or re-shaped and no stored row changes: `max_upload_mb` keeps its manifest key, type and declared default, and what moves is the bound a storage door enforces when no layer sets one, plus one optional constructor option (`maxUploadMb`) on the plugin, `mountStorageRoutes` and `registerStorageRoutes`. There is nothing for `objectstack migrate meta` to rewrite. -->
11+
12+
**BREAKING** for a host whose storage doors had no upload bound because nothing set one. Each such host now enforces 100 MB per upload.
13+
14+
**The rule.** The three storage Limits keys (`presigned_ttl`, `session_ttl`, `max_upload_mb`) resolve by one precedence, highest first: a saved setting (an admin save or an env override), the host's option, the settings manifest's default, the built-in default. Unset never means unlimited.
15+
16+
- **Built-in default.** `max_upload_mb`'s built-in default is 100 MB (counted as MiB), the number the settings manifest declares. A drift pin holds the two equal.
17+
- **Host option.** `maxUploadMb` on the `StorageServicePlugin` constructor, on `mountStorageRoutes` and on `registerStorageRoutes` is the host layer, exactly like `presignedTtl` and `sessionTtl`. It takes a positive number of MB, or `'unlimited'` for no bound. Any other value (`0`, a negative or non-finite number, a numeric string, any other string) refuses construction or the mount.
18+
- **Failure paths.** A settings read that fails, and a saved value that is present but not a positive number, take the host option or else the built-in default, never no bound.
19+
- **Coverage.** The bound applies wherever an upload is judged: the byte doors (the chunk `PUT`, the presigned local raw `PUT`, the upload-link `PUT` and its several-file form), the declared-size doors (presign, chunked start), and the server-side file verbs (`field-files`, `file-attachments` and the upload link's several-file spend).
20+
- **Boot line.** Each host door says, once at boot or mount, the bound in force and the layer it came from: the plugin through its logger, `mountStorageRoutes` and `registerStorageRoutes` through the `logger` they are given. With an explicit `'unlimited'` the line is a `warn`, and it is said even when no logger was passed, on `console.warn`.
21+
22+
**Who moves.** Each of these moves from no upload bound to 100 MB:
23+
24+
- a DevPlugin-composed server;
25+
- `--preset minimal` with storage;
26+
- a `mountStorageRoutes` host over a bare adapter or over a plugin bound to no settings;
27+
- an embedder that passes `bindToSettings: false`;
28+
- a settings-bound host while its settings read fails;
29+
- a host whose saved or env-sourced `max_upload_mb` is present but not a positive number (it was dropped, and nothing stood in its place).
30+
31+
Remedies:
32+
33+
- **A host that constructs the plugin** (`bindToSettings: false` embedders, `--preset minimal`, settings-fault hosts): one option, `new StorageServicePlugin({ maxUploadMb: 500 })` for another bound, or `maxUploadMb: 'unlimited'` to keep accepting uploads of any size (boot then says so at `warn`). A `mountStorageRoutes` or `registerStorageRoutes` host passes the same option for that mount's doors.
34+
- **A DevPlugin-composed server**: DevPlugin constructs the storage plugin with no options, so turn its storage toggle off and mount the plugin yourself: `new DevPlugin({ services: { storage: false }, extraPlugins: [new StorageServicePlugin({ maxUploadMb: 500 })] })`, or list the `StorageServicePlugin` instance in the stack's own `plugins`, where an explicit instance wins.
35+
- **A host with an invalid saved value**: correct the saved `max_upload_mb` (Setup's File Storage settings, or the env override) to a positive number. The saved layer cannot spell "no bound"; to accept any size, remove the saved value and pass the host option `maxUploadMb: 'unlimited'`.
36+
37+
**Unchanged.** A settings-bound host with nothing saved, which is the default `os serve`, already enforced the manifest's 100 MB and still does. A saved `max_upload_mb` still wins over every host option. The 18.5.0 note "with `max_upload_mb` unset a byte door states no bound and reads the whole body" no longer holds: with `max_upload_mb` unset a byte door states the host's bound or else the built-in 100 MB, and it states no bound only under an explicit host `'unlimited'`.

‎content/docs/api/error-catalog.mdx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,14 @@ The standard catalog names no `413` member.
611611
- **An upload over the File Storage settings' `max_upload_mb`.** The presigned-upload door (the
612612
declared `size`), the chunked-upload start (the declared `totalSize`), the local adapter's raw
613613
upload (the body) and the chunk door (the bytes the upload already holds plus the chunk) refuse
614-
it before anything is stored. The message names the size, the limit and the setting.
614+
it before anything is stored. The message names the size, the limit and the setting. With no
615+
saved value, the bound is the storage plugin's `maxUploadMb` option, then the setting's declared
616+
default, then the built-in 100 MB: an upload bound is never unset.
615617
- **An import over its route's row ceiling** — 5,000 rows on the synchronous route, 50,000 on the
616618
job route ([size limits](/docs/data-modeling/import-mappings#size-limits)).
617619

618-
**Fix:** Raise the setting or send a smaller file; split the import across requests. Resending
620+
**Fix:** Raise the setting (or, with nothing saved, the host's `maxUploadMb`) or send a smaller
621+
file; split the import across requests. Resending
619622
the same request cannot succeed.
620623
**Retry:** `no_retry`
621624

‎packages/qa/dogfood/test/request-body-limit-upload-doors.dogfood.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ describe('the request-body limit leaves each upload door its own bound, over a r
4343
const rootDir = mkdtempSync(join(tmpdir(), 'body-limit-upload-doors-'));
4444
stack = await bootStack(attachmentsFixtureStack as never, {
4545
security: attachmentsFixtureSecurity(),
46-
// `bindToSettings:false` keeps the constructor rootDir and leaves
47-
// `max_upload_mb` unset, so each door's own bound is none at all: what
48-
// is measured here is that the transport limit does not stand in for it.
46+
// `bindToSettings:false` keeps the constructor rootDir and reads no
47+
// `max_upload_mb`, so each door's own bound is the built-in 100 MB, far
48+
// above the transport's 10 MiB: what is measured here is that the
49+
// transport limit does not stand in for it.
4950
extraPlugins: [
5051
new StorageServicePlugin({ adapter: 'local', local: { rootDir }, bindToSettings: false }),
5152
new MCPServerPlugin(),

‎packages/services/service-storage/README.md‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,43 @@ doors whenever the plugin is bound to settings (the default):
110110

111111
| Setting | Default | Applies to |
112112
|:---|:---|:---|
113-
| `max_upload_mb` | 100 (MB, counted as MiB) | Every upload door: the presigned upload's declared `size`, the chunked upload's declared `totalSize`, the local raw PUT body and each chunk's running total. Over it ⇒ `413` with code `PAYLOAD_TOO_LARGE`, before anything is stored. |
113+
| `max_upload_mb` | 100 (MB, counted as MiB) | Every upload door: the presigned upload's declared `size`, the chunked upload's declared `totalSize`, the local raw PUT body, each chunk's running total, the upload-link PUT (and each file of its several-file form), and the server-side file verbs. Over it ⇒ `413` with code `PAYLOAD_TOO_LARGE`, before anything is stored. |
114114
| `presigned_ttl` | 3600 s | Presigned upload URLs and non-gated download URLs issued from then on. |
115115
| `session_ttl` | 86400 s | Chunked upload sessions started from then on. |
116116

117-
Per key, a saved value (an admin save or an env override) wins over the
118-
constructor's `presignedTtl` / `sessionTtl`, and those win over the namespace's
119-
declared default. A save reaches the doors without a restart; URLs and sessions
120-
already issued keep their lifetime. With no settings namespace bound
121-
(`bindToSettings: false`, or no settings service) the constructor TTLs apply and
122-
no upload size limit is enforced. On the S3 adapter a presigned upload is judged
123-
by its declared size — the bytes go straight to the bucket.
117+
All three keys resolve by one precedence, highest first: a saved value (an
118+
admin save or an env override), then the host's option on the plugin's
119+
constructor (or on `mountStorageRoutes`) — `presignedTtl`, `sessionTtl`,
120+
`maxUploadMb` — then the namespace's declared default, then the built-in
121+
default (3600 s, 86400 s, 100 MB). A save reaches the doors without a restart;
122+
URLs and sessions already issued keep their lifetime.
123+
124+
**The upload bound is never unset.** With no settings namespace bound
125+
(`bindToSettings: false`, no settings service, a settings read that failed,
126+
or `mountStorageRoutes` over a bare adapter) and no host option, every upload
127+
door enforces the built-in 100 MB — the number the manifest declares. No limit
128+
is an explicit host choice:
129+
130+
```typescript
131+
new StorageServicePlugin({ maxUploadMb: 500 }); // the host's bound, in MB
132+
new StorageServicePlugin({ maxUploadMb: 'unlimited' }); // no bound, announced at warn on boot
133+
```
134+
135+
Anything else (`0`, a negative or non-finite number, a number too small to
136+
bound one byte, a numeric string, any other string) refuses construction. Each
137+
host door — the plugin, `mountStorageRoutes`, `registerStorageRoutes` — says once
138+
the bound in force and the layer it came from; an explicit `'unlimited'` is said
139+
at `warn`, on `console.warn` when the door was given no logger.
140+
141+
Who moved from no bound to 100 MB, and the remedy:
142+
143+
| Host | Remedy |
144+
|:---|:---|
145+
| Constructs the plugin with no settings bound (`bindToSettings: false`, `--preset minimal`), or its settings read fails | `maxUploadMb: 500` or `'unlimited'` on the plugin |
146+
| `mountStorageRoutes` / `registerStorageRoutes` over a bare adapter or an unbound plugin | the same option on that call |
147+
| DevPlugin-composed server (DevPlugin builds the plugin with no options) | `new DevPlugin({ services: { storage: false }, extraPlugins: [new StorageServicePlugin({ maxUploadMb: 500 })] })`, or list the instance in the stack's `plugins` |
148+
| A saved or env-sourced `max_upload_mb` that is not a positive number | correct the saved value; the saved layer cannot spell "no bound", so to accept any size remove it and pass `maxUploadMb: 'unlimited'` | On the S3 adapter a presigned upload is judged by
149+
its declared size — the bytes go straight to the bucket.
124150

125151
## REST API Endpoints
126152

‎packages/services/service-storage/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@objectstack/objectql": "workspace:*",
5050
"@objectstack/driver-sql": "workspace:*",
5151
"@objectstack/plugin-audit": "workspace:*",
52+
"@objectstack/service-settings": "workspace:*",
5253
"@types/node": "^26.6.5",
5354
"tsx": "^4.23.15",
5455
"typescript": "^6.0.3",

‎packages/services/service-storage/src/field-file-service.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import {
2424
// The upload doors' own size verdict and refusal, asked here rather than
2525
// restated.
2626
import {
27+
parseHostMaxUploadMb,
2728
resolveStorageLimits,
2829
uploadSizeRefusal,
2930
UPLOAD_TOO_LARGE_CODE,
3031
UPLOAD_TOO_LARGE_STATUS,
32+
type HostMaxUploadMb,
3133
type StorageLimitsSnapshot,
3234
} from './storage-limits.js';
3335
// The upload doors' own storage-key layout.
@@ -81,6 +83,12 @@ export interface FieldFileServiceDeps {
8183
getStorage(): IStorageService | null;
8284
/** The `storage` namespace's Limits group as last read — the upload doors' own source. */
8385
getLimitsSnapshot(): StorageLimitsSnapshot | undefined;
86+
/**
87+
* The host's upload bound (the plugin's `maxUploadMb`, already validated) —
88+
* the host layer of the doors' own precedence; absent ⇒ the namespace
89+
* default, else the built-in 100 MB.
90+
*/
91+
hostMaxUploadMb?: HostMaxUploadMb;
8492
logger: FileReferenceLogger;
8593
}
8694

@@ -178,7 +186,10 @@ function isSlot(owner: FieldFileSlot | null, slot: FieldFileSlot): boolean {
178186
}
179187

180188
export class FieldFileService implements IFieldFileService {
181-
constructor(private readonly deps: FieldFileServiceDeps) {}
189+
constructor(private readonly deps: FieldFileServiceDeps) {
190+
// The host bound is judged where the verb is built, as at every host door.
191+
parseHostMaxUploadMb(deps.hostMaxUploadMb, 'FieldFileService');
192+
}
182193

183194
async storeFile(input: StoreFieldFileInput): Promise<StoredFieldFile> {
184195
const request = validateStoreInput(input);
@@ -190,7 +201,7 @@ export class FieldFileService implements IFieldFileService {
190201
const size = request.data.byteLength;
191202
const tooLarge = uploadSizeRefusal(
192203
size,
193-
resolveStorageLimits(this.deps.getLimitsSnapshot()).maxUploadBytes,
204+
resolveStorageLimits(this.deps.getLimitsSnapshot(), { maxUploadMb: this.deps.hostMaxUploadMb }).maxUploadBytes,
194205
(n) => `The file ${request.filename} is ${n} bytes`,
195206
);
196207
if (tooLarge !== null) refuse(UPLOAD_TOO_LARGE_CODE, UPLOAD_TOO_LARGE_STATUS, tooLarge);

‎packages/services/service-storage/src/file-attachment-service.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ import { createWallOrganizationResolver } from './backfill-sys-file-organization
3535
// The upload doors' own size verdict and refusal, asked here rather than
3636
// restated.
3737
import {
38+
parseHostMaxUploadMb,
3839
resolveStorageLimits,
3940
uploadSizeRefusal,
4041
UPLOAD_TOO_LARGE_CODE,
4142
UPLOAD_TOO_LARGE_STATUS,
43+
type HostMaxUploadMb,
4244
type StorageLimitsSnapshot,
4345
} from './storage-limits.js';
4446
// The upload doors' own storage-key layout, and the commit door's question
@@ -140,6 +142,12 @@ export interface FileAttachmentServiceDeps {
140142
getStorage(): IStorageService | null;
141143
/** The `storage` namespace's Limits group as last read — the upload doors' own source. */
142144
getLimitsSnapshot(): StorageLimitsSnapshot | undefined;
145+
/**
146+
* The host's upload bound (the plugin's `maxUploadMb`, already validated) —
147+
* the host layer of the doors' own precedence; absent ⇒ the namespace
148+
* default, else the built-in 100 MB.
149+
*/
150+
hostMaxUploadMb?: HostMaxUploadMb;
143151
logger: { warn(message: string): void; debug?(message: string): void };
144152
/** The sharing service, for the attach rule's verdict ({@link FileAttachmentService.assertMayAttach}). */
145153
getSharing?(): AttachmentSharingLike | null | undefined;
@@ -315,13 +323,16 @@ export class FileAttachmentService
315323
private readonly recordFiles: RecordFileAccess | null;
316324

317325
constructor(private readonly deps: FileAttachmentServiceDeps) {
326+
// The host bound is judged where the verb is built, as at every host door.
327+
parseHostMaxUploadMb(deps.hostMaxUploadMb, 'FileAttachmentService');
318328
const bound = deps.recordFiles;
319329
this.recordFiles = bound
320330
? new RecordFileAccess({
321331
...bound,
322332
getEngine: () => deps.getEngine(),
323333
getStorage: () => deps.getStorage(),
324334
getLimitsSnapshot: () => deps.getLimitsSnapshot(),
335+
hostMaxUploadMb: deps.hostMaxUploadMb,
325336
attachments: this,
326337
getSharing: () => deps.getSharing?.(),
327338
getSecurity: () => deps.getSecurity?.(),
@@ -594,7 +605,7 @@ export class FileAttachmentService
594605
const size = request.data.byteLength;
595606
const tooLarge = uploadSizeRefusal(
596607
size,
597-
resolveStorageLimits(this.deps.getLimitsSnapshot()).maxUploadBytes,
608+
resolveStorageLimits(this.deps.getLimitsSnapshot(), { maxUploadMb: this.deps.hostMaxUploadMb }).maxUploadBytes,
598609
(n) => `The file is ${n} bytes`,
599610
);
600611
if (tooLarge !== null) refuse(UPLOAD_TOO_LARGE_CODE, UPLOAD_TOO_LARGE_STATUS, tooLarge);

‎packages/services/service-storage/src/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export type {
2525
// group as last read. Types only — the reading and the resolution stay inside
2626
// the package, so the precedence has one definition.
2727
export type { StorageLimitsSnapshot, StorageLimitReading } from './storage-limits.js';
28+
// The host's upload bound (`maxUploadMb` on the plugin, `mountStorageRoutes` and
29+
// `registerStorageRoutes`): its type, so a host can type the option, and the
30+
// refusal a malformed one boots into, so a host can recognise it by class.
31+
export type { HostMaxUploadMb } from './storage-limits.js';
32+
export { InvalidMaxUploadMbError } from './storage-limits.js';
2833
// [#15169] The host door: the storage routes composed from a kernel and
2934
// mounted on an HTTP surface the host owns — for kernels with no `http-server`
3035
// service (cloud's per-environment tenant kernels). Published as ONE entry

0 commit comments

Comments
 (0)