Skip to content

Commit df612c1

Browse files
committed
fix: unknow image format and duplicate original url
1 parent 39ae4cf commit df612c1

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

bot/handlers_common.go

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ func getArtworkInfo(ctx context.Context, bot *telego.Bot, message telego.Message
324324
if deletedModel != nil && hasPermission {
325325
photo.WithCaption(artworkInfoCaption + fmt.Sprintf("\n\n这是一个在 %s 删除的作品\n如果发布则会取消删除", deletedModel.DeletedAt.Time().Format("2006-01-02 15:04:05")))
326326
} else {
327+
artworkInfoCaption += fmt.Sprintf("\n\n该作品共有%d张图片", len(artwork.Pictures))
327328
photo.WithCaption(artworkInfoCaption)
328329
}
329330
if isAlreadyPosted {

cmd/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
Version string = "0.9.0"
10+
Version string = "0.9.1"
1111
)
1212

1313
var VersionCmd = &cobra.Command{

sources/kemono/types.go

+35-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package kemono
22

33
import (
4+
. "ManyACG/logger"
45
"ManyACG/types"
56
"fmt"
7+
"net/http"
68
"strconv"
79
)
810

@@ -49,25 +51,47 @@ func (resp *KemonoPostResp) ToArtwork() (*types.Artwork, error) {
4951
}
5052
pictures := make([]*types.Picture, 0)
5153
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()
5965
}
60-
for i, attachment := range resp.Attachments {
66+
i := len(pictures)
67+
for _, attachment := range resp.Attachments {
6168
if !isImage(attachment.Path) {
6269
continue
6370
}
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+
}
6487
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,
6891
Width: 0,
6992
Height: 0,
7093
})
94+
i++
7195
}
7296
artwork := &types.Artwork{
7397
Title: resp.Title,

0 commit comments

Comments
 (0)