add some routes

This commit is contained in:
2026-09-03 18:48:23 +08:00
parent c4ccba256d
commit 86cde9bb97
20 changed files with 520712 additions and 7 deletions

54
routes/api/cleanupinfo.go Normal file
View File

@@ -0,0 +1,54 @@
package api
import (
"bdgrp_go/routes/upstream"
"fmt"
"os"
"path/filepath"
"bdgrp_go/routes"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, cleanupinfo)
fmt.Println("Loaded:", path)
})
}
func cleanupinfo(c *fiber.Ctx) error {
server := os.Getenv("SERVER")
cachePath := filepath.Join("resp", server, "cleanupinfo.binpb")
headers := map[string]string{
"User-Agent": c.Get("User-Agent"),
"Content-Type": c.Get("Content-Type"),
"Accept": c.Get("Accept"),
"Accept-Encoding": c.Get("Accept-Encoding"),
"x-clientversion": c.Get("x-clientversion"),
}
if server == "CN" {
headers["x-platformid"] = c.Get("x-platformid")
headers["x-deviceid"] = c.Get("x-deviceid")
headers["x-channelid"] = c.Get("x-channelid")
headers["x-clientplatform"] = c.Get("x-clientplatform")
}
url := fmt.Sprintf("%s/api/application", upstream.BaseUrl())
data, err := upstream.Fetch(url, headers)
if err != nil {
// fallback 到 cache
data, err = os.ReadFile(cachePath)
if err != nil {
return c.Status(500).SendString("no cache available")
}
} else {
os.WriteFile(cachePath, data, 0644)
}
return c.Send(data)
}