Fix bridging encrypted media from Matrix
This commit is contained in:
parent
a770263d86
commit
e08676079a
29
portal.go
29
portal.go
@ -1002,8 +1002,8 @@ func (portal *Portal) HandleMediaMessage(source *User, download func() ([]byte,
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
portal.log.Errorfln("Failed to download media for %s: %v", info.Id, err)
|
portal.log.Errorfln("Failed to download media for %s: %v", info.Id, err)
|
||||||
resp, err := portal.sendMainIntentMessage(event.MessageEventContent{
|
resp, err := portal.sendMainIntentMessage(event.MessageEventContent{
|
||||||
MsgType: event.MsgNotice,
|
MsgType: event.MsgNotice,
|
||||||
Body: "Failed to bridge media",
|
Body: "Failed to bridge media",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorfln("Failed to send media download error message for %s: %v", info.Id, err)
|
portal.log.Errorfln("Failed to send media download error message for %s: %v", info.Id, err)
|
||||||
@ -1157,25 +1157,38 @@ func (portal *Portal) downloadThumbnail(content *event.MessageEventContent, id i
|
|||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) preprocessMatrixMedia(sender *User, relaybotFormatted bool, content *event.MessageEventContent, id id.EventID, mediaType whatsapp.MediaType) *MediaUpload {
|
func (portal *Portal) preprocessMatrixMedia(sender *User, relaybotFormatted bool, content *event.MessageEventContent, eventID id.EventID, mediaType whatsapp.MediaType) *MediaUpload {
|
||||||
var caption string
|
var caption string
|
||||||
if relaybotFormatted {
|
if relaybotFormatted {
|
||||||
caption = portal.bridge.Formatter.ParseMatrix(content.FormattedBody)
|
caption = portal.bridge.Formatter.ParseMatrix(content.FormattedBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
mxc, err := content.URL.Parse()
|
var file *event.EncryptedFileInfo
|
||||||
|
rawMXC := content.URL
|
||||||
|
if content.File != nil {
|
||||||
|
file = content.File
|
||||||
|
rawMXC = file.URL
|
||||||
|
}
|
||||||
|
mxc, err := rawMXC.Parse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorln("Malformed content URL in %s: %v", id, err)
|
portal.log.Errorln("Malformed content URL in %s: %v", eventID, err)
|
||||||
}
|
}
|
||||||
data, err := portal.MainIntent().DownloadBytes(mxc)
|
data, err := portal.MainIntent().DownloadBytes(mxc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorfln("Failed to download media in %s: %v", id, err)
|
portal.log.Errorfln("Failed to download media in %s: %v", eventID, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if file != nil {
|
||||||
|
data, err = file.Decrypt(data)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorfln("Failed to decrypt media in %s: %v", eventID, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
url, mediaKey, fileEncSHA256, fileSHA256, fileLength, err := sender.Conn.Upload(bytes.NewReader(data), mediaType)
|
url, mediaKey, fileEncSHA256, fileSHA256, fileLength, err := sender.Conn.Upload(bytes.NewReader(data), mediaType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorfln("Failed to upload media in %s: %v", id, err)
|
portal.log.Errorfln("Failed to upload media in %s: %v", eventID, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1186,7 +1199,7 @@ func (portal *Portal) preprocessMatrixMedia(sender *User, relaybotFormatted bool
|
|||||||
FileEncSHA256: fileEncSHA256,
|
FileEncSHA256: fileEncSHA256,
|
||||||
FileSHA256: fileSHA256,
|
FileSHA256: fileSHA256,
|
||||||
FileLength: fileLength,
|
FileLength: fileLength,
|
||||||
Thumbnail: portal.downloadThumbnail(content, id),
|
Thumbnail: portal.downloadThumbnail(content, eventID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user