Просмотр исходного кода

⚡️ (term): 社区译名表不再返回 id

/v3/glossaries/community 整表上万条,每条一个 uuid,是响应里最大、最压不动的一块;
v6、mobile、wikipali-plugins 都不用 community 的 id。grammar 表照旧给 id
(v6 语法悬停、语法手册、逐词语法匹配凭它取 /v3/terms/{id})。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 11 часов назад
Родитель
Сommit
13265ec081

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
CLAUDE.md


+ 5 - 1
api-test/cases/17_glossaries.php

@@ -17,7 +17,7 @@ test('GET /v3/glossaries/community?lang=zh-Hans → 200,整表带 meta', funct
     assert_eq(count($res['body']['data']), $res['body']['meta']['total'], '整表不分页:total 与条数相等');
     assert_eq(count($res['body']['data']), $res['body']['meta']['total'], '整表不分页:total 与条数相等');
     $first = $res['body']['data'][0] ?? null;
     $first = $res['body']['data'][0] ?? null;
     if ($first) {
     if ($first) {
-        assert_eq(['id', 'word', 'tag', 'meaning', 'other_meaning'], array_keys($first), '条目字段');
+        assert_eq(['word', 'tag', 'meaning', 'other_meaning'], array_keys($first), '条目字段(community 不给 id)');
     }
     }
 });
 });
 
 
@@ -25,6 +25,10 @@ test('GET /v3/glossaries/grammar?lang=xx(没有这种语言的表)→ 200,
     $res = raw('GET', '/v3/glossaries/grammar', ['lang' => 'xx']);
     $res = raw('GET', '/v3/glossaries/grammar', ['lang' => 'xx']);
     assert_status(200, $res, 'grammar glossary 回退');
     assert_status(200, $res, 'grammar glossary 回退');
     assert_eq('en', $res['body']['meta']['lang'] ?? null, '回退语言');
     assert_eq('en', $res['body']['meta']['lang'] ?? null, '回退语言');
+    $first = $res['body']['data'][0] ?? null;
+    if ($first) {
+        assert_has_key('id', $first, 'grammar 条目带 id(v6 凭它取术语正文)');
+    }
 });
 });
 
 
 test('GET /v3/glossaries/{非法 kind} → 404;lang 格式不对 → 422', function () {
 test('GET /v3/glossaries/{非法 kind} → 404;lang 格式不对 → 422', function () {

+ 1 - 1
api-test/client/lib/Model/GetApiV3GlossariesKind200ResponseDataInner.php

@@ -330,7 +330,7 @@ class GetApiV3GlossariesKind200ResponseDataInner implements ModelInterface, Arra
     /**
     /**
      * Sets id
      * Sets id
      *
      *
-     * @param string|null $id id
+     * @param string|null $id 仅在部分查询口径下返回。
      *
      *
      * @return self
      * @return self
      */
      */

+ 1 - 1
api-v13/app/Http/Controllers/V3/GlossaryController.php

@@ -21,7 +21,7 @@ class GlossaryController extends Controller
      * 术语词汇表
      * 术语词汇表
      *
      *
      * 整表返回、不分页(客户端启动时拉一次,本地查词)。`meta.lang` 是实际用到的语言:
      * 整表返回、不分页(客户端启动时拉一次,本地查词)。`meta.lang` 是实际用到的语言:
-     * 该语言没有这张表时回退到英文。
+     * 该语言没有这张表时回退到英文。条目的 `id`(术语 guid)只有 grammar 表给,community 表不给(省流量)。
      *
      *
      * @unauthenticated
      * @unauthenticated
      *
      *

+ 6 - 3
api-v13/app/Http/Resources/V3/GlossaryEntryResource.php

@@ -6,7 +6,10 @@ use App\Models\DhammaTerm;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 
 
 /**
 /**
- * 词汇表的一条(`dhamma_terms` 表里系统 channel 的术语)。只给客户端本地查词要用的字段;`id` 是术语 guid。
+ * 词汇表的一条(`dhamma_terms` 表里系统 channel 的术语)。只给客户端本地查词要用的字段。
+ *
+ * `id`(术语 guid)只在语法术语表(grammar)里给:v6 悬停 / 语法手册凭它取 `/v3/terms/{id}`。
+ * 社区译名表(community)没有任何客户端用 id,而上万个 uuid 是整张表里最大、最压不动的一块,所以不给。
  *
  *
  * @mixin DhammaTerm
  * @mixin DhammaTerm
  */
  */
@@ -14,7 +17,7 @@ class GlossaryEntryResource extends BaseResource
 {
 {
     /**
     /**
      * @return array{
      * @return array{
-     *     id: string,
+     *     id?: string,
      *     word: string,
      *     word: string,
      *     tag: string|null,
      *     tag: string|null,
      *     meaning: string,
      *     meaning: string,
@@ -27,7 +30,7 @@ class GlossaryEntryResource extends BaseResource
         $other = trim((string) $this->other_meaning);
         $other = trim((string) $this->other_meaning);
 
 
         return [
         return [
-            'id' => (string) $this->guid,
+            'id' => $this->when($request->route('kind') === 'grammar', fn () => (string) $this->guid),
             'word' => (string) $this->word,
             'word' => (string) $this->word,
             'tag' => $tag === '' ? null : $tag,
             'tag' => $tag === '' ? null : $tag,
             'meaning' => (string) $this->meaning,
             'meaning' => (string) $this->meaning,

+ 12 - 6
api-v13/tests/Feature/GlossaryV3Test.php

@@ -78,12 +78,18 @@ it('rejects an unknown kind or a malformed language', function () {
         ->assertUnprocessable()->assertJsonValidationErrors('lang');
         ->assertUnprocessable()->assertJsonValidationErrors('lang');
 });
 });
 
 
-it('never exposes the auto-increment id of the terms', function () {
-    $zh = makeChannel(config('mint.admin.root_uuid'), '_community_term_zh-hans_');
-    $term = glossaryTerm($zh, 'dhamma');
+it('gives the term guid only in the grammar glossary, and never the auto-increment id', function () {
+    $root = config('mint.admin.root_uuid');
+    $grammar = glossaryTerm(makeChannel($root, '_System_Grammar_Term_zh-hans_'), 'vibhatti');
+    $community = glossaryTerm(makeChannel($root, '_community_term_zh-hans_'), 'dhamma');
 
 
-    $row = $this->getJson('/api/v3/glossaries/community?lang=zh-Hans')->json('data.0');
+    $row = $this->getJson('/api/v3/glossaries/grammar?lang=zh-Hans')->json('data.0');
     expect(array_keys($row))->toBe(['id', 'word', 'tag', 'meaning', 'other_meaning'])
     expect(array_keys($row))->toBe(['id', 'word', 'tag', 'meaning', 'other_meaning'])
-        ->and($row['id'])->toBe($term->guid)
-        ->and(json_encode($row))->not->toContain((string) $term->id);
+        ->and($row['id'])->toBe($grammar->guid)
+        ->and(json_encode($row))->not->toContain((string) $grammar->id);
+
+    $row = $this->getJson('/api/v3/glossaries/community?lang=zh-Hans')->json('data.0');
+    expect(array_keys($row))->toBe(['word', 'tag', 'meaning', 'other_meaning'])
+        ->and(json_encode($row))->not->toContain($community->guid)
+        ->and(json_encode($row))->not->toContain((string) $community->id);
 });
 });

+ 2 - 1
dashboard-v6/src/api/schema.d.ts

@@ -8564,7 +8564,7 @@ export interface paths {
         /**
         /**
          * 术语词汇表
          * 术语词汇表
          * @description 整表返回、不分页(客户端启动时拉一次,本地查词)。`meta.lang` 是实际用到的语言:
          * @description 整表返回、不分页(客户端启动时拉一次,本地查词)。`meta.lang` 是实际用到的语言:
-         *     该语言没有这张表时回退到英文。
+         *     该语言没有这张表时回退到英文。条目的 `id`(术语 guid)只有 grammar 表给,community 表不给(省流量)。
          *
          *
          *     实现:`V3\GlossaryController@__invoke`
          *     实现:`V3\GlossaryController@__invoke`
          */
          */
@@ -39162,6 +39162,7 @@ export interface operations {
                 content: {
                 content: {
                     "application/json": {
                     "application/json": {
                         data?: {
                         data?: {
+                            /** @description 仅在部分查询口径下返回。 */
                             id?: string;
                             id?: string;
                             word?: string;
                             word?: string;
                             tag?: string | null;
                             tag?: string | null;

+ 2 - 1
openapi/public/assets/protocol/resources/auto/v3-glossaries-kind.yaml

@@ -6,7 +6,7 @@ get:
   operationId: get_api_v3_glossaries_kind_
   operationId: get_api_v3_glossaries_kind_
   description: |-
   description: |-
     整表返回、不分页(客户端启动时拉一次,本地查词)。`meta.lang` 是实际用到的语言:
     整表返回、不分页(客户端启动时拉一次,本地查词)。`meta.lang` 是实际用到的语言:
-    该语言没有这张表时回退到英文。
+    该语言没有这张表时回退到英文。条目的 `id`(术语 guid)只有 grammar 表给,community 表不给(省流量)。
 
 
     实现:`V3\GlossaryController@__invoke`
     实现:`V3\GlossaryController@__invoke`
   security:
   security:
@@ -45,6 +45,7 @@ get:
                   properties:
                   properties:
                     id:
                     id:
                       type: string
                       type: string
+                      description: 仅在部分查询口径下返回。
                     word:
                     word:
                       type: string
                       type: string
                     tag:
                     tag:

Некоторые файлы не были показаны из-за большого количества измененных файлов