Add album seriesAll api

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2023-03-30 06:08:53 +08:00
parent 7da92ede3e
commit f8860f65ce
4 changed files with 180 additions and 3 deletions
+174
View File
@@ -0,0 +1,174 @@
package handler
import (
"database/sql"
"encoding/base64"
"encoding/json"
"fmt"
"honoka-chan/config"
"honoka-chan/database"
"honoka-chan/encrypt"
"honoka-chan/model"
"honoka-chan/utils"
"net/http"
"time"
"github.com/gin-gonic/gin"
_ "github.com/mattn/go-sqlite3"
)
func AlbumSeriesAllHandler(ctx *gin.Context) {
db, err := sql.Open("sqlite3", "assets/unit.db")
if err != nil {
panic(err)
}
defer db.Close()
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)
//
sql := `SELECT album_series_id FROM album_series_m`
seriesRows, err := db.Query(sql)
if err != nil {
panic(err)
}
albumSeriesAllResp := []model.AlbumResponseData{}
for seriesRows.Next() {
var series int
err = seriesRows.Scan(&series)
if err != nil {
panic(err)
}
albumSeriesAll := []model.AlbumUnitList{}
stmt, err := db.Prepare("SELECT unit_id,rarity FROM unit_m WHERE album_series_id = ?")
if err != nil {
panic(err)
}
unitRows, err := stmt.Query(series)
if err != nil {
panic(err)
}
for unitRows.Next() {
var unitId, rarity int
err = unitRows.Scan(&unitId, &rarity)
if err != nil {
panic(err)
}
albumSeries := model.AlbumUnitList{
UnitID: unitId,
RankMaxFlag: true,
LoveMaxFlag: true,
RankLevelMaxFlag: true,
AllMaxFlag: true,
TotalLove: 10000,
FavoritePoint: 1000,
}
if rarity != 4 {
switch rarity {
case 1:
// N
albumSeries.HighestLovePerUnit = 50
case 2:
// R
albumSeries.HighestLovePerUnit = 200
case 3:
// SR
albumSeries.HighestLovePerUnit = 500
case 5:
// SSR
albumSeries.HighestLovePerUnit = 750
}
} else {
// UR
albumSeries.HighestLovePerUnit = 1000
// IsSigned
stmt, err = db.Prepare("SELECT COUNT(*) AS ct FROM unit_sign_asset_m WHERE unit_id = ?")
if err != nil {
panic(err)
}
signRows, err := stmt.Query(unitId)
if err != nil {
panic(err)
}
ct := 0
for signRows.Next() {
err = signRows.Scan(&ct)
if err != nil {
panic(err)
}
}
if ct > 0 {
albumSeries.SignFlag = true
} else {
albumSeries.SignFlag = false
}
}
albumSeriesAll = append(albumSeriesAll, albumSeries)
}
albumSeriesAllResp = append(albumSeriesAllResp, model.AlbumResponseData{
SeriesID: series,
UnitList: albumSeriesAll,
})
}
rb, err := json.Marshal(albumSeriesAllResp)
if err != nil {
panic(err)
}
resp := model.Response{
ResponseData: rb,
ReleaseInfo: []interface{}{},
StatusCode: 200,
}
respb, err := json.Marshal(resp)
if err != nil {
panic(err)
}
// fmt.Println(string(respb))
xms := encrypt.RSA_Sign_SHA1(respb, "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, string(respb))
}
+1
View File
@@ -15,6 +15,7 @@ import (
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
_ "github.com/mattn/go-sqlite3"
) )
func PartyListHandler(ctx *gin.Context) { func PartyListHandler(ctx *gin.Context) {
+1
View File
@@ -54,6 +54,7 @@ func main() {
r.POST("/main.php/unit/favorite", handler.SetDisplayRankHandler) r.POST("/main.php/unit/favorite", handler.SetDisplayRankHandler)
r.POST("/main.php/subscenario/startup", handler.SubScenarioStartupHandler) r.POST("/main.php/subscenario/startup", handler.SubScenarioStartupHandler)
r.POST("/main.php/subscenario/reward", handler.SubScenarioStartupHandler) r.POST("/main.php/subscenario/reward", handler.SubScenarioStartupHandler)
r.POST("/main.php/album/seriesAll", handler.AlbumSeriesAllHandler)
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")
} }
+4 -3
View File
@@ -1,7 +1,7 @@
package model package model
// module: album, action: albumAll // module: album, action: albumAll
type AlbumAll struct { type AlbumUnitList struct {
UnitID int `json:"unit_id"` UnitID int `json:"unit_id"`
RankMaxFlag bool `json:"rank_max_flag"` RankMaxFlag bool `json:"rank_max_flag"`
LoveMaxFlag bool `json:"love_max_flag"` LoveMaxFlag bool `json:"love_max_flag"`
@@ -13,6 +13,7 @@ type AlbumAll struct {
SignFlag bool `json:"sign_flag"` SignFlag bool `json:"sign_flag"`
} }
type AlbumAllResult struct { type AlbumResponseData struct {
AlbumAll []AlbumAll SeriesID int `json:"series_id"`
UnitList []AlbumUnitList `json:"unit_list"`
} }