add /watch; go mod tidy + replace gopiped/schema with local

This commit is contained in:
DarkCat09 2024-06-14 17:04:28 +04:00
parent d5755ca1d8
commit 6d63f2c96b
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3
3 changed files with 47 additions and 5 deletions

9
go.mod
View file

@ -3,9 +3,12 @@ module git.dc09.ru/gopiped/frontend
go 1.22.0
require (
git.dc09.ru/gopiped/schema v0.0.0-20240614121310-7c66910b64d9 // indirect
git.dc09.ru/gopiped/schema v0.0.0-20240614121310-7c66910b64d9
github.com/gofiber/fiber/v3 v3.0.0-beta.2
)
require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/gofiber/fiber/v3 v3.0.0-beta.2 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
@ -16,3 +19,5 @@ require (
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.21.0 // indirect
)
replace git.dc09.ru/gopiped/schema => ../schema

10
go.sum
View file

@ -1,7 +1,7 @@
git.dc09.ru/gopiped/schema v0.0.0-20240614121310-7c66910b64d9 h1:U3Ro84v2ipAFfwktwCSb40Wu3/LgcE78tpyJWdQIWjg=
git.dc09.ru/gopiped/schema v0.0.0-20240614121310-7c66910b64d9/go.mod h1:MELbPcvICrcm9fee/pB57V+1GceEiDnZxyrU8/RbBTk=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/fiber/v3 v3.0.0-beta.2 h1:mVVgt8PTaHGup3NGl/+7U7nEoZaXJ5OComV4E+HpAao=
github.com/gofiber/fiber/v3 v3.0.0-beta.2/go.mod h1:w7sdfTY0okjZ1oVH6rSOGvuACUIt0By1iK0HKUb3uqM=
github.com/gofiber/utils/v2 v2.0.0-beta.4 h1:1gjbVFFwVwUb9arPcqiB6iEjHBwo7cHsyS41NeIW3co=
@ -15,6 +15,10 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.54.0 h1:cCL+ZZR3z3HPLMVfEYVUMtJqVaui0+gu7Lx63unHwS0=
@ -25,3 +29,5 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

33
main.go
View file

@ -2,15 +2,46 @@ package main
import (
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/client"
"dc09.ru/piped/schema"
"git.dc09.ru/gopiped/schema/pubapi"
)
const BaseUrl = "https://e73z33t5.dc09.ru"
func main() {
app := fiber.New()
cc := client.New()
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)
}
})
app.Listen("127.0.0.1:4800", fiber.ListenConfig{
EnablePrefork: true,
})