feat(pages): upload an image from a Custom HTML block and copy its link
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
44eace2bcb
commit
1136046fc2
15 files changed
+218
-5
No files matched your search
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-12-04
|
||||
@@ -0,0 +1,44 @@
|
||||
# Proposal
|
||||
|
||||
## Why
|
||||
|
||||
Custom HTML blocks hold whole designed sections, such as the INS Hotel technology page. Their images must be served from somewhere. Today the only way to get an image link is to upload it as a hero image and read its id back, or to ask a developer. Marketing staff need to upload an image from the Custom HTML block itself and get a link they can paste into their HTML.
|
||||
|
||||
## What Changes
|
||||
|
||||
- The Custom HTML block's panel gains an **Upload image** file picker. Choosing a file uploads it at once, for the page's company, with the same checks as every page image:
|
||||
- PNG, JPEG or WebP;
|
||||
- at most 2 MB;
|
||||
- the type is checked by the file's content.
|
||||
- Each upload made while the panel is open shows:
|
||||
- a small preview;
|
||||
- its link (`/api/public/page-images/<id>`) in a read-only box;
|
||||
- a **Copy link** button.
|
||||
- A refused upload shows its reason under the picker.
|
||||
- A new page with no company chosen yet asks for one first.
|
||||
- The link is relative, so it works on the published page and inside the sealed frame. The INS top bar's logo already loads this way.
|
||||
|
||||
Not changing:
|
||||
- The server. The existing `POST /api/pages/images` upload and the public image address are used as they are.
|
||||
- Saving. The upload does not touch the page's HTML; staff paste the link where they want it.
|
||||
- Unused images. They stay stored, as an unused hero upload would. Clean-up is left for later.
|
||||
- The list of uploads, which is not saved. It shows this session's uploads only.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
None.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `landing-pages`: adds "Image Upload For Custom HTML".
|
||||
|
||||
## Impact
|
||||
|
||||
- Portal:
|
||||
- `BlockFields.tsx`, the HTML block panel;
|
||||
- the editor passes the page's company to the panel (or the panel reads it from the draft hook);
|
||||
- `uploadPageImage` already exists.
|
||||
- New labels in `defaultMessages.ts` and `zh_CN.seed.json`, a regenerated local seed, and a SQL label file in this change folder.
|
||||
- No server or schema change.
|
||||
@@ -0,0 +1,23 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Image Upload For Custom HTML
|
||||
|
||||
A Custom HTML block's panel in the editor SHALL offer an image upload for the page's company, under the same checks as other page images. On success it SHALL show the image's preview and its public link with a copy button; on refusal it SHALL show the reason. The upload SHALL NOT change the block's HTML.
|
||||
|
||||
#### Scenario: Upload an image for the HTML
|
||||
|
||||
- **GIVEN** staff editing an INS page with a Custom HTML block
|
||||
- **WHEN** they choose `lobby.webp` under "Upload image" in that block's panel
|
||||
- **THEN** the image is stored for INS and the panel shows its preview and the link `/api/public/page-images/<id>`
|
||||
- **AND** "Copy link" copies that link, and the block's HTML is unchanged
|
||||
|
||||
#### Scenario: Refused upload
|
||||
|
||||
- **WHEN** staff choose a 3 MB JPEG under "Upload image"
|
||||
- **THEN** the panel shows that the image is too large, and no link appears
|
||||
|
||||
#### Scenario: New page without a company
|
||||
|
||||
- **GIVEN** a super admin's new page with no company chosen
|
||||
- **WHEN** they choose a file under "Upload image"
|
||||
- **THEN** nothing is uploaded and the panel asks them to choose a company
|
||||
@@ -0,0 +1,7 @@
|
||||
-- The labels added by add-html-image-upload, cut from the output of `npm run i18n:sql`. Run it only in an environment that already ran add-zh-cn-messages/sql/03-zh-cn-messages.sql; otherwise run that 03 file, which includes these labels.
|
||||
SET NAMES utf8mb4;
|
||||
USE `service-system`;
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesUploadImage', JSON_OBJECT('en_US', 'Upload image', 'zh_CN', '上传图片'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesUploadImage') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '上传图片') WHERE LOWER(code) = LOWER('PagesUploadImage') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesUploadImageHint', JSON_OBJECT('en_US', 'PNG, JPEG or WebP up to 2 MB. Paste the link into your HTML, for example in an img tag''s src.', 'zh_CN', 'PNG、JPEG 或 WebP,最大 2 MB。将链接粘贴到您的 HTML 中,例如 img 标签的 src。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesUploadImageHint') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', 'PNG、JPEG 或 WebP,最大 2 MB。将链接粘贴到您的 HTML 中,例如 img 标签的 src。') WHERE LOWER(code) = LOWER('PagesUploadImageHint') AND area = 'A';
|
||||
@@ -0,0 +1,34 @@
|
||||
# Tasks
|
||||
|
||||
## 1. Portal
|
||||
|
||||
- [x] 1.1 HTML block panel: an "Upload image" file picker (`image/png,image/jpeg,image/webp`) uploads at once through `uploadPageImage(companyId, base64)`.
|
||||
- Each success adds a row: preview, a read-only link `/api/public/page-images/<id>`, and a "Copy link" button that uses the clipboard.
|
||||
- A refusal shows the translated server reason under the picker.
|
||||
- With no company, the panel shows "Choose a company." and does not upload.
|
||||
- The block's HTML is never changed.
|
||||
|
||||
Verify: editor tests (success row and copy, refusal, no company, HTML unchanged) fail first, then pass; vitest exit 0; tsc; lint.
|
||||
- [x] 1.2 Add the labels (`PagesUploadImage`, `PagesUploadImageHint`; the copy button reuses the page-address copy button) to `defaultMessages.ts`, `zh_CN.seed.json` and `sql/01-html-image-labels.sql`, and regenerate `local/seed/04-zh-cn-messages.sql`.
|
||||
|
||||
## 2. Verification
|
||||
|
||||
- [x] 2.1 Use Playwright on port 3001, signing in through the form and opening Hotel technology from Pages.
|
||||
- In a Custom HTML block, upload an image, copy the link, and check that the panel shows the preview and the link.
|
||||
- Upload a file that is not an image and see the refusal.
|
||||
- Do not change the published page.
|
||||
- [x] 2.2 Run the full portal vitest (exit 0), tsc, lint, and `openspec validate add-html-image-upload --strict`. Add a release note to `docs/deployment.md` (label SQL).
|
||||
|
||||
## Notes (2026-12-04)
|
||||
|
||||
- **Red first:** the success, refusal and no-company editor tests all failed, because there was no "Upload image" picker yet. They pass now.
|
||||
- **Live check** (port 3001): signed in through the form, then opened Hotel technology from Pages.
|
||||
- In block 3 (Custom HTML), uploaded `hero-bg.webp`. The panel showed the preview and `/api/public/page-images/7` with a copy button.
|
||||
- A text file named `.png` was refused with "Use a PNG, JPEG or WebP image."
|
||||
- The page was not saved or published.
|
||||
- **Fix from the live check:** the link was shown twice (a read-only box and the copy button's text). It now shows once, beside its copy button, which reuses the page-address copy button with a `relative` option.
|
||||
- **Results:** vitest 1997 passed (exit 0); tsc clean; lint 0 errors (the 4 warnings were already there).
|
||||
|
||||
## Workflow follow-up
|
||||
|
||||
- Open a PR to `main` and merge it. Archive the change on its own branch, with its own PR.
|
||||
Reference in new issue
Block a user