Skip to content

feat(share): 通用脚本模板与分享接入新版配置中心 - #630

Open
qiyinxi wants to merge 2 commits into
AUTO-MAS-Project:devfrom
qiyinxi:feat/config-center-20260908
Open

feat(share): 通用脚本模板与分享接入新版配置中心#630
qiyinxi wants to merge 2 commits into
AUTO-MAS-Project:devfrom
qiyinxi:feat/config-center-20260908

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

通用脚本的「从模板创建」与「分享配置」全部改走新配置中心;分享前要先在浏览器完成一次登录授权。

  • 模板:列表、搜索、分页、下载改用配置中心的 GET /api/v1/configs 与结构化下载接口,只展示已审核发布、属于 AUTO-MAS 通用脚本分类的配置。渲染进程不再提交任意下载 URL,改为传 configKey + versionNo;下载有 2 MiB 上限并校验确实是通用脚本配置,导入失败会把刚建出来的空脚本删掉,不留空壳。
  • 分享登录:点分享后桌面端向配置中心申请一个人读短码,用系统浏览器打开授权页,用户确认后桌面端轮询换到一枚 30 分钟、只能上传配置的令牌。令牌只存在内存里——不写配置文件、不进日志、不进 URL;弹窗关闭或点「取消登录」会停轮询并撤销等待中的会话。Casdoor client secret 全程留在配置中心后端。
  • 分享者身份:表单去掉「作者」,由登录账号决定;上传后进入配置中心已有的待审核流程,审核通过才出现在模板列表里。表单本身不跳转,登录往返不丢输入。
  • 隐私检查:原有的路径占位替换保留并扩展到全部字段(本机用户目录统一打码为 %USERPROFILE%);新增一次分享前扫描,把疑似账号/密码/令牌、链接里带账号密码、含本机用户名或本机绝对路径的配置项列给用户,勾选确认后才允许上传。用户数据(SubConfigsInfo)一如既往整体不上传。

Important

部署方需要确认的三个值,都收敛在 app/services/config_center.py 顶部,也可用环境变量覆盖:

环境变量 当前默认值 说明
AUTO_MAS_CONFIG_CENTER_API https://share.auto-mas.top/api/v1 新配置中心后端地址。三个仓库里都没有写死的生产值,这个默认值是按「新站替换旧站、路径前缀不重叠」推的,上线前请照实际部署改掉
AUTO_MAS_CONFIG_CENTER_PROJECT auto-mas 通用脚本所属的 project_key,需要管理员在配置中心后台建好并置为 active。
AUTO_MAS_CONFIG_CENTER_CATEGORY general 通用脚本所属的 category_key,需要是 active 且 public。

授权页地址由配置中心后端下发(FRONTEND_BASE_URL),桌面端不写死。

Note

契约变更:POST /api/scripts/import/web 的请求体由 {scriptId, url} 改为 {scriptId, configKey, versionNo}POST /api/scripts/Upload/web 去掉 author、加 acknowledged;删除 POST /api/info/webconfig(返回的是旧站专有结构,新站接上后没有消费方);新增 POST /api/scripts/share/inspect/api/share/*。全局配置里 Data.WebConfigData.LastWebConfigUpdated 两项随旧接口一并移除。frontend/src/api 是按规范起开发后端后 yarn openapi 重新生成的。

分支已合入当时的 dev97335f0a):冲突只在 app/api/__init__.py(两边各加了一个 router)与两个 OpenAPI 生成文件上,生成文件是重新起开发后端后 yarn openapi 重新生成的,没有手改;git diff upstream/dev 确认除本 PR 自己的文件外没有动到 dev 的任何改动。

CHANGELOG.md 里另有两行不属于本次改动:res/version.json 上「森空岛获取凭据改为扫码登录…」和「BetterGI专项、ZZZ-OD专项 修复任务出错时提示…」两条带着 by [@qiyinxi] 署名,但 CHANGELOG.md 上没有,直接跑 changelog.py sync 会把这两个署名抹掉。这里把署名补回单一来源,res/version.json 的 diff 就只剩本 PR 新增的一条。

需要配置中心两个仓库同时合并:

  • AUTO-MAS-Project/config-center-backend#1 —— 设备授权端点与桌面令牌 scope
  • AUTO-MAS-Project/config-center-frontend#2 —— /device 授权页

本地验证(.venv\Scripts\python.exe 3.12 / Corepack Yarn 4.9.1):

  • frontendyarn lint --max-warnings 1yarn typecheck 通过;yarn test Test Files 1 failed | 44 passed (45)Tests 1 failed | 419 passed (420),失败的 electron/services/backendService.test.ts managed 模式那条在完全无关的工作树上复现,是既存红灯。
  • python -m pytest tests -q720 passed, 3 skipped(含合并 dev 之后的全量);--collect-only -q 退出码 0。
  • 端到端:本机起配置中心后端(sqlite)+ 配置中心前端 + AUTO-MAS 开发后端与 vite,用 API 与界面各走了一遍完整链路——申请短码 → 浏览器授权页批准 → 桌面端换令牌 → 隐私检查列出 Game.PathScript.Arguments 两项 → 未勾确认时上传被拒 → 勾选后上传成功 → 普通用户进待审核、管理员通过后出现在模板列表 → 关键字搜索命中/落空 → 结构化标识下载导入并落到编辑页。校验了上传内容里不再含本机用户名,重名上传会提示「该配置名称已被占用」。

Closes #624

🤖 Generated with Claude Code

模板列表、搜索、分页与下载改用配置中心的 /api/v1/configs 与结构化下载接口,
渲染进程不再提交任意下载 URL;下载有体积上限与格式校验,导入失败会删掉刚建出来
的空脚本。

分享改为设备授权:桌面端申请人读短码,用系统浏览器打开配置中心授权页,用户确认后
换取一枚只能上传配置的短期令牌,令牌只留在内存里。分享表单去掉作者,身份由登录
账号决定,上传后进入配置中心已有的待审核流程。

分享前的隐私清理扩展到全部字段,并新增一次扫描:疑似账号、密码、令牌、本机用户名
或本机绝对路径的配置项会列给用户,确认后才允许上传。

Closes AUTO-MAS-Project#624

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @qiyinxi, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 17 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown

审查者指南

本 PR 将通用脚本模板和分享流程整体迁移至新版配置中心:模板使用服务端筛选分页及结构化下载,分享通过浏览器设备授权获得仅内存令牌,并在上传前执行隐私脱敏与风险确认,同时移除旧站配置契约。

分享前浏览器授权时序图

sequenceDiagram
    participant User as User
    participant Desktop as AUTO_MAS
    participant Center as ConfigCenter
    participant Browser as SystemBrowser

    User->>Desktop: startShareAuth()
    Desktop->>Center: POST /auth/device/code
    Center-->>Desktop: userCode and verificationUri
    Desktop->>Browser: open verificationUri
    User->>Browser: approve authorization
    loop until terminal status
        Desktop->>Center: POST /auth/device/token
        Center-->>Desktop: pending or authorized
    end
    Center-->>Desktop: 30-minute upload token
    Desktop->>Desktop: store token in memory
    User->>Desktop: cancel or close dialog
    Desktop->>Center: cancel_authorization()
    Desktop->>Desktop: stop polling and clear device session
Loading

隐私检查配置分享时序图

sequenceDiagram
    participant User as User
    participant Desktop as AUTO_MAS
    participant Backend as DesktopBackend
    participant Center as ConfigCenter

    User->>Desktop: open share form
    Desktop->>Backend: POST /api/scripts/share/inspect
    Backend->>Backend: build_share_config()
    Backend->>Backend: remove_privacy_info()
    Backend->>Backend: scan_privacy_risks()
    Backend-->>Desktop: sanitized risks
    User->>Desktop: acknowledge risks
    Desktop->>Backend: POST /api/scripts/Upload/web
    Backend->>Backend: build_share_config()
    Backend->>Center: POST /user/configs
    Center-->>Backend: pending review result
    Backend-->>Desktop: upload success
Loading

从已发布模板创建脚本流程图

flowchart TD
    A["Open general script template picker"] --> B["Search or change page"]
    B --> C["Fetch published templates from config center"]
    C --> D["Select template by configKey"]
    D --> E["Create empty script"]
    E --> F["Import using configKey and versionNo"]
    F --> G{"Download and validation succeeds"}
    G -->|yes| H["Open imported script"]
    G -->|no| I["Delete newly created empty script"]
Loading

文件级变更

变更 详细信息 文件
将通用脚本模板的浏览与导入迁移到新版配置中心,并改用受约束的配置标识下载流程。
  • 新增配置中心模板列表接口,支持服务端搜索、分页并仅返回已发布的通用脚本配置
  • 导入请求从任意 URL 改为 configKey/versionNo,并限制下载大小、校验配置类型及清理用户数据
  • 模板导入失败时删除已创建的空脚本
app/services/config_center.py
app/core/config.py
app/api/share.py
app/api/scripts.py
app/models/schema.py
frontend/src/composables/useTemplateApi.ts
frontend/src/views/Scripts.vue
frontend/src/views/scripts/components/ScriptCreateDialog.vue
frontend/src/views/scripts/components/scriptCreateFlow.ts
frontend/src/api
实现配置中心的浏览器设备授权和内存令牌管理,为分享操作提供受限身份认证。
  • 新增启动、轮询、查询状态和取消授权的分享 API
  • 通过系统浏览器完成授权,令牌仅保存在内存并在有效期及 scope 约束下上传配置
  • 弹窗关闭、取消或授权终态时停止轮询并清理等待中的会话
app/services/config_center.py
app/api/share.py
app/main.py
frontend/src/composables/useShareApi.ts
frontend/src/views/EditView/Script/GeneralScriptEdit.vue
frontend/src/api
重构分享表单和上传链路,使登录账号确定分享者并纳入审核流程。
  • 移除作者字段,上传改为配置中心用户身份并提交待审核配置
  • 保持登录往返期间的表单输入,支持重新登录或切换账号
  • 增加配置名、描述和 acknowledged 契约校验及相应前端状态处理
app/api/scripts.py
app/models/schema.py
app/core/config.py
frontend/src/views/EditView/Script/GeneralScriptEdit.vue
frontend/src/i18n/locales/en-US.ts
frontend/src/i18n/locales/zh-CN.ts
扩展分享前隐私保护,自动脱敏已知路径并要求用户确认剩余风险。
  • 将本机用户目录及自由文本中的路径统一替换为 %USERPROFILE% 等占位符
  • 扫描账号、密码、令牌、认证 URL、本机用户名和绝对路径并展示风险字段
  • 始终移除 SubConfigsInfo,未确认风险时阻止上传
app/core/config.py
app/api/scripts.py
app/models/schema.py
frontend/src/views/EditView/Script/GeneralScriptEdit.vue
tests/core/test_share_privacy.py
移除旧配置分享中心的本地配置与接口契约,并同步生成前端 API 类型。
  • 删除旧 webconfig 接口及 Data.WebConfig、Data.LastWebConfigUpdated 配置项
  • 新增分享相关路由、模型和 OpenAPI 生成的前端服务方法
  • 补充变更日志署名和版本资源更新
app/api/info.py
app/models/config.py
app/api/__init__.py
app/services/__init__.py
frontend/src/api
CHANGELOG.md
res/version.json

可能相关的问题


提示与命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以回复审查评论 @sourcery-ai issue,从中创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,随时重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,随时重新生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时重新生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。如果你想从新的审查开始,这尤其有用——别忘了评论 @sourcery-ai review 以触发新的审查!

自定义使用体验

访问你的控制面板

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

本 PR 将通用脚本模板和分享流程整体迁移至新版配置中心:模板使用服务端筛选分页及结构化下载,分享通过浏览器设备授权获得仅内存令牌,并在上传前执行隐私脱敏与风险确认,同时移除旧站配置契约。

Sequence diagram for browser authorization before sharing

sequenceDiagram
    participant User as User
    participant Desktop as AUTO_MAS
    participant Center as ConfigCenter
    participant Browser as SystemBrowser

    User->>Desktop: startShareAuth()
    Desktop->>Center: POST /auth/device/code
    Center-->>Desktop: userCode and verificationUri
    Desktop->>Browser: open verificationUri
    User->>Browser: approve authorization
    loop until terminal status
        Desktop->>Center: POST /auth/device/token
        Center-->>Desktop: pending or authorized
    end
    Center-->>Desktop: 30-minute upload token
    Desktop->>Desktop: store token in memory
    User->>Desktop: cancel or close dialog
    Desktop->>Center: cancel_authorization()
    Desktop->>Desktop: stop polling and clear device session
Loading

Sequence diagram for privacy-checked configuration sharing

sequenceDiagram
    participant User as User
    participant Desktop as AUTO_MAS
    participant Backend as DesktopBackend
    participant Center as ConfigCenter

    User->>Desktop: open share form
    Desktop->>Backend: POST /api/scripts/share/inspect
    Backend->>Backend: build_share_config()
    Backend->>Backend: remove_privacy_info()
    Backend->>Backend: scan_privacy_risks()
    Backend-->>Desktop: sanitized risks
    User->>Desktop: acknowledge risks
    Desktop->>Backend: POST /api/scripts/Upload/web
    Backend->>Backend: build_share_config()
    Backend->>Center: POST /user/configs
    Center-->>Backend: pending review result
    Backend-->>Desktop: upload success
Loading

Flow diagram for creating a script from a published template

flowchart TD
    A["Open general script template picker"] --> B["Search or change page"]
    B --> C["Fetch published templates from config center"]
    C --> D["Select template by configKey"]
    D --> E["Create empty script"]
    E --> F["Import using configKey and versionNo"]
    F --> G{"Download and validation succeeds"}
    G -->|yes| H["Open imported script"]
    G -->|no| I["Delete newly created empty script"]
Loading

File-Level Changes

Change Details Files
将通用脚本模板的浏览与导入迁移到新版配置中心,并改用受约束的配置标识下载流程。
  • 新增配置中心模板列表接口,支持服务端搜索、分页并仅返回已发布的通用脚本配置
  • 导入请求从任意 URL 改为 configKey/versionNo,并限制下载大小、校验配置类型及清理用户数据
  • 模板导入失败时删除已创建的空脚本
app/services/config_center.py
app/core/config.py
app/api/share.py
app/api/scripts.py
app/models/schema.py
frontend/src/composables/useTemplateApi.ts
frontend/src/views/Scripts.vue
frontend/src/views/scripts/components/ScriptCreateDialog.vue
frontend/src/views/scripts/components/scriptCreateFlow.ts
frontend/src/api
实现配置中心的浏览器设备授权和内存令牌管理,为分享操作提供受限身份认证。
  • 新增启动、轮询、查询状态和取消授权的分享 API
  • 通过系统浏览器完成授权,令牌仅保存在内存并在有效期及 scope 约束下上传配置
  • 弹窗关闭、取消或授权终态时停止轮询并清理等待中的会话
app/services/config_center.py
app/api/share.py
app/main.py
frontend/src/composables/useShareApi.ts
frontend/src/views/EditView/Script/GeneralScriptEdit.vue
frontend/src/api
重构分享表单和上传链路,使登录账号确定分享者并纳入审核流程。
  • 移除作者字段,上传改为配置中心用户身份并提交待审核配置
  • 保持登录往返期间的表单输入,支持重新登录或切换账号
  • 增加配置名、描述和 acknowledged 契约校验及相应前端状态处理
app/api/scripts.py
app/models/schema.py
app/core/config.py
frontend/src/views/EditView/Script/GeneralScriptEdit.vue
frontend/src/i18n/locales/en-US.ts
frontend/src/i18n/locales/zh-CN.ts
扩展分享前隐私保护,自动脱敏已知路径并要求用户确认剩余风险。
  • 将本机用户目录及自由文本中的路径统一替换为 %USERPROFILE% 等占位符
  • 扫描账号、密码、令牌、认证 URL、本机用户名和绝对路径并展示风险字段
  • 始终移除 SubConfigsInfo,未确认风险时阻止上传
app/core/config.py
app/api/scripts.py
app/models/schema.py
frontend/src/views/EditView/Script/GeneralScriptEdit.vue
tests/core/test_share_privacy.py
移除旧配置分享中心的本地配置与接口契约,并同步生成前端 API 类型。
  • 删除旧 webconfig 接口及 Data.WebConfig、Data.LastWebConfigUpdated 配置项
  • 新增分享相关路由、模型和 OpenAPI 生成的前端服务方法
  • 补充变更日志署名和版本资源更新
app/api/info.py
app/models/config.py
app/api/__init__.py
app/services/__init__.py
frontend/src/api
CHANGELOG.md
res/version.json

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

…0260908

冲突只在 app/api/__init__.py(两边各加了一个 router)与两个 OpenAPI 生成文件上。
生成文件按规范起开发后端后用 yarn openapi 重新生成,没有手改。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant