diff --git a/handler/artwork.go b/handler/artwork.go index 7d2b449..807d558 100644 --- a/handler/artwork.go +++ b/handler/artwork.go @@ -63,69 +63,105 @@ func (p *PixivClient) GetArtworkByID(id string) (*models.Illust, error) { return nil, err } - // Get illust images - images, err = p.GetArtworkImages(id) - if err != nil { - return nil, err - } + // Begin testing here - illust.Images = images + c1 := make(chan []models.Image) + c2 := make(chan []models.IllustShort) + c3 := make(chan models.UserShort) + c4 := make(chan []models.Tag) + c5 := make(chan []models.IllustShort) + c6 := make(chan []models.Comment) - // Get recent artworks - ids := make([]int, 0) + go func() { + // Get illust images + images, err = p.GetArtworkImages(id) + if err != nil { + c1 <- nil + } + c1 <- images + }() - for k := range illust.Recent { - ids = append(ids, k) - } + go func() { + // Get recent artworks + ids := make([]int, 0) - sort.Sort(sort.Reverse(sort.IntSlice(ids))) + for k := range illust.Recent { + ids = append(ids, k) + } - idsString := "" - count := min(len(ids), 20) + sort.Sort(sort.Reverse(sort.IntSlice(ids))) - for i := 0; i < count; i++ { - idsString += fmt.Sprintf("&ids[]=%d", ids[i]) - } + idsString := "" + count := min(len(ids), 20) - recent, err := p.GetUserArtworks(illust.UserID, idsString) - if err != nil { - return nil, err - } - sort.Slice(recent[:], func(i, j int) bool { - left, _ := strconv.Atoi(recent[i].ID) - right, _ := strconv.Atoi(recent[j].ID) - return left > right - }) + for i := 0; i < count; i++ { + idsString += fmt.Sprintf("&ids[]=%d", ids[i]) + } - illust.RecentWorks = recent + recent, err := p.GetUserArtworks(illust.UserID, idsString) + if err != nil { + c2 <- nil + } + sort.Slice(recent[:], func(i, j int) bool { + left, _ := strconv.Atoi(recent[i].ID) + right, _ := strconv.Atoi(recent[j].ID) + return left > right + }) + c2 <- recent - // Get basic user information (the URL above does not contain avatars) - userInfo, err := p.GetUserBasicInformation(illust.UserID) - if err != nil { - return nil, err - } + }() - illust.User = userInfo + go func() { + // Get basic user information (the URL above does not contain avatars) + userInfo, err := p.GetUserBasicInformation(illust.UserID) + if err != nil { + // + } + c3 <- userInfo + }() - // Extract tags - var tags struct { - Tags []struct { - Tag string `json:"tag"` - Translation map[string]string `json:"translation"` - } `json:"tags"` - } - err = json.Unmarshal(illust.RawTags, &tags) - if err != nil { - return nil, err - } + go func() { + var tagsList []models.Tag + // Extract tags + var tags struct { + Tags []struct { + Tag string `json:"tag"` + Translation map[string]string `json:"translation"` + } `json:"tags"` + } + err = json.Unmarshal(illust.RawTags, &tags) + if err != nil { + c4 <- nil + } - for _, tag := range tags.Tags { - var newTag models.Tag - newTag.Name = tag.Tag - newTag.TranslatedName = tag.Translation["en"] + for _, tag := range tags.Tags { + var newTag models.Tag + newTag.Name = tag.Tag + newTag.TranslatedName = tag.Translation["en"] - illust.Tags = append(illust.Tags, newTag) - } + tagsList = append(tagsList, newTag) + } + c4 <- tagsList + }() + + go func() { + related, _ := p.GetRelatedArtworks(id) + // Error handling... + c5 <- related + }() + + go func() { + comments, _ := p.GetArtworkComments(id) + // Error handling... + c6 <- comments + }() + + illust.Images = <-c1 + illust.RecentWorks = <-c2 + illust.User = <-c3 + illust.Tags = <-c4 + illust.RelatedWorks = <-c5 + illust.CommentsList = <-c6 return illust.Illust, nil } diff --git a/models/models.go b/models/models.go index 77035e4..82dce28 100644 --- a/models/models.go +++ b/models/models.go @@ -113,9 +113,11 @@ type Illust struct { AiType aiType `json:"aiType"` User UserShort RecentWorks []IllustShort + RelatedWorks []IllustShort + CommentsList []Comment } -func (s Illust) ProxyImages(proxy string) { +func (s *Illust) ProxyImages(proxy string) { for i := range s.Images { s.Images[i].Small = ProxyImage(s.Images[i].Small, proxy) s.Images[i].Medium = ProxyImage(s.Images[i].Medium, proxy) @@ -125,6 +127,8 @@ func (s Illust) ProxyImages(proxy string) { for i := range s.RecentWorks { s.RecentWorks[i].Thumbnail = ProxyImage(s.RecentWorks[i].Thumbnail, proxy) } + s.RelatedWorks = ProxyShortArtworkSlice(s.RelatedWorks, proxy) + s.CommentsList = ProxyCommentsSlice(s.CommentsList, proxy) s.User.Avatar = ProxyImage(s.User.Avatar, proxy) } diff --git a/template/pages/artwork.jet.html b/template/pages/artwork.jet.html index 7f552e3..64bab2e 100644 --- a/template/pages/artwork.jet.html +++ b/template/pages/artwork.jet.html @@ -1,67 +1,84 @@
{{ raw: Illust.Description }}
+{{ raw: Illust.Description }}
- -The creator turned comments off
- {{ else if Illust.Comments == 0 }} -There is no comment yet
- {{ else }} {{ range Comments }} -The creator turned comments off
+ {{ else if Illust.Comments == 0 }} +There is no comment yet
+ {{ else }} {{ range Illust.CommentsList }} +
+ {{ if .Stamp }}
+
+ {{ else }} {{ raw: parseEmojis(.Context) }} {{ end }}
+
- {{ if .Stamp }} -
- {{ else }} {{ raw: parseEmojis(.Context) }} {{ end }}
-
- - {{ .Date }} -