Fix: user page doesn't work because of bad JSON parsing

This commit is contained in:
VnPower 2023-06-07 16:14:35 +07:00
parent ab13f590db
commit b55c849f5e
Signed by: vnpower
GPG key ID: 881DE3DEB966106C
2 changed files with 10 additions and 3 deletions

View file

@ -383,7 +383,7 @@ func (p *PixivClient) GetUserInformation(id string, page int) (*models.User, err
var body struct {
*models.User
Background map[string]string `json:"background"`
Background map[string]interface{} `json:"background"`
}
// Basic user information
@ -400,7 +400,7 @@ func (p *PixivClient) GetUserInformation(id string, page int) (*models.User, err
// Background image
if body.Background != nil {
user.BackgroundImage = body.Background["url"]
user.BackgroundImage = body.Background["url"].(string)
}
// Artworks count

View file

@ -81,7 +81,14 @@ func user_page(c *gin.Context) {
}
pageInt, _ := strconv.Atoi(page)
user, _ := PC.GetUserInformation(id, pageInt)
user, err := PC.GetUserInformation(id, pageInt)
if err != nil {
c.HTML(http.StatusInternalServerError, "error.html", gin.H{
"Title": "An error occured",
"Error": err,
})
return
}
worksCount, _ := PC.GetUserArtworksCount(id)
pageLimit := math.Ceil(float64(worksCount)/30.0) + 1.0