feat(themes): 添加可编辑的站点外观和皮肤主题(#408)
This commit is contained in:
1 parent
c768fccbc2
commit
5e66cb7c45
70 files changed
+3654
-327
No files matched your search
@@ -159,7 +159,7 @@ func run(ctx context.Context) error {
|
||||
status.markStarted()
|
||||
serveErr := make(chan error, 1)
|
||||
go func() { serveErr <- httpServer.Serve(listener) }()
|
||||
log.Printf("影策 backend listening on %s", addr)
|
||||
log.Printf("backend listening on %s", addr)
|
||||
|
||||
var serveFailure error
|
||||
select {
|
||||
@@ -189,7 +189,7 @@ func run(ctx context.Context) error {
|
||||
if err := errors.Join(shutdownFailures...); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("影策 backend stopped gracefully")
|
||||
log.Printf("backend stopped gracefully")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -473,7 +473,7 @@ func TestBuiltinDocumentationMatchesTextRequestShape(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEveryBuiltinHasDetailedDocumentation(t *testing.T) {
|
||||
requiredSections := []string{"## 接口", "## 模型", "## 参数", "## 官方", "## 影策运行时合同"}
|
||||
requiredSections := []string{"## 接口", "## 模型", "## 参数", "## 官方", "## 宿主运行时合同"}
|
||||
for _, metadata := range Builtins().List("", "", true) {
|
||||
t.Run(metadata.ID, func(t *testing.T) {
|
||||
AttachDocumentation(&metadata)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# Agnes AI 视频协议
|
||||
|
||||
Agnes AI 官方视频接口使用 Bearer API Key 和异步任务模型。影策实现覆盖 `agnes-video-v2.0`、`agnes-video-2.5`、`agnes-video-2.5-flash`,创建任务后保存响应中的 `video_id`,再查询任务状态。官方国际站 Base URL 为 `https://apihub.agnes-ai.com/v1`;密钥只配置在后端渠道,不进入浏览器 URL、日志或任务正文。
|
||||
Agnes AI 官方视频接口使用 Bearer API Key 和异步任务模型。宿主实现覆盖 `agnes-video-v2.0`、`agnes-video-2.5`、`agnes-video-2.5-flash`,创建任务后保存响应中的 `video_id`,再查询任务状态。官方国际站 Base URL 为 `https://apihub.agnes-ai.com/v1`;密钥只配置在后端渠道,不进入浏览器 URL、日志或任务正文。
|
||||
|
||||
## 接口与鉴权
|
||||
|
||||
{{OPERATIONS}}
|
||||
|
||||
创建请求发送到 `/v1/videos`。轮询接口比较特殊:它位于同一主机的根路径 `/agnesapi`,而不是 Base URL 的 `/v1` 下。影策通过“同源根路径”合同拼接请求,因此配置 `https://apihub.agnes-ai.com/v1` 时会得到 `https://apihub.agnes-ai.com/agnesapi?...`,不会错误拼成 `/v1/agnesapi`,也不会把主机硬编码进协议适配器。
|
||||
创建请求发送到 `/v1/videos`。轮询接口比较特殊:它位于同一主机的根路径 `/agnesapi`,而不是 Base URL 的 `/v1` 下。宿主通过“同源根路径”合同拼接请求,因此配置 `https://apihub.agnes-ai.com/v1` 时会得到 `https://apihub.agnes-ai.com/agnesapi?...`,不会错误拼成 `/v1/agnesapi`,也不会把主机硬编码进协议适配器。
|
||||
|
||||
请求头使用 `Authorization: Bearer <API_KEY>` 和 `Content-Type: application/json`。创建响应优先读取 `video_id`,兼容读取 `task_id` 和 `id`;轮询始终携带 `video_id`,并在模型名可用时携带 `model_name`。
|
||||
|
||||
@@ -16,7 +16,7 @@ Agnes AI 官方视频接口使用 Bearer API Key 和异步任务模型。影策
|
||||
- `agnes-video-2.5-flash`:模式与 2.5 相同,但固定 `720P`,参考图最多 5 张,不支持参考视频。
|
||||
- `agnes-video-v2.0`:支持文生视频、单图生视频和多关键帧;时长由 `num_frames / frame_rate` 控制,`num_frames` 必须符合 `8n + 1` 且不超过 441。
|
||||
|
||||
2.5 系列未显式传 `mode` 时,纯文本使用 `text`;存在音频或视频时使用 `reference`;只有一至两张图片时使用 `keyframe`。如果业务需要把图片当风格或主体参考,应在扩展参数中明确传 `mode: "reference"`。模式与媒体组合不合法时,影策在发出上游请求前直接拒绝。
|
||||
2.5 系列未显式传 `mode` 时,纯文本使用 `text`;存在音频或视频时使用 `reference`;只有一至两张图片时使用 `keyframe`。如果业务需要把图片当风格或主体参考,应在扩展参数中明确传 `mode: "reference"`。模式与媒体组合不合法时,宿主在发出上游请求前直接拒绝。
|
||||
|
||||
## 参数映射
|
||||
|
||||
@@ -24,17 +24,17 @@ Agnes AI 官方视频接口使用 Bearer API Key 和异步任务模型。影策
|
||||
|
||||
### Agnes Video 2.5 / 2.5 Flash
|
||||
|
||||
公共请求字段包括 `model`、`prompt`、`mode`、`seconds`、`size`、`aspect_ratio`、`seed`、`n`。影策固定 `n: 1`。影策字段 `images` 在 `keyframe` 模式把前两张图片依次映射为 `first_frame`、`last_frame`;在 `reference` 模式映射为官方图片数组。影策字段 `videos`、`audios` 分别映射为官方同名数组。参考视频当前发送 `{ "url": "..." }`,不臆造 `start_seconds` 或 `require_audio`。
|
||||
公共请求字段包括 `model`、`prompt`、`mode`、`seconds`、`size`、`aspect_ratio`、`seed`、`n`。宿主固定 `n: 1`。宿主字段 `images` 在 `keyframe` 模式把前两张图片依次映射为 `first_frame`、`last_frame`;在 `reference` 模式映射为官方图片数组。宿主字段 `videos`、`audios` 分别映射为官方同名数组。参考视频当前发送 `{ "url": "..." }`,不臆造 `start_seconds` 或 `require_audio`。
|
||||
|
||||
### Agnes Video V2.0
|
||||
|
||||
单张 `images` 输入映射为 `image`;多张图片映射为 `extra_body.image` 并设置 `extra_body.mode: "keyframes"`。影策字段 `duration` 会按 `frame_rate`(缺省 24)换算到最近的 `8n + 1` 帧并限制在 441 帧内。高级字段 `width`、`height`、`num_frames`、`frame_rate`、`num_inference_steps`、`seed`、`negative_prompt` 可由模型协议扩展参数传入。V2.0 不使用 `aspectRatio` 或 `resolution` 直接猜测尺寸。
|
||||
单张 `images` 输入映射为 `image`;多张图片映射为 `extra_body.image` 并设置 `extra_body.mode: "keyframes"`。宿主字段 `duration` 会按 `frame_rate`(缺省 24)换算到最近的 `8n + 1` 帧并限制在 441 帧内。高级字段 `width`、`height`、`num_frames`、`frame_rate`、`num_inference_steps`、`seed`、`negative_prompt` 可由模型协议扩展参数传入。V2.0 不使用 `aspectRatio` 或 `resolution` 直接猜测尺寸。
|
||||
|
||||
## 响应、状态与错误
|
||||
|
||||
创建成功响应中的 `video_id` 是推荐轮询标识。状态映射为:`queued` -> 等待,`in_progress` -> 处理中,`completed` -> 成功,`failed` -> 失败。成功结果优先读取 2.5 官方结构中的 `metadata.url`,并兼容 V2.0 返回的顶层 `url`;如果响应宣称完成却没有视频 URL,影策会返回真实协议错误,不生成假 URL。失败信息优先读取 `error.message`,其次读取顶层 `message` 或 `detail`。
|
||||
创建成功响应中的 `video_id` 是推荐轮询标识。状态映射为:`queued` -> 等待,`in_progress` -> 处理中,`completed` -> 成功,`failed` -> 失败。成功结果优先读取 2.5 官方结构中的 `metadata.url`,并兼容 V2.0 返回的顶层 `url`;如果响应宣称完成却没有视频 URL,宿主会返回真实协议错误,不生成假 URL。失败信息优先读取 `error.message`,其次读取顶层 `message` 或 `detail`。
|
||||
|
||||
参考媒体必须是 Agnes 服务可公开访问且在任务完成前持续有效的 URL。适配器声明了公共媒体 URL 要求,影策运行时会按现有资源流程准备上游可访问地址;本机、私网、Cookie 保护或很快过期的链接不能作为 Agnes 输入。
|
||||
参考媒体必须是 Agnes 服务可公开访问且在任务完成前持续有效的 URL。适配器声明了公共媒体 URL 要求,宿主运行时会按现有资源流程准备上游可访问地址;本机、私网、Cookie 保护或很快过期的链接不能作为 Agnes 输入。
|
||||
|
||||
## 官方资料
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ curl "{channel_base_url}/v1/audio/tasks" \
|
||||
|
||||
## 官方资料与边界
|
||||
|
||||
- 本页以影策当前 adapter 为唯一字段事实源。
|
||||
- 本页以宿主当前 adapter 为唯一字段事实源。
|
||||
- 渠道部署方必须提供真实的模型、声音、错误码和计费文档;没有这些资料时不能对用户承诺能力。
|
||||
|
||||
{{CONTRACT}}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## 接口
|
||||
|
||||
AutoDL.Art 将 ComfyUI 工作流包装为异步任务接口。创建任务使用 `POST /api/v1/comfyui/comfyui_workflow/{workflow_id}`,影策运行时模板为 `/api/v1/comfyui/comfyui_workflow/{model}`;查询结果使用 `GET /api/v1/comfyui/comfyui_workflow/result/{task_id}`,影策运行时模板为 `/api/v1/comfyui/comfyui_workflow/result/{task_id}`。`workflow_id` 由模型字段传入,不能把它写死在渠道地址中。创建接口只返回任务标识,宿主负责按照统一任务生命周期轮询。
|
||||
AutoDL.Art 将 ComfyUI 工作流包装为异步任务接口。创建任务使用 `POST /api/v1/comfyui/comfyui_workflow/{workflow_id}`,宿主运行时模板为 `/api/v1/comfyui/comfyui_workflow/{model}`;查询结果使用 `GET /api/v1/comfyui/comfyui_workflow/result/{task_id}`,宿主运行时模板为 `/api/v1/comfyui/comfyui_workflow/result/{task_id}`。`workflow_id` 由模型字段传入,不能把它写死在渠道地址中。创建接口只返回任务标识,宿主负责按照统一任务生命周期轮询。
|
||||
|
||||
## 模型
|
||||
|
||||
@@ -10,7 +10,7 @@ AutoDL 的模型选择对应 ComfyUI 工作流 ID。不同工作流可以声明
|
||||
|
||||
## 参数
|
||||
|
||||
请求体为 JSON。常用字段包括 `prompt`、`duration` 和 `resolution`;实际工作流可以扩展自己的参数 schema。工作流声明的分辨率选项属于供应商枚举,画布必须保留其完整值,例如 `768p竖`、`768p横`,插件仅在发送前统一转换为小写,不在宿主中增加 AutoDL 专用归一化。状态返回值位于 `data.status`,任务 ID 位于 `data.task_id`,成功结果位于 `data.results`。结果数组中的地址是短期 URL,成功后必须立即由宿主下载到影策资源存储,不能把临时地址直接写入画布长期数据。
|
||||
请求体为 JSON。常用字段包括 `prompt`、`duration` 和 `resolution`;实际工作流可以扩展自己的参数 schema。工作流声明的分辨率选项属于供应商枚举,画布必须保留其完整值,例如 `768p竖`、`768p横`,插件仅在发送前统一转换为小写,不在宿主中增加 AutoDL 专用归一化。状态返回值位于 `data.status`,任务 ID 位于 `data.task_id`,成功结果位于 `data.results`。结果数组中的地址是短期 URL,成功后必须立即由宿主下载到宿主资源存储,不能把临时地址直接写入画布长期数据。
|
||||
|
||||
## 鉴权
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# OpenAI Chat Completions
|
||||
|
||||
Chat Completions 是基于 `messages` 的同步或流式文本协议。影策默认把提示词包装成一条 `user` 消息;需要多轮上下文、工具调用或结构化输出时,通过模型扩展参数传入完整 OpenAI 字段。
|
||||
Chat Completions 是基于 `messages` 的同步或流式文本协议。宿主默认把提示词包装成一条 `user` 消息;需要多轮上下文、工具调用或结构化输出时,通过模型扩展参数传入完整 OpenAI 字段。
|
||||
|
||||
## 接口、鉴权与请求模式
|
||||
|
||||
@@ -12,7 +12,7 @@ Authorization: Bearer <API_KEY>
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
官方服务的 Base URL 通常以 `/v1` 结尾;在影策中应以渠道实际配置为准。同步请求返回单个 JSON;`stream: true` 时上游返回 SSE,影策文本任务流负责转发和组装事件。
|
||||
官方服务的 Base URL 通常以 `/v1` 结尾;在宿主中应以渠道实际配置为准。同步请求返回单个 JSON;`stream: true` 时上游返回 SSE,宿主文本任务流负责转发和组装事件。
|
||||
|
||||
## 模型与兼容边界
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Claude Messages API
|
||||
|
||||
Claude Messages 使用无状态 `messages` 请求生成内容。影策默认创建一条 `user` 消息、设置 `max_tokens: 4096`,并自动添加 `anthropic-version: 2023-06-01`。系统提示使用顶层 `system`,不能伪装成 `system` 角色消息。
|
||||
Claude Messages 使用无状态 `messages` 请求生成内容。宿主默认创建一条 `user` 消息、设置 `max_tokens: 4096`,并自动添加 `anthropic-version: 2023-06-01`。系统提示使用顶层 `system`,不能伪装成 `system` 角色消息。
|
||||
|
||||
## 接口、鉴权与版本头
|
||||
|
||||
@@ -13,7 +13,7 @@ anthropic-version: 2023-06-01
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
影策的通用渠道中转也可能以 Bearer 方式连接兼容网关;直连 Anthropic 时必须按官方 `x-api-key` 规则配置渠道。版本头由适配器固定添加,Beta 能力需要额外头部时当前插件不会自动猜测。
|
||||
宿主的通用渠道中转也可能以 Bearer 方式连接兼容网关;直连 Anthropic 时必须按官方 `x-api-key` 规则配置渠道。版本头由适配器固定添加,Beta 能力需要额外头部时当前插件不会自动猜测。
|
||||
|
||||
## 模型与兼容边界
|
||||
|
||||
@@ -23,7 +23,7 @@ Content-Type: application/json
|
||||
|
||||
{{PARAMETERS}}
|
||||
|
||||
`extra` 可透传 `max_tokens`、`system`、`messages`、`temperature`、`top_p`、`top_k`、`tools`、`tool_choice` 和 `stream`。`extra.messages` 替换默认消息数组。`max_tokens` 是必需的上游字段,未覆盖时影策发送 4096。
|
||||
`extra` 可透传 `max_tokens`、`system`、`messages`、`temperature`、`top_p`、`top_k`、`tools`、`tool_choice` 和 `stream`。`extra.messages` 替换默认消息数组。`max_tokens` 是必需的上游字段,未覆盖时宿主发送 4096。
|
||||
|
||||
## 请求示例
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ curl "{channel_base_url}/v1beta/models/YOUR_MODEL:generateContent" \
|
||||
|
||||
## 响应解析与安全
|
||||
|
||||
解析器遍历 `candidates[].content.parts[]`,识别 `inlineData` 或 `inline_data`,再生成 `data:<mime>;base64,...`。只有文本、finishReason 或安全反馈而没有内联图片时请求会失败。大图片不能进入 localStorage,应立即转存到影策资源存储。
|
||||
解析器遍历 `candidates[].content.parts[]`,识别 `inlineData` 或 `inline_data`,再生成 `data:<mime>;base64,...`。只有文本、finishReason 或安全反馈而没有内联图片时请求会失败。大图片不能进入 localStorage,应立即转存到宿主资源存储。
|
||||
|
||||
## 官方资料
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ curl "{channel_base_url}/v1beta/models/YOUR_VEO_MODEL:predictLongRunning" \
|
||||
|
||||
## Operation 轮询与结果
|
||||
|
||||
创建响应返回 operation `name`。影策会移除开头斜杠,并在缺少 `operations/` 前缀时自动补齐,然后请求 `/v1beta/operations/...`。
|
||||
创建响应返回 operation `name`。宿主会移除开头斜杠,并在缺少 `operations/` 前缀时自动补齐,然后请求 `/v1beta/operations/...`。
|
||||
|
||||
```json
|
||||
{"name":"operations/op_xxx","done":false}
|
||||
|
||||
@@ -49,7 +49,7 @@ curl "{channel_base_url}/v2/query/video_generation/task_xxx" \
|
||||
-H "Authorization: Bearer <MINIMAX_API_KEY>"
|
||||
```
|
||||
|
||||
当前 V2 官方成功响应在 `task.content.url` 返回视频地址,通用 parser 会先合并 `task`,再从 `content.url` 提取结果。官方仅允许查询最近 7 天任务,视频 URL 有时效,应立即转存。当前 adapter 尚未发送参考视频、参考音频、`callback_url` 或 `aigc_watermark`;虽然 V2 上游支持这些字段,影策不能宣称已支持。
|
||||
当前 V2 官方成功响应在 `task.content.url` 返回视频地址,通用 parser 会先合并 `task`,再从 `content.url` 提取结果。官方仅允许查询最近 7 天任务,视频 URL 有时效,应立即转存。当前 adapter 尚未发送参考视频、参考音频、`callback_url` 或 `aigc_watermark`;虽然 V2 上游支持这些字段,宿主不能宣称已支持。
|
||||
|
||||
## 官方资料
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# NewAPI 媒体任务协议
|
||||
|
||||
该插件把多模态参考素材统一包装为 `input.media[]`,把分辨率、比例、时长和水印放入 `parameters`,使用 `/v1/videos` 创建与查询异步任务。它是影策适配的渠道合同,不是某一家模型厂商的官方协议。
|
||||
该插件把多模态参考素材统一包装为 `input.media[]`,把分辨率、比例、时长和水印放入 `parameters`,使用 `/v1/videos` 创建与查询异步任务。它是宿主适配的渠道合同,不是某一家模型厂商的官方协议。
|
||||
|
||||
## 接口与鉴权
|
||||
|
||||
@@ -51,7 +51,7 @@ curl "{channel_base_url}/v1/videos" \
|
||||
|
||||
## 官方资料与边界
|
||||
|
||||
- NewAPI 项目与部署文档由具体运维方提供;本页以影策当前 adapter 的请求事实为准。
|
||||
- NewAPI 项目与部署文档由具体运维方提供;本页以宿主当前 adapter 的请求事实为准。
|
||||
- 上游模型官方文档只用于确认模型自身能力,不能替代 NewAPI 网关字段合同。
|
||||
|
||||
{{CONTRACT}}
|
||||
@@ -53,7 +53,7 @@ curl "{channel_base_url}/v1/video/generations/task_xxx" \
|
||||
-H "Authorization: Bearer <CHANNEL_API_KEY>"
|
||||
```
|
||||
|
||||
状态会归一为等待、处理中、成功或失败。成功结果可来自视频数组或常见顶层 URL;当前没有取消路径。任务失败后的退款、额度释放和结果保留期属于部署方账务合同,影策不会在没有接口证据时承诺。
|
||||
状态会归一为等待、处理中、成功或失败。成功结果可来自视频数组或常见顶层 URL;当前没有取消路径。任务失败后的退款、额度释放和结果保留期属于部署方账务合同,宿主不会在没有接口证据时承诺。
|
||||
|
||||
## 官方资料与边界
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# OpenAI Audio Speech
|
||||
|
||||
该插件调用 OpenAI 风格的同步文字转语音接口,把影策提示词映射为 `input`。当前只发送模型与文本,声音、格式、语速和其他 TTS 选项尚未纳入 adapter。
|
||||
该插件调用 OpenAI 风格的同步文字转语音接口,把宿主提示词映射为 `input`。当前只发送模型与文本,声音、格式、语速和其他 TTS 选项尚未纳入 adapter。
|
||||
|
||||
## 接口与鉴权
|
||||
|
||||
@@ -14,7 +14,7 @@ Content-Type: application/json
|
||||
|
||||
## 模型、声音与输出格式
|
||||
|
||||
模型、voice、格式、单次文本长度、流式能力和价格以 OpenAI 或兼容渠道实际文档为准。当前影策 metadata 没有声明参数表,这意味着只有 `model` 和 `prompt` 的内部映射稳定,不意味着上游没有必填 `voice`。若上游要求 voice,管理员必须先扩展 adapter,不能依赖未白名单的字段自动透传。
|
||||
模型、voice、格式、单次文本长度、流式能力和价格以 OpenAI 或兼容渠道实际文档为准。当前宿主 metadata 没有声明参数表,这意味着只有 `model` 和 `prompt` 的内部映射稳定,不意味着上游没有必填 `voice`。若上游要求 voice,管理员必须先扩展 adapter,不能依赖未白名单的字段自动透传。
|
||||
|
||||
## 参数与字段映射
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# OpenAI Images
|
||||
|
||||
OpenAI Images 插件实现 JSON 文生图请求,并解析 OpenAI Images 风格的 `data[]` 响应。上游官方还提供 multipart 图像编辑接口,但当前影策适配器的创建路径只构造 `/v1/images/generations`;详情中列出编辑接口是为了说明协议能力,不代表当前画布已发送编辑请求。
|
||||
OpenAI Images 插件实现 JSON 文生图请求,并解析 OpenAI Images 风格的 `data[]` 响应。上游官方还提供 multipart 图像编辑接口,但当前宿主适配器的创建路径只构造 `/v1/images/generations`;详情中列出编辑接口是为了说明协议能力,不代表当前画布已发送编辑请求。
|
||||
|
||||
## 接口与鉴权
|
||||
|
||||
@@ -63,7 +63,7 @@ curl "{channel_base_url}/v1/images/edits" \
|
||||
-F "prompt=保持人物一致,改成雨夜街道"
|
||||
```
|
||||
|
||||
该示例是上游协议参考;在影策中使用前必须补 multipart 构造、参考图数量与 MIME 校验、编辑响应测试。
|
||||
该示例是上游协议参考;在宿主中使用前必须补 multipart 构造、参考图数量与 MIME 校验、编辑响应测试。
|
||||
|
||||
## 官方资料
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# OpenAI Responses API
|
||||
|
||||
Responses API 是 OpenAI 当前统一的文本与工具调用接口,输入使用 `input`,可同时承载简单字符串、结构化消息和工具回合。影策默认发送字符串提示词,并从同步响应的 `output_text` 或 `output[]` 中提取文本。
|
||||
Responses API 是 OpenAI 当前统一的文本与工具调用接口,输入使用 `input`,可同时承载简单字符串、结构化消息和工具回合。宿主默认发送字符串提示词,并从同步响应的 `output_text` 或 `output[]` 中提取文本。
|
||||
|
||||
## 接口、鉴权与请求模式
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
## 模型与 req_key
|
||||
|
||||
影策模型 ID 映射为 `req_key`,必须与已开通的即梦能力完全一致。插件不提供可能过期的 `req_key` 白名单,也不根据名字推断文生图、图生图或版本能力。
|
||||
宿主模型 ID 映射为 `req_key`,必须与已开通的即梦能力完全一致。插件不提供可能过期的 `req_key` 白名单,也不根据名字推断文生图、图生图或版本能力。
|
||||
|
||||
## 参数与字段映射
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ curl "{channel_base_url}/v1/videos/generations" \
|
||||
|
||||
## 创建、查询与下载
|
||||
|
||||
创建响应需包含 `request_id` 或其他统一解析器支持的任务字段。查询完成后从视频数组或 `video_url/result_url/url` 读取媒体。当前没有 cancel adapter;关闭影策弹窗不会取消上游生成。结果 URL 应及时转存,不能假定永久有效。
|
||||
创建响应需包含 `request_id` 或其他统一解析器支持的任务字段。查询完成后从视频数组或 `video_url/result_url/url` 读取媒体。当前没有 cancel adapter;关闭宿主弹窗不会取消上游生成。结果 URL 应及时转存,不能假定永久有效。
|
||||
|
||||
## 错误处理
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ func renderBuiltinDocumentation(info Metadata, document string) string {
|
||||
|
||||
func renderOperations(info Metadata) string {
|
||||
var b strings.Builder
|
||||
b.WriteString("| 阶段 | 方法与相对路径 | 请求类型 | 影策行为 |\n| --- | --- | --- | --- |\n")
|
||||
b.WriteString("| 阶段 | 方法与相对路径 | 请求类型 | 宿主行为 |\n| --- | --- | --- | --- |\n")
|
||||
writeOperation(&b, "创建", info.Create, firstNonEmpty(info.ContentType, "application/json"), "提交请求;同步协议直接解析结果,异步协议读取任务 ID")
|
||||
if strings.TrimSpace(info.Poll) != "" {
|
||||
writeOperation(&b, "轮询", info.Poll, "application/json", "查询状态,成功后提取媒体地址")
|
||||
@@ -53,10 +53,10 @@ func renderOperations(info Metadata) string {
|
||||
|
||||
func renderParameters(parameters []Parameter) string {
|
||||
if len(parameters) == 0 {
|
||||
return "> 当前适配器没有声明可配置参数;这不表示上游没有参数,只表示影策尚未建立稳定映射。"
|
||||
return "> 当前适配器没有声明可配置参数;这不表示上游没有参数,只表示宿主尚未建立稳定映射。"
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("| 影策字段 | 类型 | 必填 | 实际上游映射 | 说明 |\n| --- | --- | --- | --- | --- |\n")
|
||||
b.WriteString("| 宿主字段 | 类型 | 必填 | 实际上游映射 | 说明 |\n| --- | --- | --- | --- | --- |\n")
|
||||
for _, parameter := range parameters {
|
||||
description := strings.TrimSpace(parameter.Description)
|
||||
if len(parameter.Values) > 0 {
|
||||
@@ -69,17 +69,17 @@ func renderParameters(parameters []Parameter) string {
|
||||
|
||||
func renderRuntimeContract(info Metadata) string {
|
||||
var b strings.Builder
|
||||
b.WriteString("## 影策运行时合同\n\n")
|
||||
b.WriteString("## 宿主运行时合同\n\n")
|
||||
b.WriteString("- Base URL 只填写协议服务根地址,表中的相对路径由适配器拼接;不要把同一路径重复写进 Base URL。\n")
|
||||
b.WriteString("- 密钥由后端渠道中转读取,插件详情和浏览器请求不保存密钥。Bearer、供应商签名或专用版本头以本文鉴权章节为准。\n")
|
||||
b.WriteString("- 模型名来自渠道模型配置并原样发送。此插件不暗改模型名,也不根据名称猜测价格、额度或能力。\n")
|
||||
b.WriteString("- HTTP 非 2xx、非 JSON 响应、缺少任务 ID、成功状态却没有可识别结果都会作为真实错误向上返回。\n")
|
||||
if strings.TrimSpace(info.Poll) != "" {
|
||||
b.WriteString("- 异步状态统一为:`queued/pending/created/submitted` -> 等待,`running/processing/in_progress` -> 处理中,`succeeded/completed/done` -> 成功,`failed/error/expired/cancelled` -> 失败。\n")
|
||||
b.WriteString("- 轮询频率应遵守上游速率限制;媒体 URL 通常有有效期,成功后应立即进入影策资源保存流程。\n")
|
||||
b.WriteString("- 轮询频率应遵守上游速率限制;媒体 URL 通常有有效期,成功后应立即进入宿主资源保存流程。\n")
|
||||
}
|
||||
b.WriteString("- 参考素材只接受上游可访问的 HTTP(S) URL 或带 MIME 前缀的 data URL;裸 Base64、登录后才能访问的链接和 Cookie 保护地址不可用。\n")
|
||||
b.WriteString("- 插件只保证下方“当前实现”明确列出的字段。上游新增能力不会自动获得影策支持,必须补适配、解析和测试。\n")
|
||||
b.WriteString("- 插件只保证下方“当前实现”明确列出的字段。上游新增能力不会自动获得宿主支持,必须补适配、解析和测试。\n")
|
||||
return strings.TrimSpace(b.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
appearanceSchemaVersion = 3
|
||||
appearanceSchemaVersion = 6
|
||||
appearanceLogoMaxBytes int64 = 5 << 20
|
||||
appearancePosterMaxBytes int64 = 10 << 20
|
||||
appearanceVideoMaxBytes int64 = 256 << 20
|
||||
@@ -46,38 +46,52 @@ const (
|
||||
)
|
||||
|
||||
type AppearanceSetting struct {
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BrandName string `json:"brandName"`
|
||||
BrandSlug string `json:"brandSlug"`
|
||||
AuthHeroTitle string `json:"authHeroTitle"`
|
||||
AuthHeroDescription string `json:"authHeroDescription"`
|
||||
LogoResourceID string `json:"logoResourceId"`
|
||||
DarkLogoResourceID string `json:"darkLogoResourceId"`
|
||||
LogoFrameEnabled bool `json:"logoFrameEnabled"`
|
||||
AuthVideoResourceID string `json:"authVideoResourceId"`
|
||||
AuthVideoPosterResourceID string `json:"authVideoPosterResourceId"`
|
||||
SkinID string `json:"skinId"`
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BrandName string `json:"brandName"`
|
||||
BrandSlug string `json:"brandSlug"`
|
||||
AuthHeroTitle string `json:"authHeroTitle"`
|
||||
AuthHeroDescription string `json:"authHeroDescription"`
|
||||
LogoResourceID string `json:"logoResourceId"`
|
||||
DarkLogoResourceID string `json:"darkLogoResourceId"`
|
||||
LogoFrameEnabled bool `json:"logoFrameEnabled"`
|
||||
AuthVideoResourceID string `json:"authVideoResourceId"`
|
||||
AuthVideoPosterResourceID string `json:"authVideoPosterResourceId"`
|
||||
SkinID string `json:"skinId"`
|
||||
SkinThemes []AppearanceSkinTheme `json:"skinThemes"`
|
||||
SEOTitle string `json:"seoTitle"`
|
||||
SEODescription string `json:"seoDescription"`
|
||||
SEOKeywords string `json:"seoKeywords"`
|
||||
FooterCopyright string `json:"footerCopyright"`
|
||||
ICPFilingEnabled bool `json:"icpFilingEnabled"`
|
||||
ICPFilingNumber string `json:"icpFilingNumber"`
|
||||
}
|
||||
|
||||
type PublicAppearanceSetting struct {
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BrandName string `json:"brandName"`
|
||||
BrandSlug string `json:"brandSlug"`
|
||||
AuthHeroTitle string `json:"authHeroTitle"`
|
||||
AuthHeroDescription string `json:"authHeroDescription"`
|
||||
LogoURL string `json:"logoUrl"`
|
||||
DarkLogoURL string `json:"darkLogoUrl"`
|
||||
LogoFrameEnabled bool `json:"logoFrameEnabled"`
|
||||
AuthVideoURL string `json:"authVideoUrl"`
|
||||
AuthVideoPosterURL string `json:"authVideoPosterUrl"`
|
||||
SkinID string `json:"skinId"`
|
||||
LogoConfigured bool `json:"logoConfigured"`
|
||||
DarkLogoConfigured bool `json:"darkLogoConfigured"`
|
||||
AuthVideoConfigured bool `json:"authVideoConfigured"`
|
||||
AuthVideoPosterConfigured bool `json:"authVideoPosterConfigured"`
|
||||
Configured bool `json:"configured"`
|
||||
Revision string `json:"revision"`
|
||||
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BrandName string `json:"brandName"`
|
||||
BrandSlug string `json:"brandSlug"`
|
||||
AuthHeroTitle string `json:"authHeroTitle"`
|
||||
AuthHeroDescription string `json:"authHeroDescription"`
|
||||
LogoURL string `json:"logoUrl"`
|
||||
DarkLogoURL string `json:"darkLogoUrl"`
|
||||
LogoFrameEnabled bool `json:"logoFrameEnabled"`
|
||||
AuthVideoURL string `json:"authVideoUrl"`
|
||||
AuthVideoPosterURL string `json:"authVideoPosterUrl"`
|
||||
SkinID string `json:"skinId"`
|
||||
ActiveSkin AppearanceSkinTheme `json:"activeSkin"`
|
||||
SEOTitle string `json:"seoTitle"`
|
||||
SEODescription string `json:"seoDescription"`
|
||||
SEOKeywords string `json:"seoKeywords"`
|
||||
FooterCopyright string `json:"footerCopyright"`
|
||||
ICPFilingEnabled bool `json:"icpFilingEnabled"`
|
||||
ICPFilingNumber string `json:"icpFilingNumber"`
|
||||
LogoConfigured bool `json:"logoConfigured"`
|
||||
DarkLogoConfigured bool `json:"darkLogoConfigured"`
|
||||
AuthVideoConfigured bool `json:"authVideoConfigured"`
|
||||
AuthVideoPosterConfigured bool `json:"authVideoPosterConfigured"`
|
||||
Configured bool `json:"configured"`
|
||||
Revision string `json:"revision"`
|
||||
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
||||
}
|
||||
|
||||
type AdminAppearanceSetting struct {
|
||||
@@ -97,6 +111,7 @@ func defaultAppearanceSetting() AppearanceSetting {
|
||||
AuthHeroTitle: defaultAppearanceHeroTitle,
|
||||
LogoFrameEnabled: true,
|
||||
SkinID: defaultAppearanceSkinID,
|
||||
SkinThemes: defaultAppearanceSkinThemes(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +171,15 @@ func (s *Service) UpdateAppearance(actor *model.User, value AppearanceSetting) (
|
||||
value.AuthVideoResourceID = strings.TrimSpace(value.AuthVideoResourceID)
|
||||
value.AuthVideoPosterResourceID = strings.TrimSpace(value.AuthVideoPosterResourceID)
|
||||
value.SkinID = strings.TrimSpace(value.SkinID)
|
||||
if len(value.SkinThemes) == 0 {
|
||||
value.SkinThemes = defaultAppearanceSkinThemes()
|
||||
}
|
||||
value.SkinThemes = normalizeAppearanceSkinThemes(value.SkinThemes)
|
||||
value.SEOTitle = normalizeAppearanceSingleLine(value.SEOTitle)
|
||||
value.SEODescription = normalizeAppearanceCopy(value.SEODescription)
|
||||
value.SEOKeywords = normalizeAppearanceSingleLine(value.SEOKeywords)
|
||||
value.FooterCopyright = normalizeAppearanceSingleLine(value.FooterCopyright)
|
||||
value.ICPFilingNumber = normalizeAppearanceSingleLine(value.ICPFilingNumber)
|
||||
if err := validateAppearanceSetting(value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -328,6 +352,15 @@ func (s *Service) readAppearance() (*model.SystemSetting, AppearanceSetting, err
|
||||
if value.SkinID == "" {
|
||||
value.SkinID = defaultAppearanceSkinID
|
||||
}
|
||||
if len(value.SkinThemes) == 0 {
|
||||
value.SkinThemes = defaultAppearanceSkinThemes()
|
||||
}
|
||||
value.SkinThemes = normalizeAppearanceSkinThemes(value.SkinThemes)
|
||||
value.SEOTitle = normalizeAppearanceSingleLine(value.SEOTitle)
|
||||
value.SEODescription = normalizeAppearanceCopy(value.SEODescription)
|
||||
value.SEOKeywords = normalizeAppearanceSingleLine(value.SEOKeywords)
|
||||
value.FooterCopyright = normalizeAppearanceSingleLine(value.FooterCopyright)
|
||||
value.ICPFilingNumber = normalizeAppearanceSingleLine(value.ICPFilingNumber)
|
||||
return setting, value, nil
|
||||
}
|
||||
|
||||
@@ -349,8 +382,26 @@ func validateAppearanceSetting(value AppearanceSetting) error {
|
||||
if err := validateAppearanceCopy(value.AuthHeroDescription, "登录页说明文案", 160, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if value.SkinID != defaultAppearanceSkinID {
|
||||
return BadAuthRequest("当前版本仅支持经典皮肤")
|
||||
if err := validateAppearanceSkinThemes(value.SkinThemes, value.SkinID); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, field := range []struct {
|
||||
value string
|
||||
label string
|
||||
max int
|
||||
}{
|
||||
{value.SEOTitle, "SEO 标题", 70},
|
||||
{value.SEODescription, "SEO 描述", 200},
|
||||
{value.SEOKeywords, "SEO 关键词", 300},
|
||||
{value.FooterCopyright, "版权信息", 160},
|
||||
{value.ICPFilingNumber, "备案号", 64},
|
||||
} {
|
||||
if err := validateAppearanceCopy(field.value, field.label, field.max, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if value.ICPFilingEnabled && value.ICPFilingNumber == "" {
|
||||
return BadAuthRequest("显示备案号前请先填写备案号")
|
||||
}
|
||||
for _, resourceID := range []string{value.LogoResourceID, value.DarkLogoResourceID, value.AuthVideoResourceID, value.AuthVideoPosterResourceID} {
|
||||
if len(resourceID) > 80 {
|
||||
@@ -364,6 +415,10 @@ func normalizeAppearanceCopy(value string) string {
|
||||
return strings.TrimSpace(strings.ReplaceAll(strings.ReplaceAll(value, "\r\n", "\n"), "\r", "\n"))
|
||||
}
|
||||
|
||||
func normalizeAppearanceSingleLine(value string) string {
|
||||
return strings.TrimSpace(strings.ReplaceAll(strings.ReplaceAll(value, "\r\n", " "), "\r", " "))
|
||||
}
|
||||
|
||||
func validAppearanceBrandSlug(value string) bool {
|
||||
if len(value) == 0 || len(value) > 48 || value[0] == '-' || value[len(value)-1] == '-' {
|
||||
return false
|
||||
@@ -517,6 +572,13 @@ func publicAppearanceSetting(setting *model.SystemSetting, value AppearanceSetti
|
||||
AuthVideoURL: defaultAppearanceVideoURL,
|
||||
AuthVideoPosterURL: defaultAppearancePosterURL,
|
||||
SkinID: value.SkinID,
|
||||
ActiveSkin: activeAppearanceSkin(value.SkinThemes, value.SkinID),
|
||||
SEOTitle: effectiveAppearanceSEOTitle(value),
|
||||
SEODescription: effectiveAppearanceSEODescription(value),
|
||||
SEOKeywords: value.SEOKeywords,
|
||||
FooterCopyright: effectiveAppearanceCopyright(value),
|
||||
ICPFilingEnabled: value.ICPFilingEnabled && value.ICPFilingNumber != "",
|
||||
ICPFilingNumber: value.ICPFilingNumber,
|
||||
Configured: setting != nil,
|
||||
Revision: revision,
|
||||
}
|
||||
@@ -556,6 +618,40 @@ func publicAppearanceSetting(setting *model.SystemSetting, value AppearanceSetti
|
||||
return result
|
||||
}
|
||||
|
||||
func effectiveAppearanceSEOTitle(value AppearanceSetting) string {
|
||||
if value.SEOTitle != "" {
|
||||
return value.SEOTitle
|
||||
}
|
||||
return value.BrandName
|
||||
}
|
||||
|
||||
func effectiveAppearanceSEODescription(value AppearanceSetting) string {
|
||||
if value.SEODescription != "" {
|
||||
return value.SEODescription
|
||||
}
|
||||
return value.BrandName + ",面向 AI 影视与短剧创作的工作台。"
|
||||
}
|
||||
|
||||
func effectiveAppearanceCopyright(value AppearanceSetting) string {
|
||||
if value.FooterCopyright != "" {
|
||||
return value.FooterCopyright
|
||||
}
|
||||
return fmt.Sprintf("© %d %s. All rights reserved.", time.Now().Year(), value.BrandName)
|
||||
}
|
||||
|
||||
func (s *Service) appearanceBrandName() string {
|
||||
brandName, _ := s.appearanceIdentity()
|
||||
return brandName
|
||||
}
|
||||
|
||||
func (s *Service) appearanceIdentity() (string, string) {
|
||||
_, value, err := s.readAppearance()
|
||||
if err != nil || strings.TrimSpace(value.BrandName) == "" {
|
||||
return defaultAppearanceBrandName, defaultAppearanceBrandSlug
|
||||
}
|
||||
return value.BrandName, value.BrandSlug
|
||||
}
|
||||
|
||||
func appearanceAssetURL(slot string, revision string) string {
|
||||
return "/api/public/appearance/assets/" + url.PathEscape(slot) + "?v=" + url.QueryEscape(revision)
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const maxAppearanceSkinThemes = 16
|
||||
|
||||
var (
|
||||
appearanceSkinIDPattern = regexp.MustCompile(`^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$`)
|
||||
appearanceColorPattern = regexp.MustCompile(`^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$`)
|
||||
)
|
||||
|
||||
// AppearanceSkinModeTokens is deliberately an allowlist instead of arbitrary CSS.
|
||||
// Every value is validated as a six- or eight-digit hex color before it is exposed
|
||||
// by the public appearance endpoint.
|
||||
type AppearanceSkinModeTokens struct {
|
||||
Canvas string `json:"canvas"`
|
||||
Surface string `json:"surface"`
|
||||
SurfaceSubtle string `json:"surfaceSubtle"`
|
||||
SurfaceRaised string `json:"surfaceRaised"`
|
||||
Overlay string `json:"overlay"`
|
||||
Text string `json:"text"`
|
||||
TextMuted string `json:"textMuted"`
|
||||
Border string `json:"border"`
|
||||
Control string `json:"control"`
|
||||
ControlHover string `json:"controlHover"`
|
||||
ControlActive string `json:"controlActive"`
|
||||
ControlBorder string `json:"controlBorder"`
|
||||
ControlFocus string `json:"controlFocus"`
|
||||
ControlDisabledBackground string `json:"controlDisabledBackground"`
|
||||
ControlDisabledForeground string `json:"controlDisabledForeground"`
|
||||
SwitchChecked string `json:"switchChecked"`
|
||||
SwitchCheckedHover string `json:"switchCheckedHover"`
|
||||
SwitchCheckedHandle string `json:"switchCheckedHandle"`
|
||||
SwitchUnchecked string `json:"switchUnchecked"`
|
||||
SwitchUncheckedHover string `json:"switchUncheckedHover"`
|
||||
SwitchUncheckedHandle string `json:"switchUncheckedHandle"`
|
||||
Primary string `json:"primary"`
|
||||
PrimaryHover string `json:"primaryHover"`
|
||||
PrimaryActive string `json:"primaryActive"`
|
||||
PrimaryForeground string `json:"primaryForeground"`
|
||||
Selected string `json:"selected"`
|
||||
SelectedHover string `json:"selectedHover"`
|
||||
SelectedActive string `json:"selectedActive"`
|
||||
SelectedForeground string `json:"selectedForeground"`
|
||||
Icon string `json:"icon"`
|
||||
IconMuted string `json:"iconMuted"`
|
||||
IconActive string `json:"iconActive"`
|
||||
Success string `json:"success"`
|
||||
Warning string `json:"warning"`
|
||||
Danger string `json:"danger"`
|
||||
DangerHover string `json:"dangerHover"`
|
||||
DangerActive string `json:"dangerActive"`
|
||||
DangerForeground string `json:"dangerForeground"`
|
||||
Info string `json:"info"`
|
||||
Workspace string `json:"workspace"`
|
||||
WorkspaceGrid string `json:"workspaceGrid"`
|
||||
AdminBackground string `json:"adminBackground"`
|
||||
AdminSurface string `json:"adminSurface"`
|
||||
AdminSubtle string `json:"adminSubtle"`
|
||||
AdminStrong string `json:"adminStrong"`
|
||||
AuthBackground string `json:"authBackground"`
|
||||
AuthPanel string `json:"authPanel"`
|
||||
AuthCard string `json:"authCard"`
|
||||
AuthAccent string `json:"authAccent"`
|
||||
AuthMuted string `json:"authMuted"`
|
||||
}
|
||||
|
||||
type AppearanceSkinComponentTokens struct {
|
||||
ButtonRadius int `json:"buttonRadius"`
|
||||
InputRadius int `json:"inputRadius"`
|
||||
CardRadius int `json:"cardRadius"`
|
||||
OverlayRadius int `json:"overlayRadius"`
|
||||
MenuRadius int `json:"menuRadius"`
|
||||
CheckboxRadius int `json:"checkboxRadius"`
|
||||
ControlHeight int `json:"controlHeight"`
|
||||
ControlHeightSmall int `json:"controlHeightSmall"`
|
||||
ControlHeightLarge int `json:"controlHeightLarge"`
|
||||
BorderWidth int `json:"borderWidth"`
|
||||
FocusRingWidth int `json:"focusRingWidth"`
|
||||
IconSize int `json:"iconSize"`
|
||||
ButtonFontWeight int `json:"buttonFontWeight"`
|
||||
HoverLift int `json:"hoverLift"`
|
||||
MotionFast int `json:"motionFast"`
|
||||
MotionNormal int `json:"motionNormal"`
|
||||
ShadowStyle string `json:"shadowStyle"`
|
||||
}
|
||||
|
||||
type AppearanceSkinTokens struct {
|
||||
Light AppearanceSkinModeTokens `json:"light"`
|
||||
Dark AppearanceSkinModeTokens `json:"dark"`
|
||||
Components AppearanceSkinComponentTokens `json:"components"`
|
||||
}
|
||||
|
||||
type AppearanceSkinTheme struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Locked bool `json:"locked"`
|
||||
Tokens AppearanceSkinTokens `json:"tokens"`
|
||||
}
|
||||
|
||||
func defaultAppearanceSkinThemes() []AppearanceSkinTheme {
|
||||
classic := defaultClassicAppearanceSkin()
|
||||
studio := cloneAppearanceSkin(classic, "studio-indigo", "青瓷工作室", "雾白青瓷 · 珊瑚点睛")
|
||||
studio.Tokens.Light = tintAppearanceSkinMode(studio.Tokens.Light, appearanceSkinPalette{
|
||||
canvas: "#f6f8f9", surface: "#ffffff", subtle: "#edf4f3", raised: "#d7e8e5", overlay: "#ffffff", text: "#142026", muted: "#607079", border: "#d5e0e2",
|
||||
primary: "#087f76", primaryHover: "#076d66", primaryActive: "#095c57", primaryForeground: "#ffffff", selected: "#dff4f0", selectedHover: "#ccebe6", selectedActive: "#b9e3dd", selectedForeground: "#075f59", info: "#dd7a38",
|
||||
switchChecked: "#087f76", switchCheckedHover: "#076d66", switchCheckedHandle: "#ffffff", switchUnchecked: "#a8b7b9", switchUncheckedHover: "#899b9e", switchUncheckedHandle: "#ffffff",
|
||||
success: "#16866f", warning: "#c46722", danger: "#c83f3a", dangerHover: "#ad3532", dangerActive: "#922e2c", dangerForeground: "#ffffff",
|
||||
workspace: "#ffffff", grid: "#e8f2f0", adminBackground: "#eef3f4", adminSurface: "#ffffff", adminSubtle: "#f5f9f9", adminStrong: "#dce9e8", authBackground: "#071a1d", authPanel: "#0b2226", authCard: "#0d272b", authAccent: "#72eadc", authMuted: "#8db9b4",
|
||||
})
|
||||
studio.Tokens.Dark = tintAppearanceSkinMode(studio.Tokens.Dark, appearanceSkinPalette{
|
||||
canvas: "#0b1215", surface: "#121d21", subtle: "#142428", raised: "#203a3b", overlay: "#172328", text: "#e7f4f2", muted: "#8ca6a7", border: "#294044",
|
||||
primary: "#43d8c7", primaryHover: "#72eadc", primaryActive: "#2db9aa", primaryForeground: "#052724", selected: "#193735", selectedHover: "#214743", selectedActive: "#28554f", selectedForeground: "#baf5ee", info: "#ff9e57",
|
||||
switchChecked: "#31bfae", switchCheckedHover: "#43d8c7", switchCheckedHandle: "#052724", switchUnchecked: "#3f5559", switchUncheckedHover: "#526a6d", switchUncheckedHandle: "#e7f4f2",
|
||||
success: "#4ade80", warning: "#ffb454", danger: "#ff7875", dangerHover: "#ff9a98", dangerActive: "#df5e5b", dangerForeground: "#2d0808",
|
||||
workspace: "#111d21", grid: "#17292c", adminBackground: "#0c171a", adminSurface: "#132126", adminSubtle: "#192a2e", adminStrong: "#21383a", authBackground: "#061416", authPanel: "#091c20", authCard: "#0d272b", authAccent: "#72eadc", authMuted: "#8db9b4",
|
||||
})
|
||||
studio.Tokens.Components = appearanceSkinComponentPreset(8, 8, 14, 14, 10, 5)
|
||||
|
||||
warm := cloneAppearanceSkin(classic, "warm-persimmon", "暖柿纸境", "米纸暖棕 · 柿橙强调")
|
||||
warm.Tokens.Light = tintAppearanceSkinMode(warm.Tokens.Light, appearanceSkinPalette{
|
||||
canvas: "#fbf7f2", surface: "#fffdf9", subtle: "#f6ebe3", raised: "#ead2c2", overlay: "#fffdf9", text: "#35261f", muted: "#806b61", border: "#e5d6cb",
|
||||
primary: "#b94f2f", primaryHover: "#9e4128", primaryActive: "#843621", primaryForeground: "#fffaf6", selected: "#f8e0cf", selectedHover: "#f1d1bb", selectedActive: "#e9c1a6", selectedForeground: "#8c3d25", info: "#c58a3b",
|
||||
switchChecked: "#a84a2f", switchCheckedHover: "#bd5b3c", switchCheckedHandle: "#fffaf6", switchUnchecked: "#c7b3a7", switchUncheckedHover: "#aa9182", switchUncheckedHandle: "#fffdf9",
|
||||
success: "#4d7f50", warning: "#bd6819", danger: "#bd3d32", dangerHover: "#a33229", dangerActive: "#892a23", dangerForeground: "#fffaf6",
|
||||
workspace: "#fffdf9", grid: "#f3e9e1", adminBackground: "#f6eee7", adminSurface: "#fffdf9", adminSubtle: "#faf3ed", adminStrong: "#ead8ca", authBackground: "#1f1410", authPanel: "#291813", authCard: "#361f17", authAccent: "#ffc08b", authMuted: "#b99d89",
|
||||
})
|
||||
warm.Tokens.Dark = tintAppearanceSkinMode(warm.Tokens.Dark, appearanceSkinPalette{
|
||||
canvas: "#1b1210", surface: "#291a16", subtle: "#33211b", raised: "#493027", overlay: "#31201a", text: "#f8e9df", muted: "#b89c8c", border: "#50372e",
|
||||
primary: "#ef8a61", primaryHover: "#ffab83", primaryActive: "#d87350", primaryForeground: "#37140a", selected: "#4b2a20", selectedHover: "#5b3427", selectedActive: "#6b3e2e", selectedForeground: "#ffd9c4", info: "#f0b36c",
|
||||
switchChecked: "#df7752", switchCheckedHover: "#ef8a61", switchCheckedHandle: "#37140a", switchUnchecked: "#65483d", switchUncheckedHover: "#7b5a4c", switchUncheckedHandle: "#f8e9df",
|
||||
success: "#8dcc72", warning: "#f2b35f", danger: "#ff8375", dangerHover: "#ffa094", dangerActive: "#df6a5e", dangerForeground: "#32100b",
|
||||
workspace: "#241714", grid: "#31201b", adminBackground: "#1c1210", adminSurface: "#291b17", adminSubtle: "#35231d", adminStrong: "#493027", authBackground: "#160d0a", authPanel: "#21120e", authCard: "#361f17", authAccent: "#ffc08b", authMuted: "#b99d89",
|
||||
})
|
||||
warm.Tokens.Components = appearanceSkinComponentPreset(10, 10, 16, 18, 12, 5)
|
||||
|
||||
violet := cloneAppearanceSkin(classic, "brand-violet", "霓光紫境", "冷白雾紫 · 夜幕电光")
|
||||
violet.Tokens.Light = tintAppearanceSkinMode(violet.Tokens.Light, appearanceSkinPalette{
|
||||
canvas: "#f8f7fc", surface: "#ffffff", subtle: "#f0eefb", raised: "#dfd9f5", overlay: "#ffffff", text: "#211b35", muted: "#716a86", border: "#ddd8ec",
|
||||
primary: "#6656d9", primaryHover: "#5847c7", primaryActive: "#4939b2", primaryForeground: "#ffffff", selected: "#ebe8ff", selectedHover: "#ded9ff", selectedActive: "#d0c9ff", selectedForeground: "#4f3fb5", info: "#8f61e8",
|
||||
switchChecked: "#6656d9", switchCheckedHover: "#5847c7", switchCheckedHandle: "#ffffff", switchUnchecked: "#b4afc5", switchUncheckedHover: "#9891ae", switchUncheckedHandle: "#ffffff",
|
||||
success: "#2f966e", warning: "#b96f16", danger: "#c73559", dangerHover: "#ac2c4b", dangerActive: "#912640", dangerForeground: "#ffffff",
|
||||
workspace: "#ffffff", grid: "#f0eef8", adminBackground: "#f1f0f7", adminSurface: "#ffffff", adminSubtle: "#f7f6fb", adminStrong: "#e4e0f1", authBackground: "#110d20", authPanel: "#17112b", authCard: "#211936", authAccent: "#b4a8ff", authMuted: "#958dad",
|
||||
})
|
||||
violet.Tokens.Dark = tintAppearanceSkinMode(violet.Tokens.Dark, appearanceSkinPalette{
|
||||
canvas: "#0f0c19", surface: "#171321", subtle: "#201a2f", raised: "#302746", overlay: "#1c1734", text: "#f2efff", muted: "#a9a2bd", border: "#39304d",
|
||||
primary: "#9a90ff", primaryHover: "#b5adff", primaryActive: "#8175ed", primaryForeground: "#171126", selected: "#292347", selectedHover: "#352d59", selectedActive: "#40366a", selectedForeground: "#ddd9ff", info: "#c45dff",
|
||||
switchChecked: "#8175ed", switchCheckedHover: "#9a90ff", switchCheckedHandle: "#171126", switchUnchecked: "#504967", switchUncheckedHover: "#665d7f", switchUncheckedHandle: "#f2efff",
|
||||
success: "#5bd6a2", warning: "#ffc46b", danger: "#ff7795", dangerHover: "#ff99ae", dangerActive: "#df607f", dangerForeground: "#310b17",
|
||||
workspace: "#15111f", grid: "#211b30", adminBackground: "#110e1a", adminSurface: "#191524", adminSubtle: "#211b30", adminStrong: "#302746", authBackground: "#0b0812", authPanel: "#120d20", authCard: "#211936", authAccent: "#b4a8ff", authMuted: "#958dad",
|
||||
})
|
||||
violet.Tokens.Components = appearanceSkinComponentPreset(7, 7, 12, 14, 9, 4)
|
||||
|
||||
return []AppearanceSkinTheme{classic, studio, warm, violet}
|
||||
}
|
||||
|
||||
func defaultClassicAppearanceSkin() AppearanceSkinTheme {
|
||||
return AppearanceSkinTheme{
|
||||
ID: "classic", Name: "经典黑白", Description: "项目原始样式 · 不可修改", Locked: true,
|
||||
Tokens: AppearanceSkinTokens{
|
||||
Light: AppearanceSkinModeTokens{
|
||||
Canvas: "#ffffff", Surface: "#ffffff", SurfaceSubtle: "#f7f7f7", SurfaceRaised: "#ececec", Overlay: "#ffffff", Text: "#171717", TextMuted: "#737373", Border: "#e5e5e5",
|
||||
Control: "#ffffff", ControlHover: "#f5f5f5", ControlActive: "#ececec", ControlBorder: "#d1d1d1", ControlFocus: "#171717", ControlDisabledBackground: "#f2f2f2", ControlDisabledForeground: "#a3a3a3", SwitchChecked: "#16a34a", SwitchCheckedHover: "#15803d", SwitchCheckedHandle: "#ffffff", SwitchUnchecked: "#b8b8b8", SwitchUncheckedHover: "#9f9f9f", SwitchUncheckedHandle: "#ffffff",
|
||||
Primary: "#171717", PrimaryHover: "#303030", PrimaryActive: "#404040", PrimaryForeground: "#ffffff", Selected: "#e8e8e8", SelectedHover: "#dedede", SelectedActive: "#d5d5d5", SelectedForeground: "#171717",
|
||||
Icon: "#3f3f46", IconMuted: "#a1a1aa", IconActive: "#171717", Success: "#16a34a", Warning: "#d97706", Danger: "#dc2626", DangerHover: "#b91c1c", DangerActive: "#991b1b", DangerForeground: "#ffffff", Info: "#2563eb", Workspace: "#ffffff", WorkspaceGrid: "#f3f3f3",
|
||||
AdminBackground: "#f3f4f6", AdminSurface: "#ffffff", AdminSubtle: "#f7f8fa", AdminStrong: "#eceff3", AuthBackground: "#08090c", AuthPanel: "#0b0c10", AuthCard: "#121318", AuthAccent: "#93c5fd", AuthMuted: "#8a8b91",
|
||||
},
|
||||
Dark: AppearanceSkinModeTokens{
|
||||
Canvas: "#0a0a0a", Surface: "#181818", SurfaceSubtle: "#202020", SurfaceRaised: "#2a2a2a", Overlay: "#1f1f20", Text: "#f5f5f5", TextMuted: "#a3a3a3", Border: "#2d2d2d",
|
||||
Control: "#202020", ControlHover: "#292929", ControlActive: "#333333", ControlBorder: "#4a4a4a", ControlFocus: "#f5f5f5", ControlDisabledBackground: "#252525", ControlDisabledForeground: "#737373", SwitchChecked: "#22c55e", SwitchCheckedHover: "#4ade80", SwitchCheckedHandle: "#071a0f", SwitchUnchecked: "#525252", SwitchUncheckedHover: "#686868", SwitchUncheckedHandle: "#f5f5f5",
|
||||
Primary: "#f5f5f5", PrimaryHover: "#ffffff", PrimaryActive: "#e5e5e5", PrimaryForeground: "#171717", Selected: "#2b2b2b", SelectedHover: "#343434", SelectedActive: "#3d3d3d", SelectedForeground: "#f5f5f5",
|
||||
Icon: "#d4d4d8", IconMuted: "#71717a", IconActive: "#ffffff", Success: "#4ade80", Warning: "#fbbf24", Danger: "#f87171", DangerHover: "#fca5a5", DangerActive: "#ef4444", DangerForeground: "#2b0808", Info: "#60a5fa", Workspace: "#181818", WorkspaceGrid: "#222222",
|
||||
AdminBackground: "#101010", AdminSurface: "#181818", AdminSubtle: "#202020", AdminStrong: "#2a2a2a", AuthBackground: "#08090c", AuthPanel: "#0b0c10", AuthCard: "#121318", AuthAccent: "#93c5fd", AuthMuted: "#8a8b91",
|
||||
},
|
||||
Components: appearanceSkinComponentPreset(6, 6, 12, 12, 8, 4),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type appearanceSkinPalette struct {
|
||||
canvas, surface, subtle, raised, overlay, text, muted, border string
|
||||
primary, primaryHover, primaryActive, primaryForeground, selected, selectedHover, selectedActive, selectedForeground string
|
||||
switchChecked, switchCheckedHover, switchCheckedHandle, switchUnchecked, switchUncheckedHover, switchUncheckedHandle string
|
||||
success, warning, danger, dangerHover, dangerActive, dangerForeground, info string
|
||||
workspace, grid, adminBackground, adminSurface, adminSubtle, adminStrong string
|
||||
authBackground, authPanel, authCard, authAccent, authMuted string
|
||||
}
|
||||
|
||||
func tintAppearanceSkinMode(value AppearanceSkinModeTokens, palette appearanceSkinPalette) AppearanceSkinModeTokens {
|
||||
value.Canvas, value.Surface, value.SurfaceSubtle, value.SurfaceRaised, value.Overlay = palette.canvas, palette.surface, palette.subtle, palette.raised, palette.overlay
|
||||
value.Text, value.TextMuted, value.Border = palette.text, palette.muted, palette.border
|
||||
value.Control, value.ControlHover, value.ControlActive, value.ControlBorder, value.ControlFocus = palette.surface, palette.subtle, palette.raised, palette.border, palette.primary
|
||||
value.ControlDisabledBackground, value.ControlDisabledForeground = palette.subtle, palette.muted
|
||||
value.SwitchChecked, value.SwitchCheckedHover, value.SwitchCheckedHandle = palette.switchChecked, palette.switchCheckedHover, palette.switchCheckedHandle
|
||||
value.SwitchUnchecked, value.SwitchUncheckedHover, value.SwitchUncheckedHandle = palette.switchUnchecked, palette.switchUncheckedHover, palette.switchUncheckedHandle
|
||||
value.Primary, value.PrimaryHover, value.PrimaryActive, value.PrimaryForeground = palette.primary, palette.primaryHover, palette.primaryActive, palette.primaryForeground
|
||||
value.Selected, value.SelectedHover, value.SelectedActive, value.SelectedForeground = palette.selected, palette.selectedHover, palette.selectedActive, palette.selectedForeground
|
||||
value.Icon, value.IconMuted, value.IconActive = palette.text, palette.muted, palette.primary
|
||||
value.Success, value.Warning, value.Danger = palette.success, palette.warning, palette.danger
|
||||
value.DangerHover, value.DangerActive, value.DangerForeground = palette.dangerHover, palette.dangerActive, palette.dangerForeground
|
||||
value.Info, value.Workspace, value.WorkspaceGrid = palette.info, palette.workspace, palette.grid
|
||||
value.AdminBackground, value.AdminSurface, value.AdminSubtle, value.AdminStrong = palette.adminBackground, palette.adminSurface, palette.adminSubtle, palette.adminStrong
|
||||
value.AuthBackground, value.AuthPanel, value.AuthCard, value.AuthAccent, value.AuthMuted = palette.authBackground, palette.authPanel, palette.authCard, palette.authAccent, palette.authMuted
|
||||
return value
|
||||
}
|
||||
|
||||
func appearanceSkinComponentPreset(buttonRadius, inputRadius, cardRadius, overlayRadius, menuRadius, checkboxRadius int) AppearanceSkinComponentTokens {
|
||||
return AppearanceSkinComponentTokens{
|
||||
ButtonRadius: buttonRadius, InputRadius: inputRadius, CardRadius: cardRadius, OverlayRadius: overlayRadius, MenuRadius: menuRadius, CheckboxRadius: checkboxRadius,
|
||||
ControlHeight: 36, ControlHeightSmall: 30, ControlHeightLarge: 42, BorderWidth: 1, FocusRingWidth: 2, IconSize: 16, ButtonFontWeight: 500,
|
||||
HoverLift: 1, MotionFast: 120, MotionNormal: 180, ShadowStyle: "soft",
|
||||
}
|
||||
}
|
||||
|
||||
func cloneAppearanceSkin(source AppearanceSkinTheme, id, name, description string) AppearanceSkinTheme {
|
||||
source.ID, source.Name, source.Description, source.Locked = id, name, description, false
|
||||
return source
|
||||
}
|
||||
|
||||
func normalizeAppearanceSkinThemes(themes []AppearanceSkinTheme) []AppearanceSkinTheme {
|
||||
result := make([]AppearanceSkinTheme, len(themes))
|
||||
copy(result, themes)
|
||||
builtins := defaultAppearanceSkinThemes()
|
||||
for index := range result {
|
||||
result[index].ID = strings.ToLower(strings.TrimSpace(result[index].ID))
|
||||
result[index].Name = strings.TrimSpace(result[index].Name)
|
||||
result[index].Description = strings.TrimSpace(result[index].Description)
|
||||
result[index].Locked = result[index].ID == defaultAppearanceSkinID
|
||||
var fallback AppearanceSkinTokens
|
||||
for _, builtin := range builtins {
|
||||
if builtin.ID == result[index].ID {
|
||||
fallback = builtin.Tokens
|
||||
break
|
||||
}
|
||||
}
|
||||
backfillAppearanceSkinModeColors(&result[index].Tokens.Light, fallback.Light)
|
||||
backfillAppearanceSkinModeColors(&result[index].Tokens.Dark, fallback.Dark)
|
||||
normalizeAppearanceSkinModeColors(&result[index].Tokens.Light)
|
||||
normalizeAppearanceSkinModeColors(&result[index].Tokens.Dark)
|
||||
result[index].Tokens.Components.ShadowStyle = strings.ToLower(strings.TrimSpace(result[index].Tokens.Components.ShadowStyle))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func backfillAppearanceSkinModeColors(mode *AppearanceSkinModeTokens, fallback AppearanceSkinModeTokens) {
|
||||
for _, field := range []struct {
|
||||
value *string
|
||||
fallback string
|
||||
derived string
|
||||
}{
|
||||
{&mode.SwitchChecked, fallback.SwitchChecked, mode.Primary},
|
||||
{&mode.SwitchCheckedHover, fallback.SwitchCheckedHover, mode.PrimaryHover},
|
||||
{&mode.SwitchCheckedHandle, fallback.SwitchCheckedHandle, mode.PrimaryForeground},
|
||||
{&mode.SwitchUnchecked, fallback.SwitchUnchecked, mode.ControlBorder},
|
||||
{&mode.SwitchUncheckedHover, fallback.SwitchUncheckedHover, mode.ControlActive},
|
||||
{&mode.SwitchUncheckedHandle, fallback.SwitchUncheckedHandle, mode.SelectedForeground},
|
||||
{&mode.DangerHover, fallback.DangerHover, mode.Danger},
|
||||
{&mode.DangerActive, fallback.DangerActive, mode.Danger},
|
||||
{&mode.DangerForeground, fallback.DangerForeground, mode.PrimaryForeground},
|
||||
} {
|
||||
if strings.TrimSpace(*field.value) != "" {
|
||||
continue
|
||||
}
|
||||
if field.fallback != "" {
|
||||
*field.value = field.fallback
|
||||
} else {
|
||||
*field.value = field.derived
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeAppearanceSkinModeColors(mode *AppearanceSkinModeTokens) {
|
||||
value := reflect.ValueOf(mode).Elem()
|
||||
for index := 0; index < value.NumField(); index++ {
|
||||
field := value.Field(index)
|
||||
field.SetString(strings.ToLower(strings.TrimSpace(field.String())))
|
||||
}
|
||||
}
|
||||
|
||||
func validateAppearanceSkinThemes(themes []AppearanceSkinTheme, selectedID string) error {
|
||||
if len(themes) == 0 || len(themes) > maxAppearanceSkinThemes {
|
||||
return BadAuthRequest(fmt.Sprintf("皮肤主题数量必须为 1 到 %d 套", maxAppearanceSkinThemes))
|
||||
}
|
||||
seen := make(map[string]struct{}, len(themes))
|
||||
foundSelected := false
|
||||
foundClassic := false
|
||||
classic := defaultClassicAppearanceSkin()
|
||||
for _, skin := range themes {
|
||||
if !appearanceSkinIDPattern.MatchString(skin.ID) {
|
||||
return BadAuthRequest("皮肤主题 ID 无效")
|
||||
}
|
||||
if _, exists := seen[skin.ID]; exists {
|
||||
return BadAuthRequest("皮肤主题 ID 不能重复")
|
||||
}
|
||||
seen[skin.ID] = struct{}{}
|
||||
if skin.ID == selectedID {
|
||||
foundSelected = true
|
||||
}
|
||||
if skin.ID == defaultAppearanceSkinID {
|
||||
foundClassic = true
|
||||
if skin.Name != classic.Name || skin.Description != classic.Description || !reflect.DeepEqual(skin.Tokens, classic.Tokens) {
|
||||
return BadAuthRequest("经典黑白为系统默认主题,不能修改或删除")
|
||||
}
|
||||
}
|
||||
if err := validateAppearanceSkinText(skin.Name, "皮肤主题名称", 40, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateAppearanceSkinText(skin.Description, "皮肤主题说明", 100, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateAppearanceSkinMode(skin.Tokens.Light); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateAppearanceSkinMode(skin.Tokens.Dark); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateAppearanceSkinComponents(skin.Tokens.Components); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !foundClassic {
|
||||
return BadAuthRequest("经典黑白为系统默认主题,不能修改或删除")
|
||||
}
|
||||
if !foundSelected {
|
||||
return BadAuthRequest("当前启用的皮肤主题不存在")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAppearanceSkinMode(mode AppearanceSkinModeTokens) error {
|
||||
value := reflect.ValueOf(mode)
|
||||
for index := 0; index < value.NumField(); index++ {
|
||||
if !appearanceColorPattern.MatchString(value.Field(index).String()) {
|
||||
return BadAuthRequest("皮肤颜色必须使用 6 或 8 位十六进制颜色")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAppearanceSkinComponents(value AppearanceSkinComponentTokens) error {
|
||||
for _, candidate := range []struct {
|
||||
value, min, max int
|
||||
label string
|
||||
}{
|
||||
{value.ButtonRadius, 0, 32, "按钮圆角"}, {value.InputRadius, 0, 32, "输入框圆角"}, {value.CardRadius, 0, 40, "卡片圆角"}, {value.OverlayRadius, 0, 40, "弹层圆角"}, {value.MenuRadius, 0, 32, "菜单圆角"}, {value.CheckboxRadius, 0, 12, "勾选框圆角"},
|
||||
{value.ControlHeight, 30, 48, "控件高度"}, {value.ControlHeightSmall, 24, 40, "小控件高度"}, {value.ControlHeightLarge, 36, 56, "大控件高度"}, {value.BorderWidth, 1, 3, "描边宽度"}, {value.FocusRingWidth, 1, 4, "焦点环宽度"},
|
||||
{value.IconSize, 12, 24, "图标尺寸"}, {value.ButtonFontWeight, 400, 700, "按钮字重"}, {value.HoverLift, 0, 4, "悬停抬升"}, {value.MotionFast, 0, 400, "快速动效时长"}, {value.MotionNormal, 0, 800, "常规动效时长"},
|
||||
} {
|
||||
if candidate.value < candidate.min || candidate.value > candidate.max {
|
||||
return BadAuthRequest(fmt.Sprintf("%s必须在 %d 到 %d 之间", candidate.label, candidate.min, candidate.max))
|
||||
}
|
||||
}
|
||||
if value.ControlHeightSmall > value.ControlHeight || value.ControlHeight > value.ControlHeightLarge {
|
||||
return BadAuthRequest("控件高度须满足小号不大于标准、标准不大于大号")
|
||||
}
|
||||
if value.MotionFast > value.MotionNormal {
|
||||
return BadAuthRequest("快速动效时长不能大于常规动效时长")
|
||||
}
|
||||
if value.ShadowStyle != "none" && value.ShadowStyle != "soft" && value.ShadowStyle != "strong" {
|
||||
return BadAuthRequest("阴影风格无效")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAppearanceSkinText(value, label string, maxRunes int, required bool) error {
|
||||
if required && value == "" {
|
||||
return BadAuthRequest(label + "不能为空")
|
||||
}
|
||||
if utf8.RuneCountInString(value) > maxRunes {
|
||||
return BadAuthRequest(fmt.Sprintf("%s不能超过 %d 个字符", label, maxRunes))
|
||||
}
|
||||
for _, char := range value {
|
||||
if unicode.IsControl(char) {
|
||||
return BadAuthRequest(label + "不能包含控制字符")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func activeAppearanceSkin(themes []AppearanceSkinTheme, id string) AppearanceSkinTheme {
|
||||
for _, skin := range themes {
|
||||
if skin.ID == id {
|
||||
return skin
|
||||
}
|
||||
}
|
||||
return defaultClassicAppearanceSkin()
|
||||
}
|
||||
@@ -27,15 +27,28 @@ func TestAppearanceDefaultsPreserveBuiltInBrand(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if appearance.Configured || appearance.SchemaVersion != appearanceSchemaVersion || appearance.BrandName != defaultAppearanceBrandName || appearance.BrandSlug != defaultAppearanceBrandSlug || appearance.AuthHeroTitle != defaultAppearanceHeroTitle || appearance.AuthHeroDescription != "" || appearance.LogoURL != defaultAppearanceLogoURL || appearance.DarkLogoURL != defaultAppearanceLogoURL || !appearance.LogoFrameEnabled || appearance.AuthVideoURL != defaultAppearanceVideoURL || appearance.AuthVideoPosterURL != defaultAppearancePosterURL || appearance.SkinID != defaultAppearanceSkinID {
|
||||
if appearance.Configured || appearance.SchemaVersion != appearanceSchemaVersion || appearance.BrandName != defaultAppearanceBrandName || appearance.BrandSlug != defaultAppearanceBrandSlug || appearance.AuthHeroTitle != defaultAppearanceHeroTitle || appearance.AuthHeroDescription != "" || appearance.LogoURL != defaultAppearanceLogoURL || appearance.DarkLogoURL != defaultAppearanceLogoURL || !appearance.LogoFrameEnabled || appearance.AuthVideoURL != defaultAppearanceVideoURL || appearance.AuthVideoPosterURL != defaultAppearancePosterURL || appearance.SkinID != defaultAppearanceSkinID || appearance.SEOTitle != defaultAppearanceBrandName || !strings.Contains(appearance.SEODescription, defaultAppearanceBrandName) || !strings.Contains(appearance.FooterCopyright, defaultAppearanceBrandName) || appearance.ICPFilingEnabled {
|
||||
t.Fatalf("Appearance() = %#v", appearance)
|
||||
}
|
||||
if appearance.LogoConfigured || appearance.DarkLogoConfigured || appearance.AuthVideoConfigured || appearance.AuthVideoPosterConfigured || appearance.Revision != "builtin" {
|
||||
t.Fatalf("Appearance() configured state = %#v", appearance)
|
||||
}
|
||||
if appearance.ActiveSkin.ID != defaultAppearanceSkinID || !appearance.ActiveSkin.Locked {
|
||||
t.Fatalf("Appearance() active skin = %#v", appearance.ActiveSkin)
|
||||
}
|
||||
if appearance.ActiveSkin.Tokens.Light.SwitchChecked == appearance.ActiveSkin.Tokens.Light.SwitchUnchecked || appearance.ActiveSkin.Tokens.Dark.SwitchChecked == appearance.ActiveSkin.Tokens.Dark.SwitchUnchecked || appearance.ActiveSkin.Tokens.Light.DangerForeground == "" {
|
||||
t.Fatalf("Appearance() state colors = %#v", appearance.ActiveSkin.Tokens)
|
||||
}
|
||||
adminAppearance, err := svc.AdminAppearance(&model.User{ID: "admin", Role: model.UserRoleAdmin, Status: model.UserStatusActive})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(adminAppearance.SkinThemes) != 4 || !adminAppearance.SkinThemes[0].Locked {
|
||||
t.Fatalf("AdminAppearance() skin library = %#v", adminAppearance.SkinThemes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppearanceBackfillsVersionThreeFieldsForExistingSetting(t *testing.T) {
|
||||
func TestAppearanceBackfillsVersionSixFieldsForExistingSetting(t *testing.T) {
|
||||
svc, db, _, _ := newAppearanceTestService(t)
|
||||
legacy := model.SystemSetting{Key: appearanceSettingKey, ValueJSON: `{"schemaVersion":1,"brandName":"旧品牌","skinId":"classic"}`}
|
||||
if err := db.Create(&legacy).Error; err != nil {
|
||||
@@ -46,7 +59,7 @@ func TestAppearanceBackfillsVersionThreeFieldsForExistingSetting(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if appearance.SchemaVersion != appearanceSchemaVersion || appearance.BrandName != "旧品牌" || appearance.BrandSlug != defaultAppearanceBrandSlug || appearance.AuthHeroTitle != defaultAppearanceHeroTitle || appearance.AuthHeroDescription != "" || appearance.DarkLogoURL != defaultAppearanceLogoURL || !appearance.LogoFrameEnabled {
|
||||
if appearance.SchemaVersion != appearanceSchemaVersion || appearance.BrandName != "旧品牌" || appearance.BrandSlug != defaultAppearanceBrandSlug || appearance.AuthHeroTitle != defaultAppearanceHeroTitle || appearance.AuthHeroDescription != "" || appearance.DarkLogoURL != defaultAppearanceLogoURL || !appearance.LogoFrameEnabled || appearance.SEOTitle != "旧品牌" || !strings.Contains(appearance.SEODescription, "旧品牌") || !strings.Contains(appearance.FooterCopyright, "旧品牌") || appearance.ActiveSkin.ID != "classic" {
|
||||
t.Fatalf("legacy appearance = %#v", appearance)
|
||||
}
|
||||
}
|
||||
@@ -73,12 +86,18 @@ func TestUpdateAppearancePersistsAuditsAndUsesVersionedPublicAssets(t *testing.T
|
||||
LogoFrameEnabled: false,
|
||||
AuthVideoResourceID: "brand-video",
|
||||
AuthVideoPosterResourceID: "brand-poster",
|
||||
SkinID: defaultAppearanceSkinID,
|
||||
SkinID: "studio-indigo",
|
||||
SEOTitle: "HIMA Studio - AI 影视工作台",
|
||||
SEODescription: "面向 Agent、图片、视频、画布与短剧生产的一体化 AI 创作工作台。",
|
||||
SEOKeywords: "AI 影视,短剧,画布",
|
||||
FooterCopyright: "© 2026 HIMA Studio. All rights reserved.",
|
||||
ICPFilingEnabled: true,
|
||||
ICPFilingNumber: "蜀ICP备2026000000号-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !updated.Configured || updated.BrandName != "HIMA Studio" || updated.BrandSlug != "hima-studio" || updated.Public.BrandSlug != "hima-studio" || updated.AuthHeroTitle != "把灵感,\n变成可见的故事。" || updated.Public.AuthHeroDescription != "从画布开始,持续推进你的创作。" || !updated.Public.LogoConfigured || !updated.Public.DarkLogoConfigured || updated.Public.LogoFrameEnabled || !updated.Public.AuthVideoConfigured || !updated.Public.AuthVideoPosterConfigured {
|
||||
if !updated.Configured || updated.BrandName != "HIMA Studio" || updated.BrandSlug != "hima-studio" || updated.Public.BrandSlug != "hima-studio" || updated.AuthHeroTitle != "把灵感,\n变成可见的故事。" || updated.Public.AuthHeroDescription != "从画布开始,持续推进你的创作。" || !updated.Public.LogoConfigured || !updated.Public.DarkLogoConfigured || updated.Public.LogoFrameEnabled || !updated.Public.AuthVideoConfigured || !updated.Public.AuthVideoPosterConfigured || updated.Public.SkinID != "studio-indigo" || updated.Public.SEOTitle != "HIMA Studio - AI 影视工作台" || updated.Public.SEOKeywords != "AI 影视,短剧,画布" || !updated.Public.ICPFilingEnabled || updated.Public.ICPFilingNumber != "蜀ICP备2026000000号-1" {
|
||||
t.Fatalf("UpdateAppearance() = %#v", updated)
|
||||
}
|
||||
for _, assetURL := range []string{updated.Public.LogoURL, updated.Public.DarkLogoURL, updated.Public.AuthVideoURL, updated.Public.AuthVideoPosterURL} {
|
||||
@@ -93,6 +112,9 @@ func TestUpdateAppearancePersistsAuditsAndUsesVersionedPublicAssets(t *testing.T
|
||||
if strings.Contains(string(encodedPublic), "brand-logo") || strings.Contains(string(encodedPublic), "brand-logo-dark") || strings.Contains(string(encodedPublic), "brand-video") || strings.Contains(string(encodedPublic), "brand-poster") {
|
||||
t.Fatalf("public appearance leaked resource IDs: %s", encodedPublic)
|
||||
}
|
||||
if strings.Contains(string(encodedPublic), "skinThemes") {
|
||||
t.Fatalf("public appearance leaked the complete skin library: %s", encodedPublic)
|
||||
}
|
||||
var auditCount int64
|
||||
if err := db.Model(&model.AdminAuditEvent{}).Where("action = ?", "appearance.update").Count(&auditCount).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -230,6 +252,70 @@ func TestUpdateAppearanceValidatesLoginCopy(t *testing.T) {
|
||||
if err == nil || !strings.Contains(err.Error(), "英文品牌标识") {
|
||||
t.Fatalf("invalid slug error = %v", err)
|
||||
}
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: "unknown-skin"})
|
||||
if err == nil || !strings.Contains(err.Error(), "皮肤主题") {
|
||||
t.Fatalf("invalid skin error = %v", err)
|
||||
}
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: defaultAppearanceSkinID, ICPFilingEnabled: true})
|
||||
if err == nil || !strings.Contains(err.Error(), "备案号") {
|
||||
t.Fatalf("missing ICP number error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppearanceSkinLibrarySupportsEditableCopiesAndProtectsClassic(t *testing.T) {
|
||||
svc, _, _, admin := newAppearanceTestService(t)
|
||||
themes := defaultAppearanceSkinThemes()
|
||||
custom := cloneAppearanceSkin(themes[0], "custom-editorial", "片场夜蓝", "自定义控件与明暗色")
|
||||
custom.Tokens.Light.Primary = "#123456"
|
||||
custom.Tokens.Light.PrimaryHover = "#234567"
|
||||
custom.Tokens.Dark.Primary = "#abcdef"
|
||||
custom.Tokens.Components.ButtonRadius = 14
|
||||
themes = append(themes, custom)
|
||||
legacyCustom := custom
|
||||
legacyCustom.Tokens.Light.SwitchChecked = ""
|
||||
legacyCustom.Tokens.Light.SwitchCheckedHover = ""
|
||||
legacyCustom.Tokens.Light.SwitchCheckedHandle = ""
|
||||
legacyCustom.Tokens.Light.SwitchUnchecked = ""
|
||||
legacyCustom.Tokens.Light.SwitchUncheckedHover = ""
|
||||
legacyCustom.Tokens.Light.SwitchUncheckedHandle = ""
|
||||
legacyCustom.Tokens.Light.DangerHover = ""
|
||||
legacyCustom.Tokens.Light.DangerActive = ""
|
||||
legacyCustom.Tokens.Light.DangerForeground = ""
|
||||
backfilled := normalizeAppearanceSkinThemes([]AppearanceSkinTheme{legacyCustom})[0]
|
||||
if backfilled.Tokens.Light.SwitchChecked != "#123456" || backfilled.Tokens.Light.SwitchCheckedHover != "#234567" || backfilled.Tokens.Light.SwitchUnchecked != legacyCustom.Tokens.Light.ControlBorder || backfilled.Tokens.Light.DangerHover != legacyCustom.Tokens.Light.Danger {
|
||||
t.Fatalf("legacy skin state backfill = %#v", backfilled.Tokens.Light)
|
||||
}
|
||||
|
||||
updated, err := svc.UpdateAppearance(admin, AppearanceSetting{
|
||||
BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle,
|
||||
SkinID: custom.ID, SkinThemes: themes,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if updated.Public.ActiveSkin.ID != custom.ID || updated.Public.ActiveSkin.Tokens.Light.Primary != "#123456" || updated.Public.ActiveSkin.Tokens.Components.ButtonRadius != 14 || len(updated.SkinThemes) != 5 {
|
||||
t.Fatalf("custom skin round trip = %#v", updated)
|
||||
}
|
||||
|
||||
withoutClassic := append([]AppearanceSkinTheme(nil), themes[1:]...)
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: custom.ID, SkinThemes: withoutClassic})
|
||||
if err == nil || !strings.Contains(err.Error(), "不能修改或删除") {
|
||||
t.Fatalf("missing classic error = %v", err)
|
||||
}
|
||||
|
||||
mutatedClassic := append([]AppearanceSkinTheme(nil), themes...)
|
||||
mutatedClassic[0].Name = "改名"
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: custom.ID, SkinThemes: mutatedClassic})
|
||||
if err == nil || !strings.Contains(err.Error(), "不能修改或删除") {
|
||||
t.Fatalf("mutated classic error = %v", err)
|
||||
}
|
||||
|
||||
invalidColor := append([]AppearanceSkinTheme(nil), themes...)
|
||||
invalidColor[len(invalidColor)-1].Tokens.Light.Primary = "red; background:url(x)"
|
||||
_, err = svc.UpdateAppearance(admin, AppearanceSetting{BrandName: "HIMA Studio", BrandSlug: "hima-studio", AuthHeroTitle: defaultAppearanceHeroTitle, SkinID: custom.ID, SkinThemes: invalidColor})
|
||||
if err == nil || !strings.Contains(err.Error(), "十六进制") {
|
||||
t.Fatalf("invalid color error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAppearanceUploadSniffsBytesInsteadOfDeclaredMIME(t *testing.T) {
|
||||
|
||||
@@ -233,14 +233,15 @@ func (s *Service) ExportDiagnosticBundle(userID string, req DiagnosticExportRequ
|
||||
RedactionVersion: diagnosticRedactionVersion, Truncated: collection.Truncated,
|
||||
Counts: diagnosticCounts{ClientEvents: len(collection.ClientEvents), Tasks: len(collection.Tasks), TaskLogs: len(collection.TaskLogs), APICalls: len(collection.APICalls)},
|
||||
}
|
||||
data, err := buildDiagnosticZIP(bundleID, manifest, collection)
|
||||
brandName, brandSlug := s.appearanceIdentity()
|
||||
data, err := buildDiagnosticZIP(brandName, bundleID, manifest, collection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(data) > diagnosticMaxBundleBytes {
|
||||
return nil, BadAuthRequest("诊断包超过 10 MB,请缩短时间范围后重试")
|
||||
}
|
||||
fileName := fmt.Sprintf("yingce-diagnostics-%s-%s.zip", time.Now().UTC().Format("20060102-150405"), bundleID)
|
||||
fileName := fmt.Sprintf("%s-diagnostics-%s-%s.zip", brandSlug, time.Now().UTC().Format("20060102-150405"), bundleID)
|
||||
return &DiagnosticBundle{BundleID: bundleID, FileName: fileName, Data: data}, nil
|
||||
}
|
||||
|
||||
@@ -372,7 +373,7 @@ func sanitizeDiagnosticAPICall(log model.ApiCallLog) diagnosticAPICallRecord {
|
||||
}
|
||||
}
|
||||
|
||||
func buildDiagnosticZIP(bundleID string, manifest diagnosticManifest, collection *diagnosticCollection) ([]byte, error) {
|
||||
func buildDiagnosticZIP(brandName string, bundleID string, manifest diagnosticManifest, collection *diagnosticCollection) ([]byte, error) {
|
||||
var buffer bytes.Buffer
|
||||
archive := zip.NewWriter(&buffer)
|
||||
manifestData, err := json.MarshalIndent(manifest, "", " ")
|
||||
@@ -383,7 +384,7 @@ func buildDiagnosticZIP(bundleID string, manifest diagnosticManifest, collection
|
||||
return nil, err
|
||||
}
|
||||
newline := string(rune(10))
|
||||
readme := fmt.Sprintf("影策用户诊断包%s%s诊断编号:%s%s时间范围:%s 至 %s%s%s该文件由用户主动导出,仅包含有限时间范围内的脱敏诊断摘要。%s", newline, newline, bundleID, newline, collection.Window.From.Format(time.RFC3339), collection.Window.To.Format(time.RFC3339), newline, newline, newline)
|
||||
readme := fmt.Sprintf("%s 用户诊断包%s%s诊断编号:%s%s时间范围:%s 至 %s%s%s该文件由用户主动导出,仅包含有限时间范围内的脱敏诊断摘要。%s", brandName, newline, newline, bundleID, newline, collection.Window.From.Format(time.RFC3339), collection.Window.To.Format(time.RFC3339), newline, newline, newline)
|
||||
if err := writeDiagnosticZipFile(archive, "README.txt", []byte(readme)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -40,17 +40,18 @@ type EmailSettingRequest struct {
|
||||
}
|
||||
|
||||
type PublicEmailSetting struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Username string `json:"username"`
|
||||
Encryption string `json:"encryption"`
|
||||
FromEmail string `json:"fromEmail"`
|
||||
FromName string `json:"fromName"`
|
||||
HasPassword bool `json:"hasPassword"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Username string `json:"username"`
|
||||
Encryption string `json:"encryption"`
|
||||
FromEmail string `json:"fromEmail"`
|
||||
FromName string `json:"fromName"`
|
||||
FromNameInherited bool `json:"fromNameInherited"`
|
||||
HasPassword bool `json:"hasPassword"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type emailSettingValue struct {
|
||||
@@ -72,7 +73,7 @@ func (s *Service) AdminEmailSetting(actor *model.User) (*PublicEmailSetting, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return publicEmailSetting(setting, value), nil
|
||||
return s.publicEmailSetting(setting, value), nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateEmailSetting(actor *model.User, req EmailSettingRequest) (*PublicEmailSetting, error) {
|
||||
@@ -106,7 +107,7 @@ func (s *Service) UpdateEmailSetting(actor *model.User, req EmailSettingRequest)
|
||||
if err := s.repo.SaveSystemSetting(&setting); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return publicEmailSetting(&setting, next), nil
|
||||
return s.publicEmailSetting(&setting, next), nil
|
||||
}
|
||||
|
||||
func (s *Service) EmailEnabled() (bool, error) {
|
||||
@@ -168,7 +169,9 @@ func (s *Service) SendRegistrationEmailCode(rawEmail string) error {
|
||||
if err := s.repo.Create(&record); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.deliverEmail(setting, email, "影策注册验证码", registrationEmailBody(code)); err != nil {
|
||||
brandName := s.appearanceBrandName()
|
||||
setting = resolveEmailSender(setting, brandName)
|
||||
if err := s.deliverEmail(setting, email, brandName+"注册验证码", registrationEmailBody(brandName, code)); err != nil {
|
||||
cleanupErr := s.repo.DeleteEmailVerificationCode(record.ID)
|
||||
if cleanupErr != nil {
|
||||
return errors.Join(
|
||||
@@ -278,14 +281,13 @@ func normalizeEmailSetting(value emailSettingValue) emailSettingValue {
|
||||
default:
|
||||
value.Encryption = "starttls"
|
||||
}
|
||||
if value.FromName == "" {
|
||||
value.FromName = "影策"
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func publicEmailSetting(setting *model.SystemSetting, value emailSettingValue) *PublicEmailSetting {
|
||||
result := &PublicEmailSetting{Enabled: value.Enabled, Host: value.Host, Port: value.Port, Username: value.Username, Encryption: value.Encryption, FromEmail: value.FromEmail, FromName: value.FromName, HasPassword: value.Password != ""}
|
||||
func (s *Service) publicEmailSetting(setting *model.SystemSetting, value emailSettingValue) *PublicEmailSetting {
|
||||
inherited := value.FromName == "" || value.FromName == defaultAppearanceBrandName
|
||||
value = resolveEmailSender(value, s.appearanceBrandName())
|
||||
result := &PublicEmailSetting{Enabled: value.Enabled, Host: value.Host, Port: value.Port, Username: value.Username, Encryption: value.Encryption, FromEmail: value.FromEmail, FromName: value.FromName, FromNameInherited: inherited, HasPassword: value.Password != ""}
|
||||
if setting != nil {
|
||||
result.UpdatedBy = setting.UpdatedBy
|
||||
result.CreatedAt = setting.CreatedAt
|
||||
@@ -294,6 +296,13 @@ func publicEmailSetting(setting *model.SystemSetting, value emailSettingValue) *
|
||||
return result
|
||||
}
|
||||
|
||||
func resolveEmailSender(value emailSettingValue, brandName string) emailSettingValue {
|
||||
if value.FromName == "" || value.FromName == defaultAppearanceBrandName {
|
||||
value.FromName = brandName
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func sendSMTPMail(setting emailSettingValue, recipient string, subject string, body string) error {
|
||||
address := net.JoinHostPort(setting.Host, strconv.Itoa(setting.Port))
|
||||
tlsConfig := &tls.Config{ServerName: setting.Host, MinVersion: tls.VersionTLS12}
|
||||
@@ -363,6 +372,6 @@ func randomNumericCode(length int) (string, error) {
|
||||
return fmt.Sprintf("%0*d", length, value.Int64()), nil
|
||||
}
|
||||
|
||||
func registrationEmailBody(code string) string {
|
||||
return "你正在注册影策。\n\n验证码:" + code + "\n\n验证码 10 分钟内有效。若非本人操作,请忽略本邮件。"
|
||||
func registrationEmailBody(brandName string, code string) string {
|
||||
return "你正在注册" + brandName + "。\n\n验证码:" + code + "\n\n验证码 10 分钟内有效。若非本人操作,请忽略本邮件。"
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func (s *Service) ImportLibTV(userID, canvasProjectID, projectUUID string) (*Lib
|
||||
userID = strings.TrimSpace(userID)
|
||||
canvasProjectID = strings.TrimSpace(canvasProjectID)
|
||||
if userID == "" || canvasProjectID == "" {
|
||||
return nil, Unauthorized("请先打开已同步的影策画布")
|
||||
return nil, Unauthorized("请先打开已同步的" + s.appearanceBrandName() + "画布")
|
||||
}
|
||||
if _, err := s.repo.CanvasProjectForUser(userID, canvasProjectID); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -56,7 +56,7 @@ func adaptLibTVDetail(detail *libTVDetail) (*LibTVImportResult, error) {
|
||||
sourceType := strings.ToLower(strings.TrimSpace(data.Type))
|
||||
kind := sourceType
|
||||
if sourceType == "material-style" {
|
||||
// 风格素材没有普通生成 URL,但有可复用封面时可以降级为影策图片参考节点。
|
||||
// 风格素材没有普通生成 URL,但有可复用封面时可以降级为宿主图片参考节点。
|
||||
kind = "image"
|
||||
} else if kind != "image" && kind != "video" {
|
||||
result.SkippedNodes = append(result.SkippedNodes, LibTVImportIssue{ID: nodeKey, Name: raw.Name, Reason: "暂不支持的节点类型"})
|
||||
|
||||
@@ -74,7 +74,9 @@ func (s *Service) SendPasswordResetEmailCode(rawEmail string) error {
|
||||
if err := s.repo.Create(&record); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.deliverEmail(setting, email, "影策密码重置验证码", passwordResetEmailBody(code)); err != nil {
|
||||
brandName := s.appearanceBrandName()
|
||||
setting = resolveEmailSender(setting, brandName)
|
||||
if err := s.deliverEmail(setting, email, brandName+"密码重置验证码", passwordResetEmailBody(brandName, code)); err != nil {
|
||||
if cleanupErr := s.repo.DeleteEmailVerificationCode(record.ID); cleanupErr != nil {
|
||||
log.Printf("password reset email cleanup failed: recipient=%s error=%v", maskedEmail(email), cleanupErr)
|
||||
}
|
||||
@@ -144,8 +146,8 @@ func invalidPasswordResetCode() *AuthError {
|
||||
return BadAuthRequest("验证码无效或已过期")
|
||||
}
|
||||
|
||||
func passwordResetEmailBody(code string) string {
|
||||
return "你正在重置影策账号密码。\n\n验证码:" + code + "\n\n验证码 10 分钟内有效。若非本人操作,请忽略本邮件,并确保邮箱账号安全。"
|
||||
func passwordResetEmailBody(brandName string, code string) string {
|
||||
return "你正在重置" + brandName + "账号密码。\n\n验证码:" + code + "\n\n验证码 10 分钟内有效。若非本人操作,请忽略本邮件,并确保邮箱账号安全。"
|
||||
}
|
||||
|
||||
func maskedEmail(email string) string {
|
||||
|
||||
@@ -187,6 +187,65 @@ func TestPasswordResetDeliveryFailureRemovesUnusableCode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomAppearanceBrandsRegistrationAndPasswordResetEmails(t *testing.T) {
|
||||
svc, db := newPasswordResetTestService(t)
|
||||
appearanceJSON, err := json.Marshal(AppearanceSetting{
|
||||
SchemaVersion: appearanceSchemaVersion,
|
||||
BrandName: "HIMA Studio",
|
||||
BrandSlug: "hima-studio",
|
||||
AuthHeroTitle: defaultAppearanceHeroTitle,
|
||||
LogoFrameEnabled: true,
|
||||
SkinID: defaultAppearanceSkinID,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.SystemSetting{Key: appearanceSettingKey, ValueJSON: string(appearanceJSON)}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.SystemSetting{Key: registrationSettingKey, ValueJSON: `{"enabled":true}`}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
passwordHash, err := hashPassword("strong-password")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
existing := model.User{ID: "brand-admin", Username: "brand-admin", Email: "admin@example.com", Role: model.UserRoleAdmin, Status: model.UserStatusActive, PasswordHash: passwordHash}
|
||||
resetUser := model.User{ID: "brand-user", Username: "brand-user", Email: "member@example.com", Role: model.UserRoleUser, Status: model.UserStatusActive, PasswordHash: passwordHash}
|
||||
if err := db.Create(&[]model.User{existing, resetUser}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
type delivery struct {
|
||||
fromName string
|
||||
recipient string
|
||||
subject string
|
||||
body string
|
||||
}
|
||||
deliveries := make([]delivery, 0, 2)
|
||||
svc.mailSender = func(setting emailSettingValue, recipient string, subject string, body string) error {
|
||||
deliveries = append(deliveries, delivery{fromName: setting.FromName, recipient: recipient, subject: subject, body: body})
|
||||
return nil
|
||||
}
|
||||
if err := svc.SendRegistrationEmailCode("new-member@example.com"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := svc.SendPasswordResetEmailCode(resetUser.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(deliveries) != 2 {
|
||||
t.Fatalf("deliveries = %d, want 2", len(deliveries))
|
||||
}
|
||||
for _, delivered := range deliveries {
|
||||
if delivered.fromName != "HIMA Studio" || !strings.Contains(delivered.subject, "HIMA Studio") || !strings.Contains(delivered.body, "HIMA Studio") || strings.Contains(delivered.subject, defaultAppearanceBrandName) || strings.Contains(delivered.body, defaultAppearanceBrandName) {
|
||||
t.Fatalf("email did not inherit custom appearance: %#v", delivered)
|
||||
}
|
||||
}
|
||||
if deliveries[0].subject != "HIMA Studio注册验证码" || deliveries[1].subject != "HIMA Studio密码重置验证码" {
|
||||
t.Fatalf("unexpected branded subjects: %#v", deliveries)
|
||||
}
|
||||
}
|
||||
|
||||
func newPasswordResetTestService(t *testing.T) (*Service, *gorm.DB) {
|
||||
t.Helper()
|
||||
db, err := gorm.Open(sqlite.Open("file:"+newID()+"?mode=memory&cache=shared"), &gorm.Config{})
|
||||
|
||||
@@ -41,9 +41,9 @@ func workflowPluginManifest(id, name, description string) protocol.Manifest {
|
||||
ID: id,
|
||||
Version: "1.0.0",
|
||||
Name: name,
|
||||
Vendor: "影策",
|
||||
Vendor: "内置工作流",
|
||||
Description: description,
|
||||
Documentation: "# " + name + "\n\n## 影策运行时合同\n\n该工作流能力由插件运行时统一管理。",
|
||||
Documentation: "# " + name + "\n\n## 宿主运行时合同\n\n该工作流能力由插件运行时统一管理。",
|
||||
Enabled: false,
|
||||
Installable: true,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user