From 71a48bd4d8d643125be4f12e992e65f742ff72cb Mon Sep 17 00:00:00 2001 From: perennial Date: Sat, 12 Oct 2024 03:00:12 +1100 Subject: [PATCH] fix early return when fetching artwork comments --- core/artwork.go | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/core/artwork.go b/core/artwork.go index ad3b094..d029e0e 100644 --- a/core/artwork.go +++ b/core/artwork.go @@ -316,22 +316,6 @@ func GetArtworkByID(r *http.Request, id string, full bool) (*Illust, error) { } illust2.RelatedWorks = related }() - - // Get reader comments - wg.Add(1) - go func() { - defer wg.Done() - - // if illust.CommentDisabled == 1 { - // return - // } - comments, err := GetArtworkComments(r, id) - if err != nil { - cerr <- err - return - } - illust2.CommentsList = comments - }() } // Get basic illust information @@ -433,6 +417,27 @@ func GetArtworkByID(r *http.Request, id string, full bool) (*Illust, error) { illust.RecentWorks = recent }() } + + // Get reader comments + // + // Only fetch the comments if 'full' is requested and comments are not disabled (illust.CommentDisabled != 1). + // This check needs to happen *after* fetching the basic artwork information, since that's when + // 'CommentDisabled' is populated. If we check it too early, it would default to 0 (enabled), + // leading to an invalid API call to fetch comments even when they are disabled, causing an HTTP 500 error + // on our end when we receive HTTP 400 from the Pixiv API as a result. + if full && illust.CommentDisabled != 1 { + wg.Add(1) + go func() { + defer wg.Done() + + comments, err := GetArtworkComments(r, id) + if err != nil { + cerr <- err + return + } + illust2.CommentsList = comments + }() + } }() wg.Wait()