51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package system
|
|
|
|
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, config)
|
|
fmt.Println("Loaded:", path)
|
|
})
|
|
}
|
|
|
|
func config(c *fiber.Ctx) error {
|
|
server := os.Getenv("SERVER")
|
|
cachePath := filepath.Join("resp", server, "config.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"),
|
|
"x-platformid": c.Get("x-platformid"),
|
|
"x-deviceid": c.Get("x-deviceid"),
|
|
"x-channelid": c.Get("x-channelid"),
|
|
"x-clientplatform": c.Get("x-clientplatform"),
|
|
}
|
|
|
|
data, err := upstream.Fetch("https://l3-prod-all-bd.bilibiligame.net/api/system/config", 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)
|
|
}
|