Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 修复配置管理重启服务的问题
gaoSirf611eb8aa86b
diff --git a/project/aitoearn-web/src/api/README.md b/project/aitoearn-web/src/api/README.mdindex 6e8fd8c3..92c88320 100644--- a/project/aitoearn-web/src/api/README.md+++ b/project/aitoearn-web/src/api/README.md@@ -22,6 +22,6 @@| `analytics/` | 发布流程中使用的统计辅助接口。 | `analytics/README.md` || `auth/` | 登录、验证码与当前用户信息。 | `auth/README.md` || `channels/` | 渠道平台元数据、渠道授权、发布流程与发布记录。 | `channels/README.md` |-| `config-editor/` | 配置管理、配置校验、保存、服务重启与健康检查。 | `config-editor/README.md` |+| `config-editor/` | 配置管理、配置校验、保存、服务重启与恢复检查。 | `config-editor/README.md` || `materials/` | OSS 上传、媒体库、草稿素材、素材组与公开素材查询。 | `materials/README.md` || `platforms/` | 平台专项能力,例如发布、互动、作品校验和平台参数。 | `platforms/README.md` |diff --git a/project/aitoearn-web/src/api/accounts/account.api.ts b/project/aitoearn-web/src/api/accounts/account.api.tsindex 0dc17063..94988a33 100644--- a/project/aitoearn-web/src/api/accounts/account.api.ts+++ b/project/aitoearn-web/src/api/accounts/account.api.ts@@ -19,8 +19,8 @@ export function createChannelAccountApi(data: CreateChannelAccountParams) {/*** 账号列表*/-export function getAccountListApi() {- return http.get<AccountListData>('v2/channels/accounts')+export function getAccountListApi(silent = false) {+ return http.get<AccountListData>('v2/channels/accounts', undefined, silent)}/**diff --git a/project/aitoearn-web/src/api/config-editor/README.md b/project/aitoearn-web/src/api/config-editor/README.mdindex 0cebe3ca..be100f7f 100644--- a/project/aitoearn-web/src/api/config-editor/README.md+++ b/project/aitoearn-web/src/api/config-editor/README.md@@ -6,23 +6,22 @@| 文件 | 说明 || ------------------------ | ------------------------------------------------------------ |-| `config-editor.api.ts` | 按服务目标获取配置、校验配置、保存配置、重启服务、健康检查。 |+| `config-editor.api.ts` | 按服务目标获取配置、校验配置、保存配置、重启服务、恢复检查。 || `config-editor.types.ts` | 配置文件格式、服务目标、配置响应与请求类型。 |## 接口清单-| 方法 | 路径 | 说明 |-| ----------------------------------- | --------------------------------------------- | -------------------------------------- |-| `getConfigEditorConfigApi` | `GET config` / `GET ai/config` | 获取指定服务配置对象与配置文件格式。 |-| `validateConfigEditorConfigApi` | `POST config/validate` / `ai/config/validate` | 校验指定服务配置对象。 |-| `saveConfigEditorConfigApi` | `PUT config` / `PUT ai/config` | 保存指定服务配置对象。 |-| `restartConfigEditorServiceApi` | `POST config/restart` / `ai/config/restart` | 重启指定服务。 |-| `checkConfigEditorServiceHealthApi` | `/health` | 使用纯文本健康检查确认主服务是否恢复。 |-| `checkConfigEditorConfigReadyApi` | `/health` / `GET ai/config` | 按服务目标确认配置接口是否恢复可用。 |+| 方法 | 路径 | 说明 |+| --------------------------------- | --------------------------------------------- | ------------------------------------ |+| `getConfigEditorConfigApi` | `GET config` / `GET ai/config` | 获取指定服务配置对象与配置文件格式。 |+| `validateConfigEditorConfigApi` | `POST config/validate` / `ai/config/validate` | 校验指定服务配置对象。 |+| `saveConfigEditorConfigApi` | `PUT config` / `PUT ai/config` | 保存指定服务配置对象。 |+| `restartConfigEditorServiceApi` | `POST config/restart` / `ai/config/restart` | 重启指定服务。 |+| `checkConfigEditorConfigReadyApi` | `GET v2/channels/accounts` / `GET ai/config` | 按服务目标确认服务接口是否恢复可用。 |## 维护规则- 请求方法与类型定义保持分离。- 配置编辑 UI 不直接调用 `fetch` 访问业务接口,统一通过本目录 API。-- 主服务 `/health` 返回纯文本 `OK`,不走统一响应包裹,因此使用独立 `fetch`。+- 主服务重启后使用账号列表接口确认业务 API 恢复,避免轮询旧健康检查接口。- AI 服务配置入口通过网关路径 `ai/config` 访问,重启后使用带鉴权的配置读取确认恢复。diff --git a/project/aitoearn-web/src/api/config-editor/config-editor.api.ts b/project/aitoearn-web/src/api/config-editor/config-editor.api.tsindex 3e9bdb29..39b197be 100644--- a/project/aitoearn-web/src/api/config-editor/config-editor.api.ts+++ b/project/aitoearn-web/src/api/config-editor/config-editor.api.ts@@ -1,4 +1,5 @@import type { ConfigEditorConfigDto, ConfigEditorConfigVo } from './config-editor.types'+import { getAccountListApi } from '@/api/accounts/account.api'import http from '@/utils/request'import { ConfigEditorServiceTarget } from './config-editor.types'@@ -23,48 +24,18 @@ export function restartConfigEditorServiceApi(target = ConfigEditorServiceTargetreturn http.post<void>(getConfigEditorRoute(target, 'restart'), undefined, silent)}-function getHealthCheckUrl() {- const proxyUrl = process.env.NEXT_PUBLIC_PROXY_URL?.replace(/\/+$/, '')- if (proxyUrl)- return `${proxyUrl}/health`+export async function checkConfigEditorConfigReadyApi(target = ConfigEditorServiceTarget.Server, timeoutMs = 2500) {+ const timeout = new Promise<false>(resolve => setTimeout(() => resolve(false), timeoutMs))- const apiUrl = process.env.NEXT_PUBLIC_API_URL || '/api'- if (apiUrl.startsWith('http://') || apiUrl.startsWith('https://')) {- const url = new URL(apiUrl)- const pathWithoutApi = url.pathname.replace(/\/api\/?$/, '')- url.pathname = `${pathWithoutApi}/health`.replace(/\/{2,}/g, '/')- url.search = ''- return url.toString()+ if (target === ConfigEditorServiceTarget.Server) {+ return Promise.race([+ getAccountListApi(true)+ .then(response => !!response && response.code === 0)+ .catch(() => false),+ timeout,+ ])}- return '/health'-}--export async function checkConfigEditorServiceHealthApi(timeoutMs = 2500) {- const controller = new AbortController()- const timeoutId = setTimeout(() => controller.abort(), timeoutMs)-- try {- const response = await fetch(getHealthCheckUrl(), {- cache: 'no-store',- signal: controller.signal,- })- const text = await response.text().catch(() => '')- return response.ok && (!text.trim() || text.trim() === 'OK')- }- catch {- return false- }- finally {- clearTimeout(timeoutId)- }-}--export async function checkConfigEditorConfigReadyApi(target = ConfigEditorServiceTarget.Server, timeoutMs = 2500) {- if (target === ConfigEditorServiceTarget.Server)- return checkConfigEditorServiceHealthApi(timeoutMs)-- const timeout = new Promise<false>(resolve => setTimeout(() => resolve(false), timeoutMs))const readiness = getConfigEditorConfigApi(target, true).then(response => !!response && response.code === 0).catch(() => false)diff --git a/project/aitoearn-web/src/app/i18n/locales/de/configManager.json b/project/aitoearn-web/src/app/i18n/locales/de/configManager.jsonindex 2af8c59d..4027a887 100644--- a/project/aitoearn-web/src/app/i18n/locales/de/configManager.json+++ b/project/aitoearn-web/src/app/i18n/locales/de/configManager.json@@ -242,7 +242,7 @@"restartSuccess": "Service is back online. Configuration is now effective.","dirtyHint": "There are unsaved changes.","cleanHint": "Configuration is up to date.",- "healthChecking": "Checking service health {{current}}/{{total}}...",+ "healthChecking": "Checking service recovery {{current}}/{{total}}...","jsonHint": "Der JSON-Modus wird als Objekt gespeichert. Ungültiges JSON wird nicht gesendet.","copyValueSuccess": "Configuration value copied","copyFailed": "Copy failed, please copy manually"@@ -252,8 +252,8 @@"validateFailed": "Configuration validation failed","saveFailed": "Failed to save configuration","restartFailed": "Failed to restart service",- "healthTimeout": "Service health check timed out",- "healthTimeoutDescription": "The restart request was sent, but /health did not recover in time. Please check the service manually.",+ "healthTimeout": "Service recovery check timed out",+ "healthTimeoutDescription": "The restart request was sent, but the account list API did not recover in time. Please check the service manually.","jsonInvalid": "Ungültige JSON-Konfiguration","jsonRootObject": "Der Root-Wert muss ein JSON-Objekt sein."},diff --git a/project/aitoearn-web/src/app/i18n/locales/en/configManager.json b/project/aitoearn-web/src/app/i18n/locales/en/configManager.jsonindex 159f4503..46187788 100644--- a/project/aitoearn-web/src/app/i18n/locales/en/configManager.json+++ b/project/aitoearn-web/src/app/i18n/locales/en/configManager.json@@ -242,7 +242,7 @@"restartSuccess": "Service is back online. Configuration is now effective.","dirtyHint": "There are unsaved changes.","cleanHint": "Configuration is up to date.",- "healthChecking": "Checking service health {{current}}/{{total}}...",+ "healthChecking": "Checking service recovery {{current}}/{{total}}...","jsonHint": "JSON mode saves as a JSON object. Invalid JSON will not be submitted.","copyValueSuccess": "Configuration value copied","copyFailed": "Copy failed, please copy manually"@@ -252,8 +252,8 @@"validateFailed": "Configuration validation failed","saveFailed": "Failed to save configuration","restartFailed": "Failed to restart service",- "healthTimeout": "Service health check timed out",- "healthTimeoutDescription": "The restart request was sent, but /health did not recover in time. Please check the service manually.",+ "healthTimeout": "Service recovery check timed out",+ "healthTimeoutDescription": "The restart request was sent, but the account list API did not recover in time. Please check the service manually.","jsonInvalid": "Invalid JSON configuration","jsonRootObject": "The root value must be a JSON object."},diff --git a/project/aitoearn-web/src/app/i18n/locales/fr/configManager.json b/project/aitoearn-web/src/app/i18n/locales/fr/configManager.jsonindex b997e80b..7fffdb51 100644--- a/project/aitoearn-web/src/app/i18n/locales/fr/configManager.json+++ b/project/aitoearn-web/src/app/i18n/locales/fr/configManager.json@@ -242,7 +242,7 @@"restartSuccess": "Service is back online. Configuration is now effective.","dirtyHint": "There are unsaved changes.","cleanHint": "Configuration is up to date.",- "healthChecking": "Checking service health {{current}}/{{total}}...",+ "healthChecking": "Checking service recovery {{current}}/{{total}}...","jsonHint": "Le mode JSON est enregistré comme objet. Un JSON invalide ne sera pas envoyé.","copyValueSuccess": "Configuration value copied","copyFailed": "Copy failed, please copy manually"@@ -252,8 +252,8 @@"validateFailed": "Configuration validation failed","saveFailed": "Failed to save configuration","restartFailed": "Failed to restart service",- "healthTimeout": "Service health check timed out",- "healthTimeoutDescription": "The restart request was sent, but /health did not recover in time. Please check the service manually.",+ "healthTimeout": "Service recovery check timed out",+ "healthTimeoutDescription": "The restart request was sent, but the account list API did not recover in time. Please check the service manually.","jsonInvalid": "Configuration JSON invalide","jsonRootObject": "La valeur racine doit être un objet JSON."},diff --git a/project/aitoearn-web/src/app/i18n/locales/ja/configManager.json b/project/aitoearn-web/src/app/i18n/locales/ja/configManager.jsonindex 156e43d4..d352f5bd 100644--- a/project/aitoearn-web/src/app/i18n/locales/ja/configManager.json+++ b/project/aitoearn-web/src/app/i18n/locales/ja/configManager.json@@ -242,7 +242,7 @@"restartSuccess": "Service is back online. Configuration is now effective.","dirtyHint": "There are unsaved changes.","cleanHint": "Configuration is up to date.",- "healthChecking": "Checking service health {{current}}/{{total}}...",+ "healthChecking": "Checking service recovery {{current}}/{{total}}...","jsonHint": "JSON モードはオブジェクトとして保存します。無効な JSON は送信されません。","copyValueSuccess": "Configuration value copied","copyFailed": "Copy failed, please copy manually"@@ -252,8 +252,8 @@"validateFailed": "Configuration validation failed","saveFailed": "Failed to save configuration","restartFailed": "Failed to restart service",- "healthTimeout": "Service health check timed out",- "healthTimeoutDescription": "The restart request was sent, but /health did not recover in time. Please check the service manually.",+ "healthTimeout": "Service recovery check timed out",+ "healthTimeoutDescription": "The restart request was sent, but the account list API did not recover in time. Please check the service manually.","jsonInvalid": "JSON 設定が無効です","jsonRootObject": "ルート値は JSON オブジェクトである必要があります。"},diff --git a/project/aitoearn-web/src/app/i18n/locales/ko/configManager.json b/project/aitoearn-web/src/app/i18n/locales/ko/configManager.jsonindex 08869a8f..8b97cdca 100644--- a/project/aitoearn-web/src/app/i18n/locales/ko/configManager.json+++ b/project/aitoearn-web/src/app/i18n/locales/ko/configManager.json@@ -242,7 +242,7 @@"restartSuccess": "Service is back online. Configuration is now effective.","dirtyHint": "There are unsaved changes.","cleanHint": "Configuration is up to date.",- "healthChecking": "Checking service health {{current}}/{{total}}...",+ "healthChecking": "Checking service recovery {{current}}/{{total}}...","jsonHint": "JSON 모드는 객체로 저장됩니다. 잘못된 JSON은 제출되지 않습니다.","copyValueSuccess": "Configuration value copied","copyFailed": "Copy failed, please copy manually"@@ -252,8 +252,8 @@"validateFailed": "Configuration validation failed","saveFailed": "Failed to save configuration","restartFailed": "Failed to restart service",- "healthTimeout": "Service health check timed out",- "healthTimeoutDescription": "The restart request was sent, but /health did not recover in time. Please check the service manually.",+ "healthTimeout": "Service recovery check timed out",+ "healthTimeoutDescription": "The restart request was sent, but the account list API did not recover in time. Please check the service manually.","jsonInvalid": "잘못된 JSON 구성","jsonRootObject": "루트 값은 JSON 객체여야 합니다."},diff --git a/project/aitoearn-web/src/app/i18n/locales/zh-CN/configManager.json b/project/aitoearn-web/src/app/i18n/locales/zh-CN/configManager.jsonindex c609918a..a7eb8282 100644--- a/project/aitoearn-web/src/app/i18n/locales/zh-CN/configManager.json+++ b/project/aitoearn-web/src/app/i18n/locales/zh-CN/configManager.json@@ -242,7 +242,7 @@"restartSuccess": "服务已恢复,配置已生效。","dirtyHint": "当前有未保存修改。","cleanHint": "配置已是最新状态。",- "healthChecking": "正在检查服务健康状态 {{current}}/{{total}}...",+ "healthChecking": "正在检查服务恢复状态 {{current}}/{{total}}...","jsonHint": "JSON 配置会按对象提交,格式错误时不会保存。","copyValueSuccess": "配置值已复制","copyFailed": "复制失败,请手动复制"@@ -252,8 +252,8 @@"validateFailed": "配置校验失败","saveFailed": "配置保存失败","restartFailed": "服务重启失败",- "healthTimeout": "服务健康检查超时",- "healthTimeoutDescription": "重启请求已发送,但 /health 未在预期时间内恢复,请手动检查服务状态。",+ "healthTimeout": "服务恢复检查超时",+ "healthTimeoutDescription": "重启请求已发送,但账号列表接口未在预期时间内恢复,请手动检查服务状态。","jsonInvalid": "JSON 配置格式错误","jsonRootObject": "根节点必须是 JSON 对象。"},diff --git a/project/aitoearn-web/src/app/layout/ConfigManagerDialog/README.md b/project/aitoearn-web/src/app/layout/ConfigManagerDialog/README.mdindex 897a65b5..2180e736 100644--- a/project/aitoearn-web/src/app/layout/ConfigManagerDialog/README.md+++ b/project/aitoearn-web/src/app/layout/ConfigManagerDialog/README.md@@ -6,7 +6,7 @@| 目录/文件 | 说明 || ------------------------------ | ---------------------------------------------------------------------------------- |-| `index.tsx` | 弹框入口,负责服务切换、加载、校验、保存、重启和健康检查流程。 |+| `index.tsx` | 弹框入口,负责服务切换、加载、校验、保存、重启和恢复检查流程。 || `components/ConfigSectionNav/` | 左侧配置分组目录,跟随右侧滚动高亮,点击触发锚点滚动。 || `components/ConfigFormPanel/` | 右侧配置表单滚动区域,每个分组作为锚点节点。 || `components/ConfigField/` | 可视化模式下的紧凑树形字段渲染,将对象、数组、字符串、数字、布尔值转换为表单控件。 |diff --git a/project/aitoearn-web/src/app/layout/ConfigManagerDialog/index.tsx b/project/aitoearn-web/src/app/layout/ConfigManagerDialog/index.tsxindex 413383de..d19561e1 100644--- a/project/aitoearn-web/src/app/layout/ConfigManagerDialog/index.tsx+++ b/project/aitoearn-web/src/app/layout/ConfigManagerDialog/index.tsx@@ -1,6 +1,6 @@/*** ConfigManagerDialog - 全局配置管理弹框- * 将后端配置对象转换为可编辑表单,并支持保存后重启与健康检查。+ * 将后端配置对象转换为可编辑表单,并支持保存后重启与恢复检查。*/'use client'@@ -44,7 +44,7 @@ interface ConfigManagerError {}const healthCheckIntervalMs = 1600-const healthCheckMaxAttempts = 30+const healthCheckMaxAttempts = 75const serverRelayPath: ConfigPath = ['relay']const aiRelayPath: ConfigPath = ['ai', 'relay']const serverRelayDefaultConfig: Record<string, unknown> = {diff --git a/project/aitoearn-web/src/app/layout/README.md b/project/aitoearn-web/src/app/layout/README.mdindex 62ffe67a..12f73fd5 100644--- a/project/aitoearn-web/src/app/layout/README.md+++ b/project/aitoearn-web/src/app/layout/README.md@@ -62,7 +62,7 @@ import { useConfigManagerDialogStore } from '@/store/configManagerDialog'- UI 实现在 `src/app/layout/ConfigManagerDialog/`。- 弹框内将后端配置对象转换为可编辑表单,不直接暴露 JSON 编辑。-- 保存后可重启服务,并通过 `/health` 健康检查确认服务恢复。+- 保存后可重启服务,并通过账号列表接口确认服务恢复。## routerData - 导航数据配置