Fix download methods
This commit is contained in:
50
chat.go
50
chat.go
@ -583,26 +583,52 @@ func (k *Keybase) UploadToConversation(conv chat1.ConvIDStr, title string, filen
|
||||
return k.SendMessage("attach", opts)
|
||||
}
|
||||
|
||||
// DownloadFromChannel downloads a file from a channel
|
||||
func (k *Keybase) DownloadFromChannel(channel chat1.ChatChannel, msgID chat1.MessageID, filename string) (chat1.SendRes, error) {
|
||||
opts := SendMessageOptions{
|
||||
Channel: channel,
|
||||
MessageID: msgID,
|
||||
Filename: filename,
|
||||
// Download downloads a file
|
||||
func (k *Keybase) Download(options DownloadOptions) error {
|
||||
type res struct {
|
||||
Error *Error `json:"error"`
|
||||
}
|
||||
var r res
|
||||
|
||||
arg := newDownloadArg(options)
|
||||
|
||||
jsonBytes, _ := json.Marshal(arg)
|
||||
|
||||
cmdOut, err := k.Exec("chat", "api", "-m", string(jsonBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.SendMessage("download", opts)
|
||||
err = json.Unmarshal(cmdOut, &r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if r.Error != nil {
|
||||
return fmt.Errorf("%v", r.Error.Message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DownloadFromChannel downloads a file from a channel
|
||||
func (k *Keybase) DownloadFromChannel(channel chat1.ChatChannel, msgID chat1.MessageID, output string) error {
|
||||
opts := DownloadOptions{
|
||||
Channel: channel,
|
||||
MessageID: msgID,
|
||||
Output: output,
|
||||
}
|
||||
return k.Download(opts)
|
||||
}
|
||||
|
||||
// DownloadFromConversation downloads a file from a conversation
|
||||
func (k *Keybase) DownloadFromConversation(conv chat1.ConvIDStr, msgID chat1.MessageID, filename string) (chat1.SendRes, error) {
|
||||
opts := SendMessageOptions{
|
||||
func (k *Keybase) DownloadFromConversation(conv chat1.ConvIDStr, msgID chat1.MessageID, output string) error {
|
||||
opts := DownloadOptions{
|
||||
ConversationID: conv,
|
||||
MessageID: msgID,
|
||||
Filename: filename,
|
||||
Output: output,
|
||||
}
|
||||
|
||||
return k.SendMessage("download", opts)
|
||||
return k.Download(opts)
|
||||
}
|
||||
|
||||
// LoadFlip returns the results of a flip
|
||||
|
||||
28
types.go
28
types.go
@ -149,6 +149,34 @@ func newAdvertiseCommandsArg(options AdvertiseCommandsOptions) advertiseCommands
|
||||
}
|
||||
}
|
||||
|
||||
// DownloadOptions holds a set of options to be passed to Download
|
||||
type DownloadOptions struct {
|
||||
Channel chat1.ChatChannel
|
||||
ConversationID chat1.ConvIDStr `json:"conversation_id"`
|
||||
MessageID chat1.MessageID `json:"message_id"`
|
||||
Output string
|
||||
Preview bool
|
||||
NoStream bool
|
||||
}
|
||||
|
||||
type downloadParams struct {
|
||||
Options DownloadOptions
|
||||
}
|
||||
|
||||
type downloadArg struct {
|
||||
Method string
|
||||
Params downloadParams
|
||||
}
|
||||
|
||||
func newDownloadArg(options DownloadOptions) downloadArg {
|
||||
return downloadArg{
|
||||
Method: "download",
|
||||
Params: downloadParams{
|
||||
Options: options,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// KVOptions holds a set of options to be passed to the KV methods
|
||||
type KVOptions struct {
|
||||
Team *string `json:"team"`
|
||||
|
||||
Reference in New Issue
Block a user