mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 17:33:48 +01:00
Add option to use async media uploads
https://github.com/matrix-org/matrix-spec-proposals/pull/2246
This commit is contained in:
parent
34954fc9f6
commit
f79ca422e8
6 changed files with 26 additions and 8 deletions
|
@ -34,6 +34,7 @@ type Config struct {
|
||||||
Asmux bool `yaml:"asmux"`
|
Asmux bool `yaml:"asmux"`
|
||||||
StatusEndpoint string `yaml:"status_endpoint"`
|
StatusEndpoint string `yaml:"status_endpoint"`
|
||||||
MessageSendCheckpointEndpoint string `yaml:"message_send_checkpoint_endpoint"`
|
MessageSendCheckpointEndpoint string `yaml:"message_send_checkpoint_endpoint"`
|
||||||
|
AsyncMedia bool `yaml:"async_media"`
|
||||||
} `yaml:"homeserver"`
|
} `yaml:"homeserver"`
|
||||||
|
|
||||||
AppService struct {
|
AppService struct {
|
||||||
|
|
|
@ -33,6 +33,7 @@ func (helper *UpgradeHelper) doUpgrade() {
|
||||||
helper.Copy(Bool, "homeserver", "asmux")
|
helper.Copy(Bool, "homeserver", "asmux")
|
||||||
helper.Copy(Str|Null, "homeserver", "status_endpoint")
|
helper.Copy(Str|Null, "homeserver", "status_endpoint")
|
||||||
helper.Copy(Str|Null, "homeserver", "message_send_checkpoint_endpoint")
|
helper.Copy(Str|Null, "homeserver", "message_send_checkpoint_endpoint")
|
||||||
|
helper.Copy(Bool, "homeserver", "async_media")
|
||||||
|
|
||||||
helper.Copy(Str, "appservice", "address")
|
helper.Copy(Str, "appservice", "address")
|
||||||
helper.Copy(Str, "appservice", "hostname")
|
helper.Copy(Str, "appservice", "hostname")
|
||||||
|
|
|
@ -13,6 +13,8 @@ homeserver:
|
||||||
status_endpoint: null
|
status_endpoint: null
|
||||||
# Endpoint for reporting per-message status.
|
# Endpoint for reporting per-message status.
|
||||||
message_send_checkpoint_endpoint: null
|
message_send_checkpoint_endpoint: null
|
||||||
|
# Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246?
|
||||||
|
async_media: false
|
||||||
|
|
||||||
# Application service host/registration related details.
|
# Application service host/registration related details.
|
||||||
# Changing these values requires regeneration of the registration.
|
# Changing these values requires regeneration of the registration.
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -17,7 +17,7 @@ require (
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||||
maunium.net/go/mauflag v1.0.0
|
maunium.net/go/mauflag v1.0.0
|
||||||
maunium.net/go/maulogger/v2 v2.3.2
|
maunium.net/go/maulogger/v2 v2.3.2
|
||||||
maunium.net/go/mautrix v0.10.13-0.20220317230932-15d85fe4d3cc
|
maunium.net/go/mautrix v0.10.13-0.20220321175701-3b9911029134
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -197,5 +197,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
||||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||||
maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
|
maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
|
||||||
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
||||||
maunium.net/go/mautrix v0.10.13-0.20220317230932-15d85fe4d3cc h1:7NNOnyCL03RWifzCko6QhVzn+gqS8DKRRtqCVBIKj7g=
|
maunium.net/go/mautrix v0.10.13-0.20220321175701-3b9911029134 h1:EYo8hg0p7XL8nXV18dcsSc0f/0NKFQF/+D/Cll1q0rU=
|
||||||
maunium.net/go/mautrix v0.10.13-0.20220317230932-15d85fe4d3cc/go.mod h1:WqW8mruBue+1YrL/f04Ni/4R5yfLcgO8BQhUJzl7sps=
|
maunium.net/go/mautrix v0.10.13-0.20220321175701-3b9911029134/go.mod h1:WqW8mruBue+1YrL/f04Ni/4R5yfLcgO8BQhUJzl7sps=
|
||||||
|
|
24
portal.go
24
portal.go
|
@ -2108,16 +2108,30 @@ func (portal *Portal) convertMediaMessageContent(intent *appservice.IntentAPI, m
|
||||||
func (portal *Portal) uploadMedia(intent *appservice.IntentAPI, data []byte, content *event.MessageEventContent) error {
|
func (portal *Portal) uploadMedia(intent *appservice.IntentAPI, data []byte, content *event.MessageEventContent) error {
|
||||||
data, uploadMimeType, file := portal.encryptFile(data, content.Info.MimeType)
|
data, uploadMimeType, file := portal.encryptFile(data, content.Info.MimeType)
|
||||||
|
|
||||||
uploaded, err := intent.UploadBytes(data, uploadMimeType)
|
req := mautrix.ReqUploadMedia{
|
||||||
if err != nil {
|
ContentBytes: data,
|
||||||
return err
|
ContentType: uploadMimeType,
|
||||||
|
}
|
||||||
|
var mxc id.ContentURI
|
||||||
|
if portal.bridge.Config.Homeserver.AsyncMedia {
|
||||||
|
uploaded, err := intent.UnstableUploadAsync(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
mxc = uploaded.ContentURI
|
||||||
|
} else {
|
||||||
|
uploaded, err := intent.UploadMedia(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
mxc = uploaded.ContentURI
|
||||||
}
|
}
|
||||||
|
|
||||||
if file != nil {
|
if file != nil {
|
||||||
file.URL = uploaded.ContentURI.CUString()
|
file.URL = mxc.CUString()
|
||||||
content.File = file
|
content.File = file
|
||||||
} else {
|
} else {
|
||||||
content.URL = uploaded.ContentURI.CUString()
|
content.URL = mxc.CUString()
|
||||||
}
|
}
|
||||||
|
|
||||||
content.Info.Size = len(data)
|
content.Info.Size = len(data)
|
||||||
|
|
Loading…
Reference in a new issue