From a64a40a236f3d90e48116ec16a35750dd642e53e Mon Sep 17 00:00:00 2001 From: Yuan Si Date: Thu, 30 Mar 2023 00:33:01 +0800 Subject: [PATCH] Add more apis Signed-off-by: Yuan Si --- handler/unit.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 7 ++++++ tools/tools.go | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 handler/unit.go diff --git a/handler/unit.go b/handler/unit.go new file mode 100644 index 0000000..49e3973 --- /dev/null +++ b/handler/unit.go @@ -0,0 +1,58 @@ +package handler + +import ( + "encoding/base64" + "fmt" + "honoka-chan/config" + "honoka-chan/database" + "honoka-chan/encrypt" + "honoka-chan/resp" + "honoka-chan/utils" + "net/http" + "time" + + "github.com/gin-gonic/gin" +) + +func SetDisplayRankHandler(ctx *gin.Context) { + reqTime := time.Now().Unix() + + authorizeStr := ctx.Request.Header["Authorize"] + authToken, err := utils.GetAuthorizeToken(authorizeStr) + if err != nil { + ctx.String(http.StatusForbidden, "Fuck you!") + return + } + userId := ctx.Request.Header[http.CanonicalHeaderKey("User-ID")] + if len(userId) == 0 { + ctx.String(http.StatusForbidden, "Fuck you!") + return + } + + if !database.MatchTokenUid(authToken, userId[0]) { + ctx.String(http.StatusForbidden, "Fuck you!") + return + } + + nonce, err := utils.GetAuthorizeNonce(authorizeStr) + if err != nil { + fmt.Println(err) + ctx.String(http.StatusForbidden, "Fuck you!") + return + } + nonce++ + + respTime := time.Now().Unix() + newAuthorizeStr := fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", respTime, authToken, nonce, userId[0], reqTime) + // fmt.Println(newAuthorizeStr) + + resp := resp.NotificationToken + xms := encrypt.RSA_Sign_SHA1([]byte(resp), "privatekey.pem") + xms64 := base64.RawStdEncoding.EncodeToString(xms) + + ctx.Header("Server-Version", config.Conf.Server.VersionNumber) + ctx.Header("user_id", userId[0]) + ctx.Header("authorize", newAuthorizeStr) + ctx.Header("X-Message-Sign", xms64) + ctx.String(http.StatusOK, resp) +} diff --git a/main.go b/main.go index b3abb47..16498ff 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "honoka-chan/sifcap" _ "honoka-chan/tools" "honoka-chan/xclog" + "net/http" "github.com/gin-gonic/gin" ) @@ -23,6 +24,10 @@ func main() { r := gin.Default() r.Use(middleware.KlabHeader) + r.Any("/", func(ctx *gin.Context) { + ctx.String(http.StatusOK, "Hello, world!") + }) + r.GET("/webview.php/announce/index", handler.AnnounceIndexHandler) r.POST("/main.php/login/authkey", handler.AuthKeyHandler) @@ -44,6 +49,8 @@ func main() { r.POST("/main.php/live/partyList", handler.PartyListHandler) r.POST("/main.php/live/play", handler.PlayLiveHandler) r.POST("/main.php/live/gameover", handler.GameOverHandler) + r.POST("/main.php/unit/setDisplayRank", handler.SetDisplayRankHandler) + r.POST("/main.php/unit/favorite", handler.SetDisplayRankHandler) r.Run(":8080") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") } diff --git a/tools/tools.go b/tools/tools.go index 54eef4e..4a9c0aa 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -5,5 +5,5 @@ func init() { AnalysisApi2Data("assets/api2.json") AnalysisApi3Data("assets/api3.json") // ListUnitData() - go SyncNotesList() + // go SyncNotesList() }