From b55c849f5eb08c9e89bfdb6f473d57c4ce0fb2db Mon Sep 17 00:00:00 2001 From: VnPower Date: Wed, 7 Jun 2023 16:14:35 +0700 Subject: [PATCH] Fix: user page doesn't work because of bad JSON parsing --- handler/pixiv.go | 4 ++-- views/routes.go | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/handler/pixiv.go b/handler/pixiv.go index 227f1e4..cde7ae7 100644 --- a/handler/pixiv.go +++ b/handler/pixiv.go @@ -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 diff --git a/views/routes.go b/views/routes.go index 9f82bbb..5cf87a7 100644 --- a/views/routes.go +++ b/views/routes.go @@ -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