From 4149774695676694f5dfeada6a87e6719bde1576 Mon Sep 17 00:00:00 2001 From: five-plus-one <5plus1@five-plus-one.com> Date: Sun, 1 Nov 2026 14:34:39 +0800 Subject: [PATCH 1/3] docs: define admin editing and release acceptance workflow --- AGENTS.md | 1 + Docs/README.md | 2 ++ Docs/admin-editing.md | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 Docs/admin-editing.md diff --git a/AGENTS.md b/AGENTS.md index 27c2c03..52f3cc6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,6 +30,7 @@ Islet/ 2. **状态同步**:每次开始和结束工作,更新 `workspace/status.md` 3. **workspace 保洁**:临时文件用完即删,不留垃圾文件 4. **不允许边写边设计**:不清楚的需求先在 workspace 草稿,确认后才写入 Docs +5. **问题交付**:严格遵循 Issue → 分支 → 验收 → PR → Release。先登记问题再创建对应分支,完成测试与实际页面验收后才创建 PR;发布版本关联合并后的源码、验收记录及部署恢复信息。 ## 开发纪律 diff --git a/Docs/README.md b/Docs/README.md index 515571d..e6ddd83 100644 --- a/Docs/README.md +++ b/Docs/README.md @@ -3,6 +3,8 @@ | 文档 | 内容 | |------|------| | [product-design.md](product-design.md) | 产品目标、信息架构、交互规范与验收计划 | +| [admin-editing.md](admin-editing.md) | 分组、存储策略编辑流程与弹层验收要求 | +| [acceptance-admin-editing-2026-11-01.md](acceptance-admin-editing-2026-11-01.md) | 管理端编辑、草稿与配置保存验收 | | [image-workspace.md](image-workspace.md) | 上传取链、相册封面与客户端连接交互 | | [acceptance-image-workspace-2026-10-31.md](acceptance-image-workspace-2026-10-31.md) | 图片工作台交互、布局及上线验收 | | [acceptance-orientation-2026-11-01.md](acceptance-orientation-2026-11-01.md) | 照片方向、缩略图重建及上线验收 | diff --git a/Docs/admin-editing.md b/Docs/admin-editing.md new file mode 100644 index 0000000..1a9240c --- /dev/null +++ b/Docs/admin-editing.md @@ -0,0 +1,32 @@ +# 管理端编辑流程 + +关联问题:[#1](https://github.com/five-plus-one/Islet/issues/1)、[#2](https://github.com/five-plus-one/Islet/issues/2)。 + +## 页面与表单 + +用户分组和存储策略使用独立编辑页,支持直接访问与刷新。列表保留管理入口;编辑页明确显示对象名称、返回入口和保存、取消操作。 + +- 分组:基本信息、容量与上传、可用存储三个分区。 +- 存储策略:基本信息、存储连接、图片访问三个分区。本地存储只显示适用选项。 +- 复用已发布共享库的 ManagementForm、WorkspaceSection、表单网格、Checkbox、Button 等组件。业务页面处理权限、验证、请求、草稿和保存。 +- 分区切换保留草稿。保存时验证全部分区,错误时定位对应分区并保留输入。 +- 编辑期间离开页面提示保存状态,可继续编辑或放弃修改。保存中防止重复提交和导航。 +- 编辑既有存储时密钥留空表示保留,页面不回显密钥,不在浏览器持久保存草稿。 +- 名称重复时显示可理解的重名提示,保存失败保留草稿;服务端分组错误不向页面返回数据库诊断。 + +## 兼容与含义 + +历史分组的空存储列表与空格式列表可能返回 null。前端请求边界将 null 归一化为空数组,保留有效限制项。空存储列表代表全部存储,空格式列表代表全部受支持图片格式;界面明确解释这一含义,选择指定存储时必须至少选择一项。容量、单张上限和每小时上传数量为 0 时表示不限,不能显示为 0 B。数值保存前验证非负、有限且字节数和数量为安全整数。 + +## 弹层使用 + +仅保留删除确认、创建本地用户、创建相册、上传密钥、移动图片等短任务弹窗。图片详情保留带预览的侧栏;客户端连接使用现有宽布局。逐项检查内容量、焦点、关闭行为和操作位置,避免页面与浮层同时出现无意义的多层滚动。 + +## 验收 + +1. 默认分组与自定义分组均可打开、刷新、编辑、保存并重新读取;历史 null 数组不导致异常。 +2. 分组限制、存储选择与已有密钥保持正确含义;取消、切换分区和失败重试保留预期草稿。 +3. 本地与对象存储完整配置均能编辑,加载失败和目标不存在可恢复。 +4. 桌面、分屏、手机连续缩放,深浅色与键盘操作可用;保存取消可达,弹层和提示不遮挡内容。 +5. 正式站点仅执行读取、打开与取消;写入测试在隔离验收环境进行。 +6. 验收完成后创建 PR,发布版本关联测试结果、线上检查与恢复版本。 From 66c71d76f93c21052ac50c1cd33007230ba2211d Mon Sep 17 00:00:00 2001 From: five-plus-one <5plus1@five-plus-one.com> Date: Sun, 1 Nov 2026 14:34:40 +0800 Subject: [PATCH 2/3] fix: complete group and storage policy editing flows --- .github/workflows/ci.yml | 2 +- backend/internal/router/admin.go | 19 +- backend/internal/service/group_service.go | 29 +- frontend/admin/e2e/acceptance.spec.ts | 19 + frontend/admin/package-lock.json | 4 +- frontend/admin/package.json | 3 +- frontend/admin/src/api.ts | 17 +- frontend/admin/src/react/App.tsx | 43 +- frontend/admin/src/react/admin-editors.tsx | 662 +++++++++++++++++++++ frontend/admin/src/react/main.tsx | 18 +- frontend/admin/src/react/management.tsx | 336 ++--------- frontend/admin/src/react/style.css | 8 + frontend/admin/tests/admin-api.test.ts | 56 ++ 13 files changed, 890 insertions(+), 326 deletions(-) create mode 100644 frontend/admin/src/react/admin-editors.tsx create mode 100644 frontend/admin/tests/admin-api.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2ff31f..447a292 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,6 @@ jobs: working-directory: backend env: ISLET_CDN_TEST_DSN: root:islet-ci-database@tcp(127.0.0.1:3306)/islet_cdn_jobs_test?charset=utf8mb4&parseTime=true&loc=Local - - run: npm ci && npm run type-check && npm run build + - run: npm ci && npm test && npm run type-check && npm run build working-directory: frontend/admin - run: docker compose --env-file deploy/.env.example -f deploy/docker-compose.yml config --quiet diff --git a/backend/internal/router/admin.go b/backend/internal/router/admin.go index b42cda0..6dd98fb 100644 --- a/backend/internal/router/admin.go +++ b/backend/internal/router/admin.go @@ -121,6 +121,19 @@ func policyError(c *gin.Context, err error) { } // registerGroupRoutes 用户分组管理(admin+)。 +func groupError(c *gin.Context, err error) { + switch { + case errors.Is(err, service.ErrGroupNotFound): + response.NotFound(c, err.Error()) + case errors.Is(err, service.ErrGroupNameInvalid): + response.BadRequest(c, err.Error()) + case errors.Is(err, service.ErrGroupNameExists), errors.Is(err, service.ErrGroupBuiltIn), errors.Is(err, service.ErrGroupInUse): + response.Error(c, http.StatusConflict, 4009, err.Error()) + default: + response.ServerError(c, "分组操作暂未完成,请稍后重试") + } +} + func registerGroupRoutes(admin *gin.RouterGroup, deps *Deps) { admin.GET("/user-groups", func(c *gin.Context) { groups, err := deps.Groups.List() @@ -151,7 +164,7 @@ func registerGroupRoutes(admin *gin.RouterGroup, deps *Deps) { } group, err := deps.Groups.Create(in) if err != nil { - response.Error(c, http.StatusConflict, 4009, err.Error()) + groupError(c, err) return } deps.Audit.Record(&user.ID, "group.create", "user_group", strconv.FormatUint(group.ID, 10), nil, clientIP(c)) @@ -167,7 +180,7 @@ func registerGroupRoutes(admin *gin.RouterGroup, deps *Deps) { } group, err := deps.Groups.Update(id, in) if err != nil { - response.Error(c, http.StatusConflict, 4009, err.Error()) + groupError(c, err) return } deps.Audit.Record(&user.ID, "group.update", "user_group", c.Param("id"), nil, clientIP(c)) @@ -177,7 +190,7 @@ func registerGroupRoutes(admin *gin.RouterGroup, deps *Deps) { user, _ := middleware.CurrentUser(c) id, _ := strconv.ParseUint(c.Param("id"), 10, 64) if err := deps.Groups.Delete(id); err != nil { - response.Error(c, http.StatusConflict, 4009, err.Error()) + groupError(c, err) return } deps.Audit.Record(&user.ID, "group.delete", "user_group", c.Param("id"), nil, clientIP(c)) diff --git a/backend/internal/service/group_service.go b/backend/internal/service/group_service.go index c4e0771..26cd630 100644 --- a/backend/internal/service/group_service.go +++ b/backend/internal/service/group_service.go @@ -5,16 +5,18 @@ import ( "errors" "strings" + "github.com/go-sql-driver/mysql" "gorm.io/gorm" "islet/backend/internal/model" ) var ( - ErrGroupNotFound = errors.New("用户分组不存在") - ErrGroupNameExists = errors.New("分组名称已存在") - ErrGroupBuiltIn = errors.New("内置分组不可删除") - ErrGroupInUse = errors.New("分组仍有用户,无法删除") + ErrGroupNotFound = errors.New("用户分组不存在") + ErrGroupNameExists = errors.New("分组名称已存在") + ErrGroupBuiltIn = errors.New("内置分组不可删除") + ErrGroupInUse = errors.New("分组仍有用户,无法删除") + ErrGroupNameInvalid = errors.New("分组名称不能为空,最多 64 字") ) // GroupService 用户分组管理。 @@ -68,7 +70,7 @@ func (s *GroupService) Get(id uint64) (model.UserGroup, error) { func (s *GroupService) Create(in GroupInput) (model.UserGroup, error) { name := strings.TrimSpace(in.Name) if name == "" || len([]rune(name)) > 64 { - return model.UserGroup{}, errors.New("分组名称不能为空,最多 64 字") + return model.UserGroup{}, ErrGroupNameInvalid } group := model.UserGroup{ Name: name, Description: strings.TrimSpace(in.Description), @@ -81,10 +83,7 @@ func (s *GroupService) Create(in GroupInput) (model.UserGroup, error) { group.Status = model.StatusDisabled } if err := s.db.Create(&group).Error; err != nil { - if errors.Is(err, gorm.ErrDuplicatedKey) { - return model.UserGroup{}, ErrGroupNameExists - } - return model.UserGroup{}, err + return model.UserGroup{}, groupWriteError(err) } return group, nil } @@ -96,7 +95,7 @@ func (s *GroupService) Update(id uint64, in GroupInput) (model.UserGroup, error) } name := strings.TrimSpace(in.Name) if name == "" || len([]rune(name)) > 64 { - return model.UserGroup{}, errors.New("分组名称不能为空,最多 64 字") + return model.UserGroup{}, ErrGroupNameInvalid } updates := map[string]any{ "name": name, "description": strings.TrimSpace(in.Description), @@ -115,11 +114,19 @@ func (s *GroupService) Update(id uint64, in GroupInput) (model.UserGroup, error) updates["status"] = in.Status } if err := s.db.Model(&group).Updates(updates).Error; err != nil { - return model.UserGroup{}, err + return model.UserGroup{}, groupWriteError(err) } return s.Get(id) } +func groupWriteError(err error) error { + var duplicate *mysql.MySQLError + if errors.Is(err, gorm.ErrDuplicatedKey) || (errors.As(err, &duplicate) && duplicate.Number == 1062) { + return ErrGroupNameExists + } + return err +} + func (s *GroupService) Delete(id uint64) error { var group model.UserGroup if err := s.db.First(&group, id).Error; err != nil { diff --git a/frontend/admin/e2e/acceptance.spec.ts b/frontend/admin/e2e/acceptance.spec.ts index 0ed6790..0dc2b48 100644 --- a/frontend/admin/e2e/acceptance.spec.ts +++ b/frontend/admin/e2e/acceptance.spec.ts @@ -248,6 +248,25 @@ test.describe.serial("Account and storage API acceptance", () => { policy_ids: [1], status: "active", }); + const existingName = ( + await call(owner, "/api/admin/user-groups") + ).items.find((item: any) => item.id === 2).name; + for (const [method, path] of [ + ["POST", "/api/admin/user-groups"], + ["PATCH", `/api/admin/user-groups/${group.ID}`], + ]) { + const duplicate = await owner.fetch(path, { + method, + data: { name: existingName }, + }); + expect(duplicate.status()).toBe(409); + expect((await duplicate.json()).message).toBe("分组名称已存在"); + } + const retainedGroup = ( + await call(owner, "/api/admin/user-groups") + ).items.find((item: any) => item.id === group.ID); + expect(retainedGroup.policy_ids).toEqual([1]); + expect(retainedGroup.allowed_mimes).toEqual(["image/png"]); const user = await call(owner, "/api/admin/users", "POST", { username: "member-" + suffix, password: credentials.password, diff --git a/frontend/admin/package-lock.json b/frontend/admin/package-lock.json index 457425d..ce9840e 100644 --- a/frontend/admin/package-lock.json +++ b/frontend/admin/package-lock.json @@ -1,12 +1,12 @@ { "name": "islet-admin", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "islet-admin", - "version": "0.2.0", + "version": "0.2.1", "license": "GPL-3.0-only", "dependencies": { "@fiveplusone/ui": "file:vendor/fiveplusone-ui-0.5.77-media.3.tgz", diff --git a/frontend/admin/package.json b/frontend/admin/package.json index 13120dc..0813bac 100644 --- a/frontend/admin/package.json +++ b/frontend/admin/package.json @@ -1,9 +1,10 @@ { "name": "islet-admin", - "version": "0.2.0", + "version": "0.2.1", "private": true, "type": "module", "scripts": { + "test": "node --experimental-strip-types --test tests/*.test.ts", "test:e2e": "playwright test", "dev": "vite --host 127.0.0.1", "type-check": "tsc --noEmit", diff --git a/frontend/admin/src/api.ts b/frontend/admin/src/api.ts index d76513a..3763e1f 100644 --- a/frontend/admin/src/api.ts +++ b/frontend/admin/src/api.ts @@ -371,7 +371,22 @@ export const api = { { method: "POST" }, ), - groups: () => request<{ items: GroupView[] }>("/api/admin/user-groups"), + groups: async () => { + const result = await request<{ + items: (Omit & { + policy_ids: number[] | null; + allowed_mimes: string[] | null; + })[]; + }>("/api/admin/user-groups"); + return { + ...result, + items: result.items.map((group) => ({ + ...group, + policy_ids: group.policy_ids ?? [], + allowed_mimes: group.allowed_mimes ?? [], + })), + }; + }, saveGroup: (input: Partial & { name: string }) => input.id ? request(`/api/admin/user-groups/${input.id}`, { diff --git a/frontend/admin/src/react/App.tsx b/frontend/admin/src/react/App.tsx index f35882d..aadadda 100644 --- a/frontend/admin/src/react/App.tsx +++ b/frontend/admin/src/react/App.tsx @@ -56,6 +56,7 @@ import { import { uploads } from "./uploads"; import { Gallery, UploadPage, Albums, Tokens, Profile } from "./library"; import { AdminPage, Setup } from "./management"; +import { GroupEditor, PolicyEditor } from "./admin-editors"; const navigation = [ ["/images", "图片库", Images], ["/upload", "上传图片", Upload], @@ -372,6 +373,10 @@ function Workspace({ theme }: { theme: React.ReactNode }) { ); const admin = me.user.role !== "user"; + const activePath = + navigation.find( + ([path]) => loc.pathname === path || loc.pathname.startsWith(path + "/"), + )?.[0] || loc.pathname; const items = navigation .filter((_, i) => admin || i < 6) .map(([id, label, Icon]) => ({ id, label, icon: })); @@ -386,7 +391,7 @@ function Workspace({ theme }: { theme: React.ReactNode }) { { navigate(path); setMobile(false); @@ -399,7 +404,7 @@ function Workspace({ theme }: { theme: React.ReactNode }) { variant="sidebar" label="管理导航" items={items.slice(6)} - value={loc.pathname} + value={activePath} onChange={(path) => { navigate(path); setMobile(false); @@ -438,7 +443,7 @@ function Workspace({ theme }: { theme: React.ReactNode }) { - {items.find((x) => x.id === loc.pathname)?.label || "图片工作台"} + {items.find((x) => x.id === activePath)?.label || "图片工作台"}
{theme} @@ -481,6 +486,38 @@ function Workspace({ theme }: { theme: React.ReactNode }) { } /> } /> } /> + + ) : ( + + ) + } + /> + : + } + /> + + ) : ( + + ) + } + /> + : + } + /> void; + dirty: boolean; + busy: boolean; + error: string; + save: () => Promise; + children: ReactNode; +}) { + const navigate = useNavigate(), + saved = useRef(false), + submitting = useRef(false); + const blocker = useBlocker( + ({ nextLocation }) => + !saved.current && (dirty || busy) && nextLocation.pathname !== "/login", + ); + useBeforeUnload((event) => { + if (!saved.current && (dirty || busy)) event.preventDefault(); + }); + useEffect(() => { + if (busy && blocker.state === "blocked") blocker.reset(); + }, [busy, blocker]); + const feedback = useRef(null); + useEffect(() => { + if (error) feedback.current?.focus(); + }, [error, section]); + return ( + <> +
+ +
+
{ + event.preventDefault(); + if (submitting.current) return; + submitting.current = true; + try { + if (await save()) { + saved.current = true; + navigate(destination); + } + } finally { + submitting.current = false; + } + }} + > + { + if (!busy) setSection(value); + }} + status={busy ? "正在保存…" : dirty ? "有未保存的修改" : "设置已载入"} + actions={ + <> + + + + } + > +
+ +
+
{children}
+
+
+ blocker.state === "blocked" && blocker.reset()} + footer={ + <> + + + + } + > +

离开后,本次修改不会保存。

+
+ + ); +} + +export function GroupEditor() { + const { id } = useParams(), + data = useLoad(api.groups, [id]), + policies = useLoad(api.policies); + if (data.loading || policies.loading) return ; + if (data.error || policies.error) + return ( + { + data.reload(); + policies.reload(); + }} + /> + ); + const group = id + ? data.data?.items.find((item) => String(item.id) === id) + : undefined; + if (id && !group) return ; + return ( + + ); +} +function EditorMissing({ + destination, + name, +}: { + destination: string; + name: string; +}) { + const navigate = useNavigate(); + return ( + + + + ); +} +function GroupDraft({ + group, + policies, +}: { + group?: GroupView; + policies: { id: number; name: string; status: string }[]; +}) { + const initial = useRef({ + name: group?.name || "", + description: group?.description || "", + status: group?.status || "active", + quota: String(group ? group.quota_bytes / 1048576 : 1024), + max: String(group ? group.max_file_bytes / 1048576 : 10), + hourly: String(group?.uploads_per_hour ?? 100), + mimes: group + ? (group.allowed_mimes ?? []).join(", ") + : "image/jpeg, image/png, image/webp, image/gif", + policy_ids: [...(group?.policy_ids ?? [])], + allPolicies: !group?.policy_ids?.length, + }).current; + const [draft, setDraft] = useState(initial), + [section, setSection] = useState("basic"), + [error, setError] = useState(""), + [busy, setBusy] = useState(false); + const { notify } = useSession(); + const update = ( + key: K, + value: (typeof draft)[K], + ) => setDraft((current) => ({ ...current, [key]: value })); + async function save() { + setError(""); + if (!draft.name.trim() || draft.name.trim().length > 64) { + setSection("basic"); + setError("请输入 1–64 字的分组名称"); + return false; + } + const quota = Number(draft.quota) * 1048576, + max = Number(draft.max) * 1048576, + hourly = Number(draft.hourly); + if ( + [draft.quota, draft.max, draft.hourly].some((v) => !v.trim()) || + [quota, max, hourly].some((v) => !Number.isSafeInteger(v) || v < 0) + ) { + setSection("limits"); + setError("容量和上传数量须为有效的非负数,上传数量须为整数"); + return false; + } + const mimes = draft.mimes + .split(/[,,]/) + .map((s) => s.trim()) + .filter(Boolean); + if (mimes.some((mime) => !/^image\/[a-zA-Z0-9.+*-]+$/.test(mime))) { + setSection("limits"); + setError("图片格式请使用 image/jpeg 等格式,多个用逗号分隔"); + return false; + } + if (!draft.allPolicies && !draft.policy_ids.length) { + setSection("storage"); + setError("请至少选择一个存储,或选择使用全部存储"); + return false; + } + setBusy(true); + try { + await api.saveGroup({ + id: group?.id, + name: draft.name.trim(), + description: draft.description.trim(), + status: draft.status, + quota_bytes: quota, + max_file_bytes: max, + uploads_per_hour: hourly, + allowed_mimes: mimes, + policy_ids: draft.allPolicies ? [] : draft.policy_ids, + }); + notify("分组已保存"); + return true; + } catch (e) { + setError(errorText(e)); + return false; + } finally { + setBusy(false); + } + } + return ( + + {section === "basic" && ( + + <> + update("name", v)} + required + /> + update("description", v)} + multiline + /> + update("status", v)} + options={statusOptions} + /> + + + )} + {section === "limits" && ( + + <> +
+ update("quota", v)} + /> + update("max", v)} + /> + update("hourly", v)} + /> +
+ update("mimes", v)} + hint="例如 image/jpeg, image/png;留空允许全部受支持的图片格式。" + /> + +
+ )} + {section === "storage" && ( + + <> + update("allPolicies", event.target.checked)} + /> + {draft.allPolicies ? ( +

+ 允许使用全部可用存储,包括以后新增的存储。 +

+ ) : ( + <> +

+ 选择此分组可以使用的存储,至少选择一项。 +

+ {policies.map((policy) => ( + + update( + "policy_ids", + event.target.checked + ? [...draft.policy_ids, policy.id] + : draft.policy_ids.filter( + (value) => value !== policy.id, + ), + ) + } + /> + ))} + + )} + +
+ )} +
+ ); +} + +const blankPolicy: PolicyInput = { + name: "", + driver: "local", + url_mode: "proxy", + naming: "date", + is_default: false, + status: "active", + endpoint: "", + region: "", + bucket: "", + prefix: "", + cdn: "", + cdn_refresh: false, + access_key: "", + secret_key: "", + path_style: true, +}; +export function PolicyEditor() { + const { id } = useParams(), + data = useLoad(api.policies, [id]); + if (data.loading) return ; + if (data.error) return ; + const policy = id + ? data.data?.items.find((item) => String(item.id) === id) + : undefined; + if (id && !policy) + return ; + return ( + + ); +} +function PolicyDraft({ + initial: source, + secretConfigured, +}: { + initial: PolicyInput; + secretConfigured: boolean; +}) { + const initial = useRef(source).current, + [draft, setDraft] = useState(initial), + [section, setSection] = useState("basic"), + [error, setError] = useState(""), + [busy, setBusy] = useState(false); + const { notify } = useSession(); + const update = (key: K, value: PolicyInput[K]) => + setDraft((current) => ({ ...current, [key]: value })); + async function save() { + setError(""); + if (!draft.name.trim() || draft.name.trim().length > 64) { + setSection("basic"); + setError("请输入 1–64 字的策略名称"); + return false; + } + if ( + draft.driver === "s3" && + (!draft.endpoint.trim() || + !draft.bucket.trim() || + !draft.access_key.trim() || + (!draft.secret_key && !secretConfigured)) + ) { + setSection("connection"); + setError("请填写服务地址、存储桶和访问密钥"); + return false; + } + if ( + draft.driver === "s3" && + draft.cdn_refresh && + !/^https:\/\/[^/?#:@]+\/?$/.test(draft.cdn.trim()) + ) { + setSection("delivery"); + setError("请填写完整的 HTTPS 加速域名,例如 https://img.example.com"); + return false; + } + setBusy(true); + try { + await api.savePolicy({ ...draft, name: draft.name.trim() }); + notify("存储策略已保存"); + return true; + } catch (e) { + setError(errorText(e)); + return false; + } finally { + setBusy(false); + } + } + return ( + + {section === "basic" && ( + + <> + update("name", v)} + required + /> +
+ update("driver", v)} + options={[ + { value: "local", label: "本地磁盘" }, + { value: "s3", label: "S3 / 阿里云 OSS" }, + ]} + /> + update("status", v)} + options={statusOptions} + /> +
+ update("is_default", event.target.checked)} + /> + +
+ )} + {section === "connection" && ( + + {draft.driver === "local" ? ( +

本地存储由部署时配置,无需填写连接信息。

+ ) : ( + <> + update("endpoint", v)} + hint="例如 https://oss-cn-shanghai.aliyuncs.com" + /> +
+ update("region", v)} + /> + update("bucket", v)} + /> +
+ update("prefix", v)} + hint="可选,例如 images/" + /> +
+ update("access_key", v)} + /> + update("secret_key", v)} + hint={ + secretConfigured + ? "已保存密钥,留空继续使用。" + : "填写存储提供商的访问密钥。" + } + /> +
+ update("path_style", event.target.checked)} + /> + + )} +
+ )} + {section === "delivery" && ( + + <> + update("naming", v)} + options={[ + { value: "date", label: "日期目录" }, + { value: "random", label: "随机名称" }, + { value: "keep", label: "保留文件名" }, + ]} + /> + {draft.driver === "s3" && ( + <> + update("cdn", v)} + hint="可选,例如 https://img.example.com" + /> + + update("cdn_refresh", event.target.checked) + } + /> +

+ 开启后分享链接默认使用加速域名。加速域名须回源至本站;密钥须有该域名的缓存刷新与查询权限,审核、恢复和回收图片后会自动同步。 +

+

+ 对象存储请设为私有读取,让图片访问继续遵循本站的审核规则。 +

+ + )} + +
+ )} +
+ ); +} diff --git a/frontend/admin/src/react/main.tsx b/frontend/admin/src/react/main.tsx index cd64952..644a625 100644 --- a/frontend/admin/src/react/main.tsx +++ b/frontend/admin/src/react/main.tsx @@ -1,5 +1,5 @@ import { createRoot } from "react-dom/client"; -import { BrowserRouter } from "react-router-dom"; +import { createBrowserRouter, RouterProvider } from "react-router-dom"; import { TooltipProvider } from "@fiveplusone/ui"; import "@fiveplusone/ui/styles.css"; import "@fiveplusone/ui/app-surfaces.css"; @@ -10,10 +10,16 @@ document.documentElement.dataset.product = "brand"; document.documentElement.dataset.theme = localStorage.getItem("islet-theme") || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"); +const router = createBrowserRouter([ + { + path: "*", + element: ( + + + + ), + }, +]); createRoot(document.getElementById("app")!).render( - - - - - , + , ); diff --git a/frontend/admin/src/react/management.tsx b/frontend/admin/src/react/management.tsx index e0c9566..88ab78d 100644 --- a/frontend/admin/src/react/management.tsx +++ b/frontend/admin/src/react/management.tsx @@ -8,13 +8,7 @@ import { EmptyState, Tabs, } from "@fiveplusone/ui"; -import { - api, - type GroupView, - type PolicyInput, - type UserView, - beginOIDCLogin, -} from "../api"; +import { api, type GroupView, type UserView, beginOIDCLogin } from "../api"; import { errorText, humanBytes, groupLabel, dateLabel } from "../utils"; import { Heading, @@ -621,42 +615,15 @@ function Users() { } function Groups() { const data = useLoad(api.groups), - policies = useLoad(api.policies), - { notify } = useSession(); - const [edit, setEdit] = useState | null>(null), - [remove, setRemove] = useState(), - [error, setError] = useState(""), - [busy, setBusy] = useState(false); - const update = (key: string, v: unknown) => - setEdit((x) => ({ ...x, [key]: v })); + navigate = useNavigate(); + const [remove, setRemove] = useState(); return ( <> { - setError(""); - setEdit({ - name: "", - description: "", - quota_bytes: 1073741824, - max_file_bytes: 10485760, - allowed_mimes: [ - "image/jpeg", - "image/png", - "image/webp", - "image/gif", - ], - policy_ids: [], - uploads_per_hour: 100, - status: "active", - }); - }} - > - 新建分组 - + } /> @@ -664,27 +631,35 @@ function Groups() { ) : (
- {data.data?.items.map((x) => ( - -

{groupLabel(x.name)}

-

{x.description}

+ {data.data?.items.map((group) => ( + +

{groupLabel(group.name)}

+

{group.description}

每位成员容量: - {x.quota_bytes ? humanBytes(x.quota_bytes) : "不限"} + {group.quota_bytes ? humanBytes(group.quota_bytes) : "不限"} +

+

+ 单张上限: + {group.max_file_bytes + ? humanBytes(group.max_file_bytes) + : "不限"} +

+

+ {group.status === "active" ? "启用" : "停用"} ·{" "} + {group.policy_ids.length + ? `${group.policy_ids.length} 个指定存储` + : "全部可用存储"}

-

单张上限:{humanBytes(x.max_file_bytes)}

- {!x.built_in && ( - )} @@ -693,110 +668,10 @@ function Groups() { ))}
)} - !busy && setEdit(null)} - footer={ - - } - > - {edit && ( -
- update("name", v)} - /> - update("description", v)} - /> - update("quota_bytes", Number(v) * 1048576)} - /> - update("max_file_bytes", Number(v) * 1048576)} - /> - update("uploads_per_hour", Number(v))} - /> - - update( - "allowed_mimes", - v - .split(",") - .map((x) => x.trim()) - .filter(Boolean), - ) - } - hint="填写 MIME 类型,多个用逗号分隔" - /> -
- 可用存储 - {policies.data?.items.map((x) => ( - - update( - "policy_ids", - e.target.checked - ? [...(edit.policy_ids || []), x.id] - : (edit.policy_ids || []).filter((id) => id !== x.id), - ) - } - /> - ))} -
- update("status", v)} - options={[ - { value: "active", label: "启用" }, - { value: "disabled", label: "停用" }, - ]} - /> - -
- )} -
{remove && ( setRemove(undefined)} onConfirm={async () => { await api.deleteGroup(remove.id); @@ -809,44 +684,18 @@ function Groups() { } function Policies() { const data = useLoad(api.policies), + navigate = useNavigate(), { notify } = useSession(); - const [edit, setEdit] = useState(null), - [remove, setRemove] = useState(), + const [remove, setRemove] = useState(), [error, setError] = useState(""), [busy, setBusy] = useState(false); - const blank: PolicyInput = { - name: "", - driver: "local", - url_mode: "proxy", - naming: "date", - is_default: false, - status: "active", - endpoint: "", - region: "", - bucket: "", - prefix: "", - cdn: "", - cdn_refresh: false, - access_key: "", - secret_key: "", - path_style: true, - }; - const update = (key: string, v: unknown) => - setEdit((x) => ({ ...x!, [key]: v })); return ( <> { - setError(""); - setEdit({ ...blank }); - }} - > - 新建策略 - + } /> @@ -855,23 +704,20 @@ function Policies() { ) : (
- {data.data?.items.map((x) => ( - + {data.data?.items.map((policy) => ( +

- {x.name} - {x.is_default ? " · 默认" : ""} + {policy.name} + {policy.is_default ? " · 默认" : ""}

- {x.driver === "local" ? "本地磁盘" : "对象存储"} ·{" "} - {x.status === "active" ? "启用" : "停用"} + {policy.driver === "local" ? "本地磁盘" : "对象存储"} ·{" "} + {policy.status === "active" ? "启用" : "停用"}

@@ -880,8 +726,9 @@ function Policies() { disabled={busy} onClick={async () => { setBusy(true); + setError(""); try { - await api.testPolicyById(x.id); + await api.testPolicyById(policy.id); notify("存储连接正常"); } catch (e) { setError(errorText(e)); @@ -892,7 +739,7 @@ function Policies() { > 测试连接 -
@@ -900,113 +747,6 @@ function Policies() { ))}
)} - !busy && setEdit(null)} - footer={ - - } - > - {edit && ( -
- update("name", v)} - /> - update("driver", v)} - options={[ - { value: "local", label: "本地磁盘" }, - { value: "s3", label: "S3 / 阿里云 OSS" }, - ]} - /> - {edit.driver === "s3" && ( - <> - {[ - ["endpoint", "服务地址"], - ["region", "区域"], - ["bucket", "存储桶"], - ["prefix", "路径前缀"], - ["cdn", "图片加速地址"], - ["access_key", "访问密钥 ID"], - ["secret_key", "访问密钥(留空保留已有)"], - ].map(([key, label]) => ( - update(key, v)} - /> - ))} - update("cdn_refresh", e.target.checked)} - /> -

- 加速域名须回源至本站;访问密钥需具备该域名的刷新与查询权限。限制、恢复和回收图片时自动同步访问状态。 -

- update("path_style", e.target.checked)} - /> - - )} - update("naming", v)} - options={[ - { value: "date", label: "日期目录" }, - { value: "random", label: "随机名称" }, - { value: "keep", label: "保留文件名" }, - ]} - /> -

- 启用加速与缓存同步后,分享链接默认使用 - CDN。对象存储应设置为私有读取,保留本站的审核与恢复能力。 -

- update("status", v)} - options={[ - { value: "active", label: "启用" }, - { value: "disabled", label: "停用" }, - ]} - /> - update("is_default", e.target.checked)} - /> - -
- )} -
{remove !== undefined && ( footer { + bottom: 0; +} diff --git a/frontend/admin/tests/admin-api.test.ts b/frontend/admin/tests/admin-api.test.ts new file mode 100644 index 0000000..848a178 --- /dev/null +++ b/frontend/admin/tests/admin-api.test.ts @@ -0,0 +1,56 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { api, ApiError } from "../src/api.ts"; + +test("historical group arrays preserve unrestricted and restricted meanings", async () => { + const originalFetch = globalThis.fetch; + const storage = Object.getOwnPropertyDescriptor(globalThis, "localStorage"); + Object.defineProperty(globalThis, "localStorage", { + configurable: true, + value: { getItem: () => null }, + }); + try { + globalThis.fetch = async () => + Response.json({ + code: 0, + data: { + items: [ + { id: 1, policy_ids: null, allowed_mimes: null }, + { + id: 2, + policy_ids: [3, 9], + allowed_mimes: ["image/png", "image/webp"], + }, + ], + }, + }); + const { items } = await api.groups(); + assert.deepEqual(items[0].policy_ids, []); + assert.deepEqual(items[0].allowed_mimes, []); + assert.deepEqual(items[1].policy_ids, [3, 9]); + assert.deepEqual(items[1].allowed_mimes, ["image/png", "image/webp"]); + + let saved: Record | undefined; + globalThis.fetch = async (url, options) => { + assert.equal(url, "/api/admin/user-groups/2"); + assert.equal(options?.method, "PATCH"); + saved = JSON.parse(String(options?.body)); + return Response.json({ code: 0, data: saved }); + }; + await api.saveGroup({ ...items[1], name: "members" }); + assert.deepEqual(saved?.policy_ids, [3, 9]); + assert.deepEqual(saved?.allowed_mimes, ["image/png", "image/webp"]); + + globalThis.fetch = async () => + Response.json({ code: 500, message: "暂时无法保存" }, { status: 500 }); + await assert.rejects( + api.saveGroup({ ...items[1], name: "members" }), + (error: unknown) => + error instanceof ApiError && error.message === "暂时无法保存", + ); + } finally { + globalThis.fetch = originalFetch; + if (storage) Object.defineProperty(globalThis, "localStorage", storage); + else Reflect.deleteProperty(globalThis, "localStorage"); + } +}); From f2d76f9e5a72c2938f313f9e2456637ea9439147 Mon Sep 17 00:00:00 2001 From: five-plus-one <5plus1@five-plus-one.com> Date: Sun, 1 Nov 2026 14:34:40 +0800 Subject: [PATCH 3/3] docs: record admin editing acceptance --- Docs/acceptance-admin-editing-2026-11-01.md | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Docs/acceptance-admin-editing-2026-11-01.md diff --git a/Docs/acceptance-admin-editing-2026-11-01.md b/Docs/acceptance-admin-editing-2026-11-01.md new file mode 100644 index 0000000..968e807 --- /dev/null +++ b/Docs/acceptance-admin-editing-2026-11-01.md @@ -0,0 +1,30 @@ +# 管理端编辑验收 + +日期:2026-11-01。关联 Issue:[#1](https://github.com/five-plus-one/Islet/issues/1)、[#2](https://github.com/five-plus-one/Islet/issues/2)。 + +## 已验证行为 + +| 范围 | 结果 | +| --- | --- | +| 默认分组编辑 | 正式站点复现历史空存储列表异常;候选支持直接打开编辑、刷新、保存与重新读取 | +| 分组限制 | 新建指定本地存储的分组,容量与单张上限为 0、格式留空,保存刷新后指定存储仍保留;空指定范围阻止保存 | +| 输入与失败 | 负数、无效 CDN 域名、重复名称有错误反馈;保存失败保留草稿;分区切换保留输入 | +| 草稿保护 | 取消和侧栏导航显示放弃提示,继续编辑恢复当前草稿,放弃后进入目标页面 | +| 存储配置 | 本地存储创建后回读;对象存储更名保存时密钥留空,随后真实连接测试成功 | +| 布局与键盘 | 390、600、900 和默认 1384 像素窗口;深浅主题;分区方向键、Esc 关闭与焦点路径;窄屏无页面横向溢出,保存取消可达 | +| 弹层审查 | 用户创建 3 字段、相册 2 字段、密钥 2 字段、移动图片 1 字段;图片详情采用全高侧栏,审核确认与 PicList 宽布局可操作 | +| 异常路径 | 不存在的分组提供返回列表;发布候选浏览器没有脚本错误 | + +写入验收使用本机隔离应用与数据库,以及独立 S3 测试存储。正式数据不用于写入测试。页面使用已发布的共享表单组件,宿主仅适配内容宽度、滚动容器与业务逻辑。 + +## 自动验证 + +- Go 构建与全部测试通过。 +- 前端类型检查、正式构建与空数组兼容回归测试通过。 +- 完整候选镜像运行 5 组接口验收,全部通过:账户与分组权限、图片编辑与回收、上传密钥与配额、S3 管理访问、图片审核与原图保留。其中包含分组创建与修改重名提示以及失败后原限制保留断言。 +- Docker Compose 配置校验通过。 +- 浏览器验收使用浏览器工具完成。 + +## 发布恢复 + +候选镜像:`islet:production-20261101.04`。恢复镜像:`islet:production-20261101.03`。本次保持数据库结构兼容;发布只切换 Islet 服务。上线前保存原配置及备份,比较账户、图片、分组、存储配置、环境、挂载、网络和其他业务容器,切换后回读正式编辑入口。