Repository navigation
Commit ae9c134
fix(storage): the upload-link page speaks the request's language, and its refusals read as page copy (#32891)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DKMkvWZdqZ8XFcrT6arhCKt)_
Refs #32712 (item a)
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:代理用 `create_upload_link` 发给用户的上传页面,现在按请求的语言显示(浏览器
`Accept-Language`,没有时用工作区默认语言,再没有就是英文),平台语言表上的 11
种语言都有译文;上传后页面显示的拒绝原因(记录被审批锁定、字段只读、文件太大等)也改成页面自己的、同一语言的句子,由服务器放在
`error.userMessage` 里返回。
- 为什么改:中文部署里用户打开链接看到的是整页英文;审批锁定的拒绝还带着 `RECORD_LOCKED:`
前缀和记录标题,只读字段的拒绝直接写出对象和字段的 API 名,和页面「不点名记录、字段」的设计(#30892)相冲突。
- 风险与回滚:只动上传链接这一对 GET/PUT 门和它的页面;`error.code`、成功响应体不变,`error.message`
仍是诊断用英文(只去掉生产者自己的代码前缀,与 `/api/v1/data` 一致);工作区默认语言经平台唯一的
`resolveLocalizationContext` 读取,读不到就用英文。回滚即 revert 本 PR。
-
先看:`packages/services/service-storage/src/upload-link-copy.ts`(译文表与「拒绝码到页面句子」的映射)、`storage-routes.ts`(`uploadLinkCopyFor`
的语言顺序与 `relayUploadLinkRefusal`)、`upload-link-page.ts`(页面与脚本读
`userMessage`)。
- 两分钟验证:`pnpm --filter @objectstack/service-storage exec vitest run
src/record-file-access.integration.test.ts src/upload-link-copy.test.ts
-t "#32712"`,预期 13 passed。
- 需要你做的:无,席位落地。
## What changes
One package, `@objectstack/service-storage`. No new export, error code,
route, query parameter or wire field: `userMessage` is the existing
optional member of the error envelope (`ApiErrorSchema.userMessage`).
- **The page's language (`storage-routes.ts`,
`storage-service-plugin.ts`).** Both upload-link doors pick the language
once per request: the request's `Accept-Language` (read with the
platform's `preferredLocaleFromHeader`), else the workspace default for
the signed-in caller, else English. The workspace default is the
`localization` settings for the caller's organization and user, read
through `resolveLocalizationContext`, the resolver every authenticated
door's execution context uses; `composeStorageRoutes` binds it, so the
plugin's mount and the host door (`mountStorageRoutes`) both get it. A
default that cannot be read is no default. The doors still read no query
parameter, so `?locale` is not a source here.
- **The sentences (`upload-link-copy.ts`, new).** Every sentence the
page shows, for each language on the platform locale table
(`PLATFORM_LOCALES`), keyed and read like Setup's storage test answer
(`storage-test-copy.ts`). The two now share one reader, `copy-locale.ts`
(moved out of `storage-test-copy.ts`; `storageTestCopyLocaleOf` keeps
its name and answers). The expiry is written with `Intl.DateTimeFormat`
in the page's language, still in UTC and saying so.
- **The page (`upload-link-page.ts`).** The page's `lang` and `dir`
attributes follow the language (`ar` is right-to-left). The script's
status lines arrive as a JSON literal escaped for an inline script.
After an upload it shows `error.userMessage`, or the page's own "the
upload failed" when the answer carries none; it no longer shows
`error.message`.
- **The refusals (`relayUploadLinkRefusal` and the PUT door's own
refusals).** Each refusal now carries `userMessage`: a text the producer
itself marked for the user (`declaredUserMessage`), verbatim; else the
page's sentence for the code (`AUTH_REQUIRED`, `RESOURCE_NOT_FOUND`,
`PAYLOAD_TOO_LARGE`, `ERR_FILE_CONSTRAINT`, `PERMISSION_DENIED`,
`FIELD_NOT_ACCESSIBLE`, `RECORD_LOCKED`, `RECORD_NOT_FOUND`, any `503`);
else the producer's text behind a localized "the upload was refused"
lead-in. None of the page's sentences names a record, object or field.
`error.message` keeps the producer's wording with its own code prefix
stripped by `withoutDeclaredCodePrefix`, the `/api/v1/data` door's rule,
so the record lock's `RECORD_LOCKED: …` no longer leads it.
- **Route ledger notes** for the two doors say so.
## Why
The card (#32712, triage 6822323217): a zh-CN deployment hands out an
English-only page; ruling C on #32440 (program #32654) has text
addressed to a person composed by its producer in the request's
language. Note 6830733775 (contract review of PR #32779, N1) adds the
refusals the page shows since #32734: the lock refusal reached the page
with its code prefix and the record's title, and the read-only refusal
named object and field by API name.
## Acceptance notes
- Out of scope, untouched: naming the record and the field on the page
(the #30892 privacy choice; needs a maintainer ruling). This PR removes
no ruling: the page's own sentences name nothing, as its header always
said. The refusals that used to carry a record title or `object.field`
were the exception, and now read as page copy.
- The fallback limb shows the producer's text verbatim behind a
localized lead-in, so a refusal the page has no sentence for (an app's
validation rule, `VALIDATION_FAILED`) keeps telling the person why, in
the producer's language. A producer that marks its own `userMessage` is
shown as written.
- The `GET` door's `401 AUTH_REQUIRED` is still the JSON envelope a
browser shows raw (it now carries a localized `userMessage` too).
Turning it into a page is not this card.
- `storage-test-copy.ts` changes only by delegating to the shared
reader; its exports and answers are the same
(`storage-test-locale.test.ts` green).
- Step 0 on `main` `c04aa295`: the page took no request input, and
neither upload-link door read `Accept-Language`, `?locale` or a settings
value (`grep -ci "accept-language|locale"` over `storage-routes.ts` and
`upload-link-page.ts`: 0 and 0). Rendered, the picker page was
`lang="en"`, "Upload a file … It stops working at Thu, 12 Nov 2026
22:00:00 GMT." whatever the request or the workspace said.
## Tests
- `record-file-access.integration.test.ts`, new `#32712` block, through
the real routes on the real plugin (sqlite `:memory:`), with a
`settings` service answering the workspace's `localization.locale` and
announcing changes: the picker page in zh-CN (lang, every sentence, the
expiry, no record/object/field/user named); workspace default when the
request names no language, the request's language winning over it,
English with neither; the unusable page and the PUT's unusable and
sign-in refusals; the record lock and the `readonlyWhen` refusal (the
page's sentence, no `RECORD_LOCKED` prefix, nothing named); the upload
limit in the workspace default with the link still usable; the page
script's status lines in zh-CN showing the door's `userMessage`.
- Existing pins updated: the lock refusal's `message` no longer starts
with `RECORD_LOCKED`; the page shows `userMessage`, and an answer with
none shows "The upload failed." rather than the diagnostic.
- `upload-link-copy.test.ts`, new: every platform locale has every
sentence; no non-English entry repeats an English sentence; English
unchanged; locale reading (aliases, regions, fallback); each code's
sentence; the expiry format.
## Verification
All readings on head `4f6a91d1d8` (branch tip after one `git merge
origin/main`; the merge brought two `ui/` commits and nothing under
`packages/services/`), after a whole-tree `turbo run build`.
<details><summary>Tests</summary>
- `pnpm --filter @objectstack/service-storage test`: 79 files, 1484
tests passed (taken on `6324ca39`+tests, before the `main` merge, which
touched no storage path).
- `pnpm --filter @objectstack/service-storage typecheck` (tsc, scripts
tsconfig, `check:test-typecheck`): exit 0.
- Focused: `vitest run src/record-file-access.integration.test.ts
src/upload-link-copy.test.ts -t "#32712"`: 13 passed.
</details>
<details><summary>Ablations (each through
`scripts/ablation-replace.mjs`: anchor hit 1 to 0, blob restored equal
to HEAD, `git diff HEAD` empty)</summary>
The suite imports `src/` directly, so no rebuild sits between mutation
and run.
- A1, `relayUploadLinkRefusal` keeps the producer's prefix
(`withoutDeclaredCodePrefix(e.message, err)` replaced by `e.message`): 2
red, the lock refusal's `message` starts `RECORD_LOCKED` (the #32734 pin
and the new #32712 pin).
- A2, the relay sends the producer's text as `userMessage`
(`uploadLinkRefusalText(…)` replaced by `message`): 4 red
(unusable/sign-in, lock, read-only, upload limit).
- A3, the workspace default wins over the request's language: 6 red.
- A4, the page script shows `error.message` instead of
`error.userMessage`: 2 red.
</details>
<details><summary>Gates</summary>
- `node scripts/pm/dispatch-gates.mjs --ran`: "75 derived famil(ies)
accounted for — 75 run, 0 NOT-MEASURED". Every family exited 0. Two
(`check:dual-build-cjs-loads`, `check:i18n`) exited 3 on a first pass
before the whole-tree build, and 0 after it on this head.
- `pnpm lint` (`eslint . --no-inline-config`): exit 0.
- The run record is in the project files as
`server-seat5/32712/gates-ran-4f6a91d1.txt`.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cy5JYAeZEX9ESoQ1Uc)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cy5JYAeZEX9ESoQ1Uc
<!-- signed: domain:server#5 · os-elon-musk ·
session_016WV4cy5JYAeZEX9ESoQ1Uc -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 25ee507 commit ae9c134
10 files changed
Lines changed: 1001 additions & 97 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
34 | 41 | | |
35 | 42 | | |
36 | 43 | | |
| |||
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
| |||
81 | 89 | | |
82 | 90 | | |
83 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
84 | 99 | | |
85 | 100 | | |
86 | 101 | | |
| |||
145 | 160 | | |
146 | 161 | | |
147 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
148 | 175 | | |
149 | 176 | | |
150 | 177 | | |
| |||
667 | 694 | | |
668 | 695 | | |
669 | 696 | | |
| 697 | + | |
| 698 | + | |
670 | 699 | | |
671 | 700 | | |
672 | 701 | | |
673 | 702 | | |
674 | 703 | | |
675 | 704 | | |
676 | 705 | | |
677 | | - | |
| 706 | + | |
678 | 707 | | |
679 | 708 | | |
680 | 709 | | |
681 | 710 | | |
682 | 711 | | |
683 | | - | |
684 | | - | |
685 | | - | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
686 | 864 | | |
687 | 865 | | |
688 | 866 | | |
0 commit comments