add more routes

This commit is contained in:
2026-09-06 21:57:03 +08:00
parent 4688c10585
commit 5743a36f51
35 changed files with 202373 additions and 2 deletions

View File

@@ -0,0 +1,59 @@
package area
import (
"bdgrp_go/master"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, handle)
fmt.Println("Loaded:", path)
})
}
func handle(c *fiber.Ctx) error {
userid := c.Params("userid")
m := master.GetMaster()
areaMap := m["masterAreaMap"].(map[string]any)
entries := areaMap["entries"].(map[string]any)
// .filter(area.areaType === "common").map(...)
resultEntries := map[string]any{}
for areaId, v := range entries {
area := v.(map[string]any)
if area["areaType"] != "common" {
continue
}
resultEntries[areaId] = map[string]any{
"userId": userid,
"areaId": areaId,
}
}
data := map[string]any{
"registerTimeOpenAreaIdList": nil,
"userAreaStatusMap": map[string]any{
"entries": resultEntries,
},
}
encoded, err := pbutil.Encode("RegisterTimeOpenAreaResponse", data)
if err != nil {
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,69 @@
package bandstory
import (
"bdgrp_go/master"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, handle)
fmt.Println("Loaded:", path)
})
}
var bandStoryKeys = map[string]string{
"1": "masterPoppinPartyStoryMap",
"2": "masterAfterglowStoryMap",
"3": "masterHelloHappyWorldStoryMap",
"4": "masterPastelPalettesStoryMap",
"5": "masterRoseliaStoryMap",
"18": "masterRaiseASuilenStoryMap",
"21": "masterMorfonicaStoryMap",
"45": "masterMyGoStoryMap",
}
func handle(c *fiber.Ctx) error {
userid := c.Params("userid")
bandid := c.Params("bandid")
m := master.GetMaster()
key, _ := bandStoryKeys[bandid]
storyMap := m[key].(map[string]any)
entries := storyMap["entries"].(map[string]any)
var result []any
for _, v := range entries {
story := v.(map[string]any)
result = append(result, map[string]any{
"userId": userid,
"bandStoryId": story["bandStoryId"],
"bandId": story["bandId"],
"status": "already_read",
"seq": story["seq"],
})
}
data := map[string]any{
"entries": result,
}
encoded, err := pbutil.Encode("UserBandStoryList", data)
if err != nil {
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,55 @@
package device
import (
"bdgrp_go/db"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Put(path, updateDevice)
fmt.Println("Loaded:", path)
})
}
func updateDevice(c *fiber.Ctx) error {
decrypted, err := utils.Decrypt(c.Body())
if err != nil {
fmt.Println(err)
}
decoded, err := pbutil.Decode("DeviceInfoUpdateRequest", decrypted)
userid := c.Params("userid")
user := db.FindUser(userid)
user["deviceModel"] = decoded["deviceModel"]
user["operatingSystem"] = decoded["operatingSystem"]
db.Save()
data := map[string]any{
"deviceModel": user["deviceModel"],
"operatingSystem": user["operatingSystem"],
"clientVersion": user["clientVersion"],
}
encoded, err := pbutil.Encode("UserRegistration", data)
if err != nil {
fmt.Println(err)
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,40 @@
package param_userid
import (
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"time"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, liveBoost)
fmt.Println("Loaded:", path)
})
}
func liveBoost(c *fiber.Ctx) error {
data := map[string]any{
"userId": c.Params("userId"),
"count": 67,
"serverDate": time.Now().UnixMilli(),
"liveBoostBonusType": "default",
}
encoded, err := pbutil.Encode("UserLiveBoost", data)
if err != nil {
fmt.Println(err)
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,39 @@
package param_userid
import (
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, liveFever)
fmt.Println("Loaded:", path)
})
}
func liveFever(c *fiber.Ctx) error {
data := map[string]any {
"userId": c.Params("userId"),
"count": 67,
"inActivity": true,
"limit": 3,
}
encoded, err := pbutil.Encode("UserLiveFeverCount", data)
if err != nil {
fmt.Println(err)
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,38 @@
package param_userid
import (
"bdgrp_go/db"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Put(path, mainDeck)
fmt.Println("Loaded:", path)
})
}
func mainDeck(c *fiber.Ctx) error {
decrypted, err := utils.Decrypt(c.Body())
if err != nil {
fmt.Println(err)
}
decoded, err := pbutil.Decode("UserPutRequest", decrypted)
userid := c.Params("userid")
user := db.FindUser(userid)
user["mainDeck"] = decoded["mainDeck"]
db.Save()
return c.Send(nil)
}

View File

@@ -0,0 +1,93 @@
package param_userid
import (
"bdgrp_go/master"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"encoding/json"
"fmt"
"maps"
"os"
"path/filepath"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, handle)
fmt.Println("Loaded:", path)
})
}
func handle(c *fiber.Ctx) error {
userid := c.Params("userid")
m := master.GetMaster()
// 讀 pastEvents/{SERVER}.json
pastPath := filepath.Join("pastEvents", os.Getenv("SERVER")+".json")
pastData, err := os.ReadFile(pastPath)
if err != nil {
return c.Status(500).SendString("no past events")
}
var past map[string]any
json.Unmarshal(pastData, &past)
// masterEventStoryMemorialConfigMap.entries
configMap := m["masterEventStoryMemorialConfigMap"].(map[string]any)
entries := configMap["entries"].(map[string]any)
// pastEventStoryMap.entries
pastStoryMap := past["pastEventStoryMap"].(map[string]any)
pastEntries := pastStoryMap["entries"].(map[string]any)
// Object.fromEntries(Object.entries(...).map(...))
resultEntries := map[string]any{}
for eventId := range entries {
// Array.from({ length: ... }, (_, i) => ...)
var storyList []any
if pastEvent, ok := pastEntries[eventId].(map[string]any); ok {
if innerEntries, ok := pastEvent["entries"].([]any); ok {
for i := range innerEntries {
storyList = append(storyList, map[string]any{
"userId": userid,
"eventId": eventId,
"seq": i,
"status": "already_read",
})
}
}
}
resultEntries[eventId] = map[string]any{
"eventId": eventId,
"userEventStoryList": map[string]any{
"entries": storyList,
},
"isExistUnReadStory": false,
"isLocked": false,
}
}
// 合併 past(等同 ...past)
data := map[string]any{
"userEventStoryMemorialMap": map[string]any{
"entries": resultEntries,
},
}
maps.Copy(data, past)
encoded, err := pbutil.Encode("UserEventStoryMemorialResponse", data)
if err != nil {
return c.Status(500).SendString(err.Error())
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
return c.Status(500).SendString(err.Error())
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,20 @@
package param_userid
import (
"bdgrp_go/routes"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, recruitment)
fmt.Println("Loaded:", path)
})
}
func recruitment(c *fiber.Ctx) error {
return c.SendStatus(200)
}

View File

@@ -0,0 +1,20 @@
package music
import (
"bdgrp_go/routes"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Post(path, music)
fmt.Println("Loaded:", path)
})
}
func music(c *fiber.Ctx) error {
return c.SendStatus(200)
}

View File

@@ -0,0 +1,82 @@
package param_musicid
import (
"bdgrp_go/db"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"crypto/sha1"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Put(path, musicContinue)
fmt.Println("Loaded:", path)
})
}
func musicContinue(c *fiber.Ctx) error {
userid := c.Params("userid")
decrypted, err := utils.Decrypt(c.Body())
if err != nil {
fmt.Println(err)
}
decoded, err := pbutil.Decode("UserMusicContinueRequest", decrypted)
if err != nil {
fmt.Println(err)
}
user := db.FindUser(userid)
str := userid + decoded["continueCount"].(string) + decoded["continueTime"].(string)
data := map[string]any{
"userGamedata": map[string]any{
"userId": userid,
"rank": user["rank"],
"exp": user["exp"],
"coin": user["coin"],
"mainDeck": user["mainDeck"],
"paidStar": user["paidStar"],
"freeStar": user["freeStar"],
"seal": user["seal"],
"degree": user["degree"],
"publishTotalDeckPowerFlg": user["publishTotalDeckPowerFlg"],
"publishBandRankFlg": user["publishBandRankFlg"],
"publishMusicClearedFlg": user["publishMusicClearedFlg"],
"publishMusicFullComboFlg": user["publishMusicFullComboFlg"],
"publishHighScoreRatingFlg": user["publishHighScoreRatingFlg"],
"pooledExp": user["pooledExp"],
"totalExp": user["totalExp"],
"nextExp": user["nextExp"],
"publishUpdatedAtFlg": user["publishUpdatedAtFlg"],
"userPaidStarRecallResponse": nil,
"startDashLoginBonusReceiveFlg": user["startDashLoginBonusReceiveFlg"],
"publishMusicAllPerfectFlg": user["publishMusicAllPerfectFlg"],
"publishDeckRankFlg": user["publishDeckRankFlg"],
"publishStageAchievementConditionsFlg": user["publishStageAchievementConditionsFlg"],
"publishStageFriendRankingFlg": user["publishStageFriendRankingFlg"],
"publishCharacterRankFlg": user["publishCharacterRankFlg"],
"loginDays": user["loginDays"],
},
"continueHash": fmt.Sprintf("%x", sha1.Sum([]byte(str))),
}
encoded, err := pbutil.Encode("UserMusicContinueResponse", data)
if err != nil {
fmt.Println(err)
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,20 @@
package param_musicid
import (
"bdgrp_go/routes"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Post(path, retry)
fmt.Println("Loaded:", path)
})
}
func retry(c *fiber.Ctx) error {
return c.SendStatus(200)
}

View File

@@ -0,0 +1,40 @@
package param_userid
import (
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, present)
fmt.Println("Loaded:", path)
})
}
func present(c *fiber.Ctx) error {
data := map[string]any{
"pagination": map[string]any{
"start": 9223372036854775807,
"limit": c.Query("limit"),
"record": 0,
},
}
encoded, err := pbutil.Encode("UserPresentLimit", data)
if err != nil {
fmt.Println(err)
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
}
return c.Send(encrypted)
}

View File

@@ -0,0 +1,40 @@
package param_userid
import (
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Get(path, presentHistory)
fmt.Println("Loaded:", path)
})
}
func presentHistory(c *fiber.Ctx) error {
data := map[string]any{
"pagination": map[string]any{
"start": 9223372036854775807,
"limit": c.Query("limit"),
"record": 0,
},
}
encoded, err := pbutil.Encode("UserPresentHistoryList", data)
if err != nil {
fmt.Println(err)
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
}
return c.Send(encrypted)
}