mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 07:24:55 +08:00
feat(patch):统一清单驱动汉化发布
This commit is contained in:
+13
-2
@@ -1306,8 +1306,19 @@ func validateTranslationMemoryConfirmParams(params backendrpc.TranslationMemoryC
|
||||
|
||||
func validateLocalizedPublishParams(params backendrpc.LocalizedPublishParams) error {
|
||||
hasFile := strings.TrimSpace(params.TranslationFile) != ""
|
||||
if hasFile == params.FromWorker {
|
||||
return errors.New("localized publish requires exactly one of translation_file or from_worker")
|
||||
hasManifest := strings.TrimSpace(params.PatchManifest) != ""
|
||||
inputs := 0
|
||||
if hasFile {
|
||||
inputs++
|
||||
}
|
||||
if params.FromWorker {
|
||||
inputs++
|
||||
}
|
||||
if hasManifest {
|
||||
inputs++
|
||||
}
|
||||
if inputs != 1 {
|
||||
return errors.New("localized publish requires exactly one of translation_file, from_worker, or patch_manifest")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1954,6 +1954,7 @@ func TestAdminControlForwardsAllowlistedActions(t *testing.T) {
|
||||
{name: "translation glossary deprecate", action: "translation-glossary-deprecate", body: `{"term_id":"term-sensei","reviewer":"reviewer","reason":"retired"}`, rpcMethod: "translation.glossary.deprecate", call: "translation.glossary.deprecate"},
|
||||
{name: "translation glossary delete", action: "translation-glossary-delete", body: `{"term_id":"term-sensei","reviewer":"reviewer","reason":"duplicate"}`, rpcMethod: "translation.glossary.delete", call: "translation.glossary.delete"},
|
||||
{name: "localized publish", action: "localized-publish", body: `{"from_worker":true,"localized_release_id":"localized-1","force":true}`, rpcMethod: "localized.publish", call: "localized.publish"},
|
||||
{name: "localized patch manifest publish", action: "localized-publish", body: `{"patch_manifest":"/tmp/patch-manifest.json","localized_release_id":"localized-1"}`, rpcMethod: "localized.publish", call: "localized.publish"},
|
||||
{name: "localized rollback", action: "localized-rollback", body: `{"localized_release_id":"localized-1"}`, rpcMethod: "localized.rollback", call: "localized.rollback"},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
@@ -2041,6 +2042,14 @@ func TestAdminControlForwardsAllowlistedActions(t *testing.T) {
|
||||
if recorder.Code != http.StatusBadRequest {
|
||||
t.Fatalf("invalid localized publish status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
|
||||
request = httptest.NewRequest(http.MethodPost, "/admin/control/localized-publish", strings.NewReader(`{"from_worker":true,"patch_manifest":"/tmp/patch-manifest.json"}`))
|
||||
request.Header.Set("Authorization", "Bearer control-token")
|
||||
recorder = httptest.NewRecorder()
|
||||
s.Handler().ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusBadRequest {
|
||||
t.Fatalf("invalid localized patch manifest status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminLocalizedStatusRequiresAuthAndForwards(t *testing.T) {
|
||||
|
||||
@@ -730,6 +730,8 @@ paths:
|
||||
type: string
|
||||
from_worker:
|
||||
type: boolean
|
||||
patch_manifest:
|
||||
type: string
|
||||
localized_release_id:
|
||||
type: string
|
||||
responses:
|
||||
|
||||
Reference in New Issue
Block a user