Skip to content

Commit

Permalink
fix: better API
Browse files Browse the repository at this point in the history
  • Loading branch information
RicheyJang committed Mar 24, 2022
1 parent d7f9aac commit 8931b9a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
37 changes: 30 additions & 7 deletions plugins/pixiv/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,7 @@ func (pic *PictureInfo) GenSinglePicMsg() (message.Message, error) {
}
}
// 下载图片
path, err := images.GetNewTempSavePath("pixiv")
if err != nil {
return nil, err
}
c := client.NewHttpClient(&client.HttpOptions{TryTime: 2, Timeout: getTimeout()})
c.SetUserAgent()
err = c.DownloadToFile(path, pic.URL)
path, err := pic.GetPicture()
if err != nil {
return nil, err
}
Expand All @@ -146,6 +140,35 @@ func (pic *PictureInfo) GenSinglePicMsg() (message.Message, error) {
return message.Message{message.Text(pic.Title), picMsg, message.Text(tip)}, nil
}

// GetPicture 下载图片,返回图片保存路径
func (pic *PictureInfo) GetPicture() (path string, err error) {
// 初始化
if pic == nil {
return "", fmt.Errorf("pic is nil")
}
if !pic.CheckNoSESE() {
return "", fmt.Errorf("不可以涩涩!")
}
if len(pic.URL) == 0 {
err = pic.GetURLByPID()
if err != nil {
return "", fmt.Errorf("GetURLByPID failed: %v", err)
}
}
// 下载图片
path, err = images.GetNewTempSavePath("pixiv")
if err != nil {
return "", fmt.Errorf("GetNewTempSavePath err: %v", err)
}
c := client.NewHttpClient(&client.HttpOptions{TryTime: 2, Timeout: getTimeout()})
c.SetUserAgent()
err = c.DownloadToFile(path, pic.URL)
if err != nil {
return "", err
}
return
}

// GetDescribe 获取图片说明
func (pic *PictureInfo) GetDescribe() string {
if !pic.CheckNoSESE() {
Expand Down
13 changes: 8 additions & 5 deletions plugins/pixiv/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ var proxy *manager.PluginProxy

type PictureInfo struct {
Title string // 标题
URL string // 图片链接

// 下载所需
URL string // 图片链接
PID int64 // 下载图片时要么有URL;要么有PID及P
P int // 分P

// 描述所需
Tags []string // 标签
PID int64
P int // 分P
Author string // 作者
UID int64 // 作者UID
Author string // 作者
UID int64 // 作者UID

Src string // 无需填写,来源图库
}
Expand Down

0 comments on commit 8931b9a

Please sign in to comment.