mirror of
https://github.com/SinTan1729/privtracker.git
synced 2024-12-25 15:08:35 -06:00
38 lines
735 B
Go
38 lines
735 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/jackpal/bencode-go"
|
|
)
|
|
|
|
type ScrapeRequest struct {
|
|
InfoHash string `query:"info_hash"`
|
|
}
|
|
|
|
type ScrapeResponse struct {
|
|
Files map[string]Stat `bencode:"files"`
|
|
}
|
|
|
|
type Stat struct {
|
|
Complete int `bencode:"complete"`
|
|
Incomplete int `bencode:"incomplete"`
|
|
// Downloaded uint `bencode:"downloaded"`
|
|
}
|
|
|
|
func scrape(c *fiber.Ctx) error {
|
|
var req ScrapeRequest
|
|
err := c.QueryParser(&req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
numSeeders, numLeechers := GetStats(c.Params("room"), req.InfoHash)
|
|
resp := ScrapeResponse{
|
|
Files: map[string]Stat{
|
|
req.InfoHash: {
|
|
Complete: numSeeders,
|
|
Incomplete: numLeechers,
|
|
},
|
|
},
|
|
}
|
|
return bencode.Marshal(c, resp)
|
|
}
|