pkgs/main.go

51 lines
909 B
Go

package main
import (
"fmt"
"git.ddd.rip/ptrcnull/pkgs/utils"
"github.com/gofiber/fiber/v2"
"net/http"
)
func main() {
app := fiber.New()
app.Get("/:file", func(ctx *fiber.Ctx) error {
file := ctx.Params("file")
res, err := http.Get("https://pkgs.alpinelinux.org/contents?file=" + file + "&path=&name=&branch=&arch=x86_64")
if err != nil {
return err
}
node, err := utils.Parse(res.Body)
if err != nil {
return err
}
tbody := node.QuerySelector("tbody")
if tbody == nil {
return fmt.Errorf("cannot find tbody")
}
//log.Println(tbody.Render())
reply := ""
tbody.ForEach(func(row *utils.Node) {
cells := row.Children()
if len(cells) == 0 {
return
}
if len(cells) < 5 {
reply = "Not found :("
return
}
reply += cells[1].Text() + "\n" + cells[0].Text() + "\n\n"
})
return ctx.SendString(reply)
})
panic(app.Listen(":8080"))
}