mx-space / mx-space/core

Admin 后台中,翻译词条页面中“生成词条”按钮失效

Open
#2,817 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
558
Forks
156
Avg merge
10h 57m
Merged PRs (30d)
5

Description

Describe the bug

@mx-space/core 14.8.0 自带的 Admin 后台中,点击翻译词条页面的“生成词条”按钮后,会提示 Invalid input,无法生成词条。


以下内容来自 ChatGPT:

Bug 描述

Admin 实际发送的请求为:

POST /api/v3/ai/translations/entries/generate
Content-Type: application/json

null

服务器随后返回:

422 Unprocessable Entity

从代码来看,原因可能是:

  1. AiTranslationEntriesRouteView.tsx 调用 generateTranslationEntries() 时没有传入参数。
  2. Admin 的 API 封装使用了 data ?? null,因此请求体被序列化成了 null
  3. 后端使用的 GenerateEntriesSchema 可以把缺失的请求体默认为 {},但不接受 null

发送空对象或者合法参数时,接口可以正常工作:

{
  "keyPaths": ["post.tag"],
  "targetLangs": ["zh"]
}

在我的实例中,上面的请求成功生成了 26 个词条:

{
  "created": 26,
  "skipped": 0
}

另外还有一个相关的 Admin UI 遗漏:Core 的后端 Schema 已经支持 post.tag,但 Admin 侧的 TranslationEntryKeyPath 类型和词条类型筛选选项中没有包含 post.tag。因此,即使已经成功生成博文标签词条,也无法在后台筛选该类型。

预期行为
  • 点击“生成词条”后,应发送 {} 或者不发送请求体。
  • 服务器应根据当前配置正常生成翻译词条。
  • 词条类型筛选中应包含“博文标签”或 post.tag
实际行为
  • Admin 发送的请求体是 null
  • 服务器返回 422 Invalid input
  • 翻译词条没有生成。
  • 后台筛选选项中没有 post.tag
可能的修复方式

Admin 可以在没有传入参数时发送空对象:

data ?? {}

另一种方式是在后端 Schema 中将 null 也规范化为 {}

同时,Admin 侧的词条类型定义和筛选选项也需要加入:

'post.tag'

相关功能实现:#2816。

Reproduction
  1. 配置一个可以正常工作的 AI 翻译服务和目标语言。 2. 打开“AI → 翻译词条”页面。 3. 点击“生成词条”。 4. 页面提示 Invalid input。 5. 检查网络请求,可以看到 POST /api/v3/ai/translations/entries/generate 返回 422,JSON 请求体为 null
System Info
Core: @mx-space/core 14.8.0
Admin: Core 14.8.0 自带版本
部署方式: Docker,innei/mx-server:latest
API Base: /api/v3

Node.js: 26.7.0
pnpm: 11.25.0

API 根接口返回:
  name: @mx-space/core
  version: 14.8.0
Validations
  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AiTranslationEntriesRouteView.tsx and the Admin API wrapper to trace the request body for generateTranslationEntries(). Then inspect GenerateEntriesSchema and the TranslationEntryKeyPath type and filter options. Done means generation no longer sends null, the request succeeds, and post.tag appears as a selectable entry type; run the translation-entry tests if present.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, frontend, internationalization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.