Repository navigation
Commit 333e6f3
fix(data-objectstack): uploadFile/uploadFiles upload through the storage service presigned flow (#38237)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoAoNwrZVJoUEFfvMURpRPKJ)_
Fixes #38163
Clause-②: no
Metadata-protocol: none
Route taken: (a). `uploadFile` and `uploadFiles` now upload through the
package's own presigned storage adapter,
`createObjectStackUploadAdapter`. `recordId` maps to `attachTo` with
scope `attachments`, and the adapter's result maps to
`FileUploadResult`. The declared `DataSource` contract promises an
upload that returns a stored file, and the storage service is the one
upload route the standard server serves, so (a) keeps that promise and
(b) would not. Two options cannot be mapped: `fieldName` and `metadata`.
Neither presigned request carries them. Those two are refused before any
request, in the (b) manner, with an error that names the supported path,
so nothing is dropped silently. Neither method sends a request to
`/api/data/RESOURCE/upload` any more.
Why refusing `fieldName` / `metadata` is not a narrowing (`Clause-②: no`
stands): before this PR every call to either method failed. The standard
server answers the old route 404 `ENDPOINT_NOT_FOUND` (405 with the
version segment), whatever options were passed, so no caller had a
working upload that carried those options. This PR removes no working
behaviour. A call that always failed now succeeds without the two
options, and with them it fails at once with an error that names the
supported path, instead of a 404. The public types
(`DataSource.uploadFile` / `uploadFiles`, `FileUploadResult`) are
unchanged, and no metadata an author writes is affected
(`Metadata-protocol: none`).
## 维护者速读
-
用户能看到什么变化:用界面数据层「上传文件」接口的应用和插件,上传现在真正落到存储服务,拿回已存好的文件;以前每次都失败。普通控制台用户无感,因为仓库里没人调用它。
- 为什么做:修复界面数据层对外声明却发往一条不存在地址的上传接口,替以后要调用它的应用解决问题。
- 出错会怎样:调用方传了直传流程带不了的两个附加选项,会立刻收到写明改法的报错,而不是被悄悄丢掉。其余改动可直接撤回。
- 要你做的:无。
## What changes
- `ui/packages/data-objectstack/src/index.ts`: `uploadFile` delegates to
`createObjectStackUploadAdapter`, which sends `POST
/api/v1/storage/upload/presigned`, the byte `PUT`, then `POST
/api/v1/storage/upload/complete`. The adapter is built per call because
`attachTo` is one of its construction options. The fetch it uses is
built once per data source (`storageUploadFetch`). That fetch is the
injected `uploadTransport` (#37506), plus the data source's `token` on
every request to this server and never on a presigned URL on another
origin. The same-origin check compares resolved origins: the URL is
resolved against `baseUrl`, or the page's origin when `baseUrl` is
empty, and it counts as this server only when the origins match (and,
for a `baseUrl` with a path, the resolved path lies under it). A server
that cannot be read, or a URL that does not parse, is not this server.
`uploadFiles` is N sequential presigned uploads. The first refused file
stops the batch, and the rejection's `details` carry `failedIndex` plus,
as `uploaded`, the files already stored. The files after it are not
sent.
- Option mapping: `recordId` maps to `attachTo: { parentObject:
resource, parentId: recordId }` and `scope: 'attachments'`. Without it,
no scope is sent, so the server default applies, and `resource` is not
sent. `onProgress` maps the adapter's 0 to 1 ratio to 0 to 100, spread
across the batch for `uploadFiles`. `fieldName` and `metadata` reject
with `UNSUPPORTED_OPERATION` before any request.
- Errors: a refused storage request rejects `ObjectStackError` with
`UPLOAD_ERROR`, the server's status, and `details.serverCode`. A failure
that got no HTTP answer reaches the caller unchanged, as before.
- `ui/packages/data-objectstack/src/upload-adapter.ts`: the presign
refusal and the byte-PUT refusal now carry `status` (and `code`), as the
completion refusal already did, so the mapping above can read them.
Messages are unchanged.
- No public shape changes: `DataSource.uploadFile` / `uploadFiles` and
`FileUploadResult` are untouched.
-
`packages/qa/dogfood/test/data-objectstack-upload-route-38163.dogfood.test.ts`:
the real-stack pin. `packages/qa/dogfood/package.json` gains one
devDependency, `@object-ui/data-objectstack` (`workspace:*`), and
`pnpm-lock.yaml` gains only that importer entry, written by `pnpm
install`. With that, the pin resolves the adapter, the dogfood closure
builds it, and the dogfood test hash follows adapter changes.
`packages/qa/dogfood/vitest.config.ts` gains the one anchored alias
`check:test-source-alias` prescribes, so the pin resolves the adapter's
SOURCE in this checkout and not its last build. The dogfood package is
private, so it needs no changeset.
## Tests
- `uploadTransport-37506.test.ts` is updated, because its fake server
now answers 404 on `/api/data/RESOURCE/upload` as the real one does. The
#37506 pins keep their meaning: injected fetch, bearer on every request,
connection state unchanged. A new top-level describe for #38163 checks
that no request reaches the unserved route, the exact three-step
sequence per file, the `recordId` mapping and result, the default scope
without `recordId`, the refusal of `fieldName` and `metadata` with zero
requests, token-only signing with no token on a foreign presigned URL,
`UPLOAD_ERROR` code, status and serverCode, the partial-batch report,
progress, and presigned URLs spelled protocol-relative (`//host`),
slash-backslash and double-backslash getting no token while the presign
and complete requests keep it. Ablation, run after the commit: with the
previous string check restored, the slash-backslash case fails (1 of
15). The double-backslash case already got no token under that check.
With the origin comparison removed, all three spellings and the
cross-origin case fail (4 of 15). After restoring, git status is clean.
- Unit ablation: with the base `index.ts` restored on disk, the file
reported 12 of 12 failed. With the fix restored, it reported 21 of 21
passed (this file plus `objectstack-upload-scope-12055.test.ts`).
- Package run: 128 of 128 test files and 1450 of 1450 tests passed, and
`type-check` exited 0, both on 95e3f9f.
- Real-stack pin (2 of 2 passing again on 95e3f9f; its `baseUrl` is a
bare origin, so no path rule applies), first measured on head 9725c42,
resolving the adapter source through the alias (the dependency is
declared, and no link was made by hand). The stack is `bootStack` with
`StorageServicePlugin`, the attachments fixture and a bearer-only
session. `uploadFile` with a `recordId` (token only) and `uploadFiles`
(host bearer fetch) pass 2 of 2. They assert committed `sys_file` rows,
the `sys_attachment` row with its `attachmentId`, and that no request
reached an unserved upload path. Ablation: with the base `index.ts`
restored on disk (the file shows the old route twice), both tests fail
with `UPLOAD_ERROR` "Not found", the server's 404. After `git checkout
HEAD`, git status is clean and both pass again. The dogfood `typecheck`
exits 0.
## Acceptance notes
- `README.md` (File Uploads) does not describe `uploadFile` /
`uploadFiles`, and it is outside the claimed surface. No sentence in it
became false.
## Verification
Read first: `index.ts`, at `uploadThroughStorage` and
`storageUploadFetch` (where the token goes, and which URLs get it), then
`uploadFiles` (what a partial batch reports).
Two-minute check: run `pnpm --dir ui exec vitest run
packages/data-objectstack/src/uploadTransport-37506.test.ts`. Expected:
15 passed.
<details><summary>Local gates on head 95e3f9f</summary>
`node scripts/pm/dispatch-gates.mjs --commands` derived 87 families over
the 8 changed paths, and all 87 exited 0, `check:test-source-alias`
included. The `--ran` reconciliation reported: 87 derived, 87 run, 0
NOT-MEASURED. `overlap-check` reported clean: origin/main, #38192 (which
shares the dogfood `package.json`) and #38284 (which shares
`pnpm-lock.yaml`) all merge cleanly. All other CI families are left to
the PR's check-runs.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM)_
<!-- signed: repo:objectstack#3 · os-tesla ·
session_01L9qibx7DSQZnugnuX8CpCM -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ed4ec27 commit 333e6f3
8 files changed
Lines changed: 582 additions & 131 deletions
File tree
- .changeset
- packages/qa/dogfood
- test
- ui/packages/data-objectstack/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
248 | 252 | | |
249 | 253 | | |
250 | 254 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments