Update some forgotten items.
parent
a45216f441
commit
f2cd95670d
11
bot.go
11
bot.go
|
@ -198,18 +198,7 @@ func (bot *BotAPI) UploadFiles(endpoint string, params Params, files []RequestFi
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.Size != -1 {
|
|
||||||
io.Copy(part, f.Reader)
|
io.Copy(part, f.Reader)
|
||||||
} else {
|
|
||||||
data, err := ioutil.ReadAll(f.Reader)
|
|
||||||
if err != nil {
|
|
||||||
w.CloseWithError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := bytes.NewBuffer(data)
|
|
||||||
io.Copy(part, buf)
|
|
||||||
}
|
|
||||||
case FileURL:
|
case FileURL:
|
||||||
val := string(f)
|
val := string(f)
|
||||||
if err := m.WriteField(file.Name, val); err != nil {
|
if err := m.WriteField(file.Name, val); err != nil {
|
||||||
|
|
|
@ -120,7 +120,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
f, _ := os.Open("tests/image.jpg")
|
f, _ := os.Open("tests/image.jpg")
|
||||||
reader := FileReader{Name: "image.jpg", Reader: f, Size: -1}
|
reader := FileReader{Name: "image.jpg", Reader: f}
|
||||||
|
|
||||||
msg := NewPhoto(ChatID, reader)
|
msg := NewPhoto(ChatID, reader)
|
||||||
msg.Caption = "Test"
|
msg.Caption = "Test"
|
||||||
|
@ -177,7 +177,7 @@ func TestSendNewPhotoToChannelFileReader(t *testing.T) {
|
||||||
bot, _ := getBot(t)
|
bot, _ := getBot(t)
|
||||||
|
|
||||||
f, _ := os.Open("tests/image.jpg")
|
f, _ := os.Open("tests/image.jpg")
|
||||||
reader := FileReader{Name: "image.jpg", Reader: f, Size: -1}
|
reader := FileReader{Name: "image.jpg", Reader: f}
|
||||||
|
|
||||||
msg := NewPhotoToChannel(Channel, reader)
|
msg := NewPhotoToChannel(Channel, reader)
|
||||||
msg.Caption = "Test"
|
msg.Caption = "Test"
|
||||||
|
|
29
configs.go
29
configs.go
|
@ -375,10 +375,6 @@ func (config AnimationConfig) params() (Params, error) {
|
||||||
return params, err
|
return params, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config AnimationConfig) name() string {
|
|
||||||
return "animation"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config AnimationConfig) method() string {
|
func (config AnimationConfig) method() string {
|
||||||
return "sendAnimation"
|
return "sendAnimation"
|
||||||
}
|
}
|
||||||
|
@ -899,8 +895,15 @@ func (config WebhookConfig) params() (Params, error) {
|
||||||
return params, err
|
return params, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config WebhookConfig) name() string {
|
func (config WebhookConfig) files() []RequestFile {
|
||||||
return "certificate"
|
if config.Certificate != nil {
|
||||||
|
return []RequestFile{{
|
||||||
|
Name: "certificate",
|
||||||
|
File: config.Certificate,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveWebhookConfig is a helper to remove a webhook.
|
// RemoveWebhookConfig is a helper to remove a webhook.
|
||||||
|
@ -923,12 +926,9 @@ type FileBytes struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileReader contains information about a reader to upload as a File.
|
// FileReader contains information about a reader to upload as a File.
|
||||||
// If Size is -1, it will read the entire Reader into memory to
|
|
||||||
// calculate a Size.
|
|
||||||
type FileReader struct {
|
type FileReader struct {
|
||||||
Name string
|
Name string
|
||||||
Reader io.Reader
|
Reader io.Reader
|
||||||
Size int64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileURL is a URL to use as a file for a request.
|
// FileURL is a URL to use as a file for a request.
|
||||||
|
@ -1642,15 +1642,14 @@ func (config SetStickerSetThumbConfig) params() (Params, error) {
|
||||||
params["name"] = config.Name
|
params["name"] = config.Name
|
||||||
params.AddNonZero("user_id", config.UserID)
|
params.AddNonZero("user_id", config.UserID)
|
||||||
|
|
||||||
if thumb, ok := config.Thumb.(string); ok {
|
|
||||||
params["thumb"] = thumb
|
|
||||||
}
|
|
||||||
|
|
||||||
return params, nil
|
return params, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config SetStickerSetThumbConfig) name() string {
|
func (config SetStickerSetThumbConfig) files() []RequestFile {
|
||||||
return "thumb"
|
return []RequestFile{{
|
||||||
|
Name: "thumb",
|
||||||
|
File: config.Thumb,
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetChatStickerSetConfig allows you to set the sticker set for a supergroup.
|
// SetChatStickerSetConfig allows you to set the sticker set for a supergroup.
|
||||||
|
|
|
@ -349,4 +349,6 @@ var (
|
||||||
_ Fileable = (*NewStickerSetConfig)(nil)
|
_ Fileable = (*NewStickerSetConfig)(nil)
|
||||||
_ Fileable = (*AddStickerConfig)(nil)
|
_ Fileable = (*AddStickerConfig)(nil)
|
||||||
_ Fileable = (*MediaGroupConfig)(nil)
|
_ Fileable = (*MediaGroupConfig)(nil)
|
||||||
|
_ Fileable = (*WebhookConfig)(nil)
|
||||||
|
_ Fileable = (*SetStickerSetThumbConfig)(nil)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue