mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-28 05:32:01 -08:00
move logic for getting url to its own function
This commit is contained in:
parent
56e7bd01ca
commit
44411b4789
@ -556,6 +556,21 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getMessageFileUrl changes the Matrix mxc:// uploads and changes them to a regular url
|
||||||
|
func (b *Bmatrix) getMessageFileUrl(content map[string]interface{}) (string, error) {
|
||||||
|
var (
|
||||||
|
ok bool
|
||||||
|
url string
|
||||||
|
)
|
||||||
|
|
||||||
|
if url, ok = content["url"].(string); !ok {
|
||||||
|
return "", fmt.Errorf("url isn't a %T", url)
|
||||||
|
}
|
||||||
|
url = strings.Replace(url, "mxc://", b.GetString("Server")+"/_matrix/media/v1/download/", -1)
|
||||||
|
|
||||||
|
return url, nil
|
||||||
|
}
|
||||||
|
|
||||||
// handleDownloadFile handles file download
|
// handleDownloadFile handles file download
|
||||||
func (b *Bmatrix) handleDownloadFile(rmsg *config.Message, content map[string]interface{}) error {
|
func (b *Bmatrix) handleDownloadFile(rmsg *config.Message, content map[string]interface{}) error {
|
||||||
var (
|
var (
|
||||||
@ -566,10 +581,17 @@ func (b *Bmatrix) handleDownloadFile(rmsg *config.Message, content map[string]in
|
|||||||
)
|
)
|
||||||
|
|
||||||
rmsg.Extra = make(map[string][]interface{})
|
rmsg.Extra = make(map[string][]interface{})
|
||||||
if url, ok = content["url"].(string); !ok {
|
|
||||||
return fmt.Errorf("url isn't a %T", url)
|
//// moved to getMessageFileUrl
|
||||||
|
//if url, ok = content["url"].(string); !ok {
|
||||||
|
// return fmt.Errorf("url isn't a %T", url)
|
||||||
|
//}
|
||||||
|
//url = strings.Replace(url, "mxc://", b.GetString("Server")+"/_matrix/media/v1/download/", -1)
|
||||||
|
|
||||||
|
url, err := b.getMessageFileUrl(content)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
url = strings.Replace(url, "mxc://", b.GetString("Server")+"/_matrix/media/v1/download/", -1)
|
|
||||||
|
|
||||||
if info, ok = content["info"].(map[string]interface{}); !ok {
|
if info, ok = content["info"].(map[string]interface{}); !ok {
|
||||||
return fmt.Errorf("info isn't a %T", info)
|
return fmt.Errorf("info isn't a %T", info)
|
||||||
@ -601,7 +623,7 @@ func (b *Bmatrix) handleDownloadFile(rmsg *config.Message, content map[string]in
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if the size is ok
|
// check if the size is ok
|
||||||
err := helper.HandleDownloadSize(b.Log, rmsg, name, int64(size), b.General)
|
err = helper.HandleDownloadSize(b.Log, rmsg, name, int64(size), b.General)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user