mirror of
https://github.com/keven1024/015.git
synced 2026-06-08 21:34:33 +00:00
feat(backend): add text translation handler and update task mapping for new translation functionality
This commit is contained in:
45
backend/internal/controllers/task/text.go
Normal file
45
backend/internal/controllers/task/text.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
)
|
||||
|
||||
var validProviders = map[string]bool{
|
||||
"google": true,
|
||||
"microsoft": true,
|
||||
"deeplx": true,
|
||||
"deepseek": true,
|
||||
}
|
||||
|
||||
var validSources = map[string]bool{
|
||||
"auto": true,
|
||||
"zh-CN": true,
|
||||
"en": true,
|
||||
"ja": true,
|
||||
"ko": true,
|
||||
}
|
||||
|
||||
type TranslateTextRequest struct {
|
||||
Text string `json:"text"`
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
Provider string `json:"provider"`
|
||||
}
|
||||
|
||||
func HandleTextTranslate(c *echo.Context) ([]byte, error) {
|
||||
r := new(TranslateTextRequest)
|
||||
if err := c.Bind(r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.Text == "" || r.Target == "" || !validProviders[r.Provider] || !validSources[r.Source] {
|
||||
return nil, ErrInvalidRequest
|
||||
}
|
||||
return json.Marshal(map[string]any{
|
||||
"text": r.Text,
|
||||
"source": r.Source,
|
||||
"target": r.Target,
|
||||
"provider": r.Provider,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user