mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 06:34:54 +08:00
@@ -50,6 +50,7 @@ func (s *Server) handleAdminIndex(w http.ResponseWriter, r *http.Request) {
|
||||
"/admin/control/schedule-remove",
|
||||
"/admin/control/schedule-run",
|
||||
"/admin/control/translation-task-update",
|
||||
"/admin/control/translation-proofread",
|
||||
},
|
||||
}
|
||||
if r.Method == http.MethodHead {
|
||||
@@ -81,6 +82,10 @@ func (s *Server) handleAdminControl(w http.ResponseWriter, r *http.Request) {
|
||||
s.handleAdminTranslationTaskUpdate(w, r)
|
||||
return
|
||||
}
|
||||
if action == "translation-proofread" {
|
||||
s.handleAdminTranslationProofread(w, r)
|
||||
return
|
||||
}
|
||||
request, ok := decodeAdminControlRequest(w, r)
|
||||
if !ok {
|
||||
return
|
||||
@@ -182,6 +187,26 @@ func (s *Server) handleAdminTranslationTaskUpdate(w http.ResponseWriter, r *http
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleAdminTranslationProofread(w http.ResponseWriter, r *http.Request) {
|
||||
backend, ok := s.backend.(TranslationBackend)
|
||||
if !ok || backend == nil {
|
||||
writeErrorJSON(w, http.StatusServiceUnavailable, "translation_backend_unavailable", "Rust bat translation backend is unavailable")
|
||||
return
|
||||
}
|
||||
result, err := backend.TranslationProofread(r.Context())
|
||||
if err != nil {
|
||||
s.writeControlBackendError(w, "translation-proofread", err)
|
||||
return
|
||||
}
|
||||
writeNoStoreJSON(w, http.StatusAccepted, AdminControlResponse{
|
||||
Service: "bat-api",
|
||||
Action: "translation-proofread",
|
||||
RPCMethod: "translation.proofread",
|
||||
Status: "accepted",
|
||||
Result: result,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleAdminSchedules(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||
writeErrorJSON(w, http.StatusMethodNotAllowed, "method_not_allowed", "method not allowed")
|
||||
|
||||
@@ -593,6 +593,11 @@ func (b *controlBackend) TranslationTaskUpdate(ctx context.Context, params backe
|
||||
return json.RawMessage(`{"task_status":"` + params.Status + `"}`), nil
|
||||
}
|
||||
|
||||
func (b *controlBackend) TranslationProofread(ctx context.Context) (json.RawMessage, error) {
|
||||
b.calls = append(b.calls, "translation.proofread")
|
||||
return json.RawMessage(`{"translation_workflow_status":"manual_proofreading"}`), nil
|
||||
}
|
||||
|
||||
type scheduleBackend struct {
|
||||
*controlBackend
|
||||
scheduleCalls []string
|
||||
@@ -1156,6 +1161,7 @@ func TestAdminControlForwardsAllowlistedActions(t *testing.T) {
|
||||
{name: "repair", action: "repair", rpcMethod: "resource.repair", call: "resource.repair"},
|
||||
{name: "catalog refresh", action: "catalog-refresh", rpcMethod: "catalog.refresh", call: "catalog.refresh"},
|
||||
{name: "translation task update", action: "translation-task-update", body: `{"task_id":"textunit/v-current/Scenario","status":"failed","failure_reason":"provider rejected payload","provider_run_id":"provider-run-1"}`, rpcMethod: "translation.task.update", call: "translation.task.update"},
|
||||
{name: "translation proofread", action: "translation-proofread", rpcMethod: "translation.proofread", call: "translation.proofread"},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
@@ -148,7 +148,7 @@ paths:
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
enum: [reload, refresh, restart, sync, verify, repair, catalog-refresh, schedule-add, schedule-update, schedule-remove, schedule-run, translation-task-update]
|
||||
enum: [reload, refresh, restart, sync, verify, repair, catalog-refresh, schedule-add, schedule-update, schedule-remove, schedule-run, translation-task-update, translation-proofread]
|
||||
requestBody:
|
||||
required: false
|
||||
content:
|
||||
|
||||
@@ -53,6 +53,7 @@ type ScheduleBackend interface {
|
||||
// by the dashboard. It does not create arbitrary translation jobs.
|
||||
type TranslationBackend interface {
|
||||
TranslationTaskUpdate(ctx context.Context, params backendrpc.TranslationTaskUpdateParams) (json.RawMessage, error)
|
||||
TranslationProofread(ctx context.Context) (json.RawMessage, error)
|
||||
}
|
||||
|
||||
// RPCClient adapts *backendrpc.Client to Backend.
|
||||
@@ -114,6 +115,10 @@ func (r RPCClient) ScheduleRun(ctx context.Context, params backendrpc.ScheduleRu
|
||||
func (r RPCClient) TranslationTaskUpdate(ctx context.Context, params backendrpc.TranslationTaskUpdateParams) (json.RawMessage, error) {
|
||||
return r.Client.TranslationTaskUpdate(ctx, params)
|
||||
}
|
||||
|
||||
func (r RPCClient) TranslationProofread(ctx context.Context) (json.RawMessage, error) {
|
||||
return r.Client.TranslationProofread(ctx)
|
||||
}
|
||||
func (r RPCClient) ParseStatus(ctx context.Context) (json.RawMessage, error) {
|
||||
return r.Client.ParseStatus(ctx)
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ type rpcRequest struct {
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
ID uint64 `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Params any `json:"params,omitempty"`
|
||||
Params any `json:"params"`
|
||||
}
|
||||
|
||||
type rpcResponse struct {
|
||||
@@ -273,6 +273,12 @@ type TranslationTaskUpdateParams struct {
|
||||
ProviderRunID string `json:"provider_run_id,omitempty"`
|
||||
}
|
||||
|
||||
// TranslationProofread marks the current localized workflow as manual
|
||||
// proofreading. Rust owns the persisted localized state.
|
||||
func (c *Client) TranslationProofread(ctx context.Context) (json.RawMessage, error) {
|
||||
return c.rawData(ctx, "translation.proofread", nil)
|
||||
}
|
||||
|
||||
// Ack is returned by accepted daemon control methods.
|
||||
type Ack struct {
|
||||
Command string `json:"command"`
|
||||
|
||||
@@ -375,6 +375,35 @@ func TestTranslationTaskUpdateSendsWorkerParams(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranslationProofreadUsesRustMethod(t *testing.T) {
|
||||
client := newTestClient(t, func(t *testing.T, req testRequest) testResponse {
|
||||
if req.Method != "translation.proofread" {
|
||||
t.Fatalf("method = %s", req.Method)
|
||||
}
|
||||
if string(req.Params) != "null" {
|
||||
t.Fatalf("params = %s, want null", req.Params)
|
||||
}
|
||||
return testResponse{
|
||||
Result: testEnvelope{
|
||||
OK: true,
|
||||
Status: "ok",
|
||||
RequestID: "req-test-translation-proofread",
|
||||
Data: map[string]any{
|
||||
"translation_workflow_status": "manual_proofreading",
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
raw, err := client.TranslationProofread(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("TranslationProofread error: %v", err)
|
||||
}
|
||||
if !json.Valid(raw) {
|
||||
t.Fatalf("invalid raw JSON: %s", string(raw))
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplicationErrorReturnsAPIError(t *testing.T) {
|
||||
client := newTestClient(t, func(t *testing.T, req testRequest) testResponse {
|
||||
if req.Method != "task.status" {
|
||||
|
||||
Reference in New Issue
Block a user