frontend/main.go

49 lines
918 B
Go
Raw Permalink Normal View History

2024-06-14 13:46:42 +03:00
package main
import (
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/client"
"git.dc09.ru/gopiped/schema/pubapi"
)
2024-06-14 13:46:42 +03:00
const BaseUrl = "https://e73z33t5.dc09.ru"
2024-06-14 13:46:42 +03:00
func main() {
app := fiber.New()
cc := client.New()
2024-06-14 13:46:42 +03:00
app.Get("/", func(c fiber.Ctx) error {
return c.SendString("dc09piped")
})
app.Get("/watch", func(c fiber.Ctx) error {
vid := c.Query("v")
// TODO: return error if vid == ""
listen := c.Query("listen") == "1"
resp, err := cc.Get(BaseUrl + "/streams/" + vid)
if err != nil {
return err
}
if resp.StatusCode() != 200 {
return c.Send(resp.Body())
}
var data pubapi.Streams
resp.JSON(&data)
// TODO: templating
// TODO: sort+filter streams
if listen {
return c.SendString(data.AudioStreams[0].Url)
} else {
return c.SendString(data.VideoStreams[0].Url)
}
})
2024-06-14 13:46:42 +03:00
app.Listen("127.0.0.1:4800", fiber.ListenConfig{
EnablePrefork: true,
})
}