mozhi/pages/api.go

71 lines
1.9 KiB
Go
Raw Normal View History

2023-07-06 10:54:45 +00:00
package pages
import (
"codeberg.org/aryak/simplytranslate/utils"
"github.com/gofiber/fiber/v2"
)
func HandleSourceLanguages(c *fiber.Ctx) error {
engine := c.Query("engine")
if engine == "" {
return c.SendStatus(fiber.StatusBadRequest)
}
var data []utils.List
if engine == "google" {
data = utils.LangListGoogle("sl")
} else if engine == "libre" {
data = utils.LangListLibreTranslate("sl")
} else if engine == "reverso" {
data = utils.LangListReverso("sl")
} else if engine == "deepl" {
data = utils.LangListDeepl("sl")
2023-07-22 05:42:26 +00:00
} else if engine == "watson" {
data = utils.LangListWatson("sl")
2023-07-22 14:22:38 +00:00
} else if engine == "yandex" {
data = utils.LangListYandex("sl")
}
2023-07-06 10:54:45 +00:00
return c.JSON(data)
}
func HandleTargetLanguages(c *fiber.Ctx) error {
engine := c.Query("engine")
if engine == "" {
return c.SendStatus(fiber.StatusBadRequest)
}
var data []utils.List
if engine == "google" {
data = utils.LangListGoogle("tl")
} else if engine == "libre" {
data = utils.LangListLibreTranslate("sl")
} else if engine == "reverso" {
data = utils.LangListReverso("tl")
} else if engine == "deepl" {
data = utils.LangListDeepl("tl")
2023-07-22 05:42:26 +00:00
} else if engine == "watson" {
data = utils.LangListWatson("tl")
2023-07-22 14:22:38 +00:00
} else if engine == "yandex" {
data = utils.LangListYandex("tl")
}
2023-07-06 10:54:45 +00:00
return c.JSON(data)
}
func HandleTTS(c *fiber.Ctx) error {
engine := c.Query("engine")
lang := c.Query("lang")
2023-07-22 14:24:15 +00:00
text := c.Query("text")
2023-07-06 10:54:45 +00:00
// Why does go not have an andor statement :(
if engine == "" {
return c.SendStatus(fiber.StatusBadRequest)
} else if text == "" {
return c.SendStatus(fiber.StatusBadRequest)
} else if lang == "" {
return c.SendStatus(fiber.StatusBadRequest)
}
var data string
if engine == "google" {
data = utils.TTSGoogle(lang, text)
} else if engine == "reverso" {
data = utils.TTSReverso(lang, text)
}
2023-07-22 14:24:15 +00:00
c.Set("Content-Type", "audio/mpeg")
2023-07-06 10:54:45 +00:00
return c.Send([]byte(data))
}