fix early return when fetching artwork comments

This commit is contained in:
perennial
2024-10-12 03:00:12 +11:00
parent 06ac1109b2
commit 71a48bd4d8
+21 -16
View File
@@ -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()