|
1 | 1 | package kemono
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + . "ManyACG/logger" |
4 | 5 | "ManyACG/types"
|
5 | 6 | "fmt"
|
| 7 | + "net/http" |
6 | 8 | "strconv"
|
7 | 9 | )
|
8 | 10 |
|
@@ -49,25 +51,47 @@ func (resp *KemonoPostResp) ToArtwork() (*types.Artwork, error) {
|
49 | 51 | }
|
50 | 52 | pictures := make([]*types.Picture, 0)
|
51 | 53 | if isImage(resp.File.Path) {
|
52 |
| - pictures = append(pictures, &types.Picture{ |
53 |
| - Index: 0, |
54 |
| - Thumbnail: cdnBaseURL + resp.File.Path, |
55 |
| - Original: cdnBaseURL + resp.File.Path, |
56 |
| - Width: 0, |
57 |
| - Height: 0, |
58 |
| - }) |
| 54 | + fileResp, err := reqClient.R().DisableAutoReadResponse().Get(cdnBaseURL + resp.File.Path) |
| 55 | + if err == nil && fileResp.StatusCode == http.StatusOK { |
| 56 | + pictures = append(pictures, &types.Picture{ |
| 57 | + Index: 0, |
| 58 | + Thumbnail: cdnBaseURL + resp.File.Path, |
| 59 | + Original: cdnBaseURL + resp.File.Path, |
| 60 | + Width: 0, |
| 61 | + Height: 0, |
| 62 | + }) |
| 63 | + } |
| 64 | + fileResp.Body.Close() |
59 | 65 | }
|
60 |
| - for i, attachment := range resp.Attachments { |
| 66 | + i := len(pictures) |
| 67 | + for _, attachment := range resp.Attachments { |
61 | 68 | if !isImage(attachment.Path) {
|
62 | 69 | continue
|
63 | 70 | }
|
| 71 | + fileURL := cdnBaseURL + attachment.Path |
| 72 | + fileResp, err := reqClient.R().DisableAutoReadResponse().Get(fileURL) |
| 73 | + if err != nil { |
| 74 | + Logger.Warnf("get attachment %s failed: %s", fileURL, err) |
| 75 | + continue |
| 76 | + } |
| 77 | + if fileResp.StatusCode != http.StatusOK { |
| 78 | + Logger.Warnf("get attachment %s failed: %d", fileURL, fileResp.StatusCode) |
| 79 | + continue |
| 80 | + } |
| 81 | + fileResp.Body.Close() |
| 82 | + for _, picture := range pictures { |
| 83 | + if picture.Original == fileURL { |
| 84 | + continue |
| 85 | + } |
| 86 | + } |
64 | 87 | pictures = append(pictures, &types.Picture{
|
65 |
| - Index: uint(i + 1), |
66 |
| - Thumbnail: cdnBaseURL + attachment.Path, |
67 |
| - Original: cdnBaseURL + attachment.Path, |
| 88 | + Index: uint(i), |
| 89 | + Thumbnail: fileURL, |
| 90 | + Original: fileURL, |
68 | 91 | Width: 0,
|
69 | 92 | Height: 0,
|
70 | 93 | })
|
| 94 | + i++ |
71 | 95 | }
|
72 | 96 | artwork := &types.Artwork{
|
73 | 97 | Title: resp.Title,
|
|
0 commit comments