All checks were successful
Build and publish the docker image / build (push) Successful in 58s
Signed-off-by: ngn <ngn@ngn.tf>
47 lines
935 B
Go
47 lines
935 B
Go
package routes
|
|
|
|
import (
|
|
"git.ngn.tf/ngn/tren/extract"
|
|
"git.ngn.tf/ngn/tren/util"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type translate_form struct {
|
|
Dictionary string
|
|
Term string
|
|
}
|
|
|
|
func POST_translate(c *fiber.Ctx) error {
|
|
var (
|
|
extractor *extract.Extractor
|
|
trans *extract.Translation
|
|
form translate_form
|
|
err error
|
|
)
|
|
|
|
extractor = c.Locals("extractor").(*extract.Extractor)
|
|
|
|
if err = c.BodyParser(&form); err != nil {
|
|
return util.RenderError(c, 400)
|
|
}
|
|
|
|
if form.Dictionary == "" || form.Term == "" {
|
|
return util.RenderError(c, 400)
|
|
}
|
|
|
|
if trans, err = extractor.Translate(form.Dictionary, form.Term); err != nil {
|
|
return util.RenderError(c, 500, err)
|
|
}
|
|
|
|
if trans == nil {
|
|
return util.RenderError(c, 400)
|
|
}
|
|
|
|
return util.Render(c, "translate", fiber.Map{
|
|
"term": form.Term,
|
|
"fields": trans.Fields,
|
|
"entries": trans.Entries,
|
|
"suggestions": trans.Suggestions,
|
|
})
|
|
}
|