Add more apis

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2023-03-30 00:33:46 +08:00
parent 2bdcc043ca
commit a64a40a236
3 changed files with 66 additions and 1 deletions
+58
View File
@@ -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)
}
+7
View File
@@ -7,6 +7,7 @@ import (
"honoka-chan/sifcap" "honoka-chan/sifcap"
_ "honoka-chan/tools" _ "honoka-chan/tools"
"honoka-chan/xclog" "honoka-chan/xclog"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -23,6 +24,10 @@ func main() {
r := gin.Default() r := gin.Default()
r.Use(middleware.KlabHeader) 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.GET("/webview.php/announce/index", handler.AnnounceIndexHandler)
r.POST("/main.php/login/authkey", handler.AuthKeyHandler) 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/partyList", handler.PartyListHandler)
r.POST("/main.php/live/play", handler.PlayLiveHandler) r.POST("/main.php/live/play", handler.PlayLiveHandler)
r.POST("/main.php/live/gameover", handler.GameOverHandler) 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") r.Run(":8080") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
} }
+1 -1
View File
@@ -5,5 +5,5 @@ func init() {
AnalysisApi2Data("assets/api2.json") AnalysisApi2Data("assets/api2.json")
AnalysisApi3Data("assets/api3.json") AnalysisApi3Data("assets/api3.json")
// ListUnitData() // ListUnitData()
go SyncNotesList() // go SyncNotesList()
} }