add some routes

This commit is contained in:
2026-09-03 18:48:23 +08:00
parent 3004676239
commit a1569590bc
18 changed files with 520697 additions and 7 deletions

20
routes/api/acdm/userid.go Normal file
View File

@@ -0,0 +1,20 @@
package acdm
import (
"fmt"
"bdgrp_go/routes"
"github.com/gofiber/fiber/v2"
)
func init() {
routes.Register(func(app *fiber.App) {
app.Get("/api/acdm/:userid", acdm)
fmt.Println("Loaded: /api/acdm/:userid")
})
}
func acdm(c *fiber.Ctx) error {
return c.SendString("")
}

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

@@ -0,0 +1,54 @@
package api
import (
"fmt"
"os"
"path/filepath"
"bdgrp_go/routes"
"bdgrp_go/routes/upstream"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, application)
fmt.Println("Loaded:", path)
})
}
func application(c *fiber.Ctx) error {
server := os.Getenv("SERVER")
cachePath := filepath.Join("resp", server, "application.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)
}

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)
}

View File

@@ -0,0 +1,54 @@
package information
import (
"fmt"
"os"
"path/filepath"
"bdgrp_go/routes"
"bdgrp_go/routes/upstream"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, application)
fmt.Println("Loaded:", path)
})
}
func application(c *fiber.Ctx) error {
server := os.Getenv("SERVER")
cachePath := filepath.Join("resp", server, "overview.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/information/overview", 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)
}

View File

@@ -0,0 +1,57 @@
package system
import (
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"os"
"strconv"
"time"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, application)
fmt.Println("Loaded:", path)
})
}
func application(c *fiber.Ctx) error {
var offset int
server := os.Getenv("SERVER")
switch server {
case "TW", "CN":
offset = 28800000
break
case "JP":
offset = 32400000
break
case "GL":
offset = 0
break
}
data := map[string]any{
"serverDate": strconv.FormatInt(time.Now().Add(27*time.Hour).UnixMilli(), 10),
"timeZoneRawOffset": offset,
}
encoded, err := pbutil.Encode("ServerSystem", data)
if err != nil {
fmt.Println(err)
return c.Status(500).SendString("")
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,50 @@
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)
}

22
routes/helper.go Normal file
View File

@@ -0,0 +1,22 @@
package routes
import (
"runtime"
"strings"
)
func PathOf() string {
_, file, _, _ := runtime.Caller(1)
// 取 routes/ 之後的部分
idx := strings.Index(file, "routes/")
if idx == -1 {
return "/"
}
path := file[idx+len("routes"):]
// 去掉 .go
path = strings.TrimSuffix(path, ".go")
return path
}

View File

@@ -0,0 +1,31 @@
package upstream
import (
"io"
"net/http"
"os"
)
var BaseUrls = map[string]string{
"TW": "https://v1010-bd.mobimon.com.tw",
"JP": "https://api.garupa.jp",
"GL": "https://api.app-bang-dream-gbp.com",
"CN": "https://l3-prod-all-bd.bilibiligame.net",
}
func Fetch(url string, headers map[string]string) ([]byte, error) {
req, _ := http.NewRequest("GET", url, nil)
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return io.ReadAll(resp.Body)
}
func BaseUrl() string {
return BaseUrls[os.Getenv("SERVER")]
}