From f89fcf72120caba68207cfbeb6be11eb2070f6cb Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 9 May 2020 02:08:23 +0300 Subject: [PATCH] Make no-cgo build work without source changes --- go.mod | 1 + go.sum | 2 ++ nocrypto.go => no-cgo.go | 12 ++++++++++++ portal.go | 6 ++---- webp.go | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) rename nocrypto.go => no-cgo.go (87%) create mode 100644 webp.go diff --git a/go.mod b/go.mod index 2b6cc1c..b360bb3 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 + golang.org/x/image v0.0.0-20200430140353-33d19683fad8 gopkg.in/yaml.v2 v2.2.8 maunium.net/go/mauflag v1.0.0 maunium.net/go/maulogger/v2 v2.1.1 diff --git a/go.sum b/go.sum index 3d63304..dd3f71e 100644 --- a/go.sum +++ b/go.sum @@ -59,6 +59,8 @@ github.com/tulir/go-whatsapp v0.2.6 h1:d58cqz/iqcCDeT+uFjLso8oSgMTYqoxGhGhGOyyHB github.com/tulir/go-whatsapp v0.2.6/go.mod h1:gyw9zGup1/Y3ZQUueZaqz3iR/WX9a2Lth4aqEbXjkok= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw= +golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= diff --git a/nocrypto.go b/no-cgo.go similarity index 87% rename from nocrypto.go rename to no-cgo.go index 0479daf..961bf5c 100644 --- a/nocrypto.go +++ b/no-cgo.go @@ -18,9 +18,21 @@ package main +import ( + "image" + "io" + + "golang.org/x/image/webp" +) + func (bridge *Bridge) initCrypto() error { if !bridge.Config.Bridge.Encryption.Allow { bridge.Log.Warnln("Bridge built without end-to-bridge encryption, but encryption is enabled in config") } bridge.Log.Debugln("Bridge built without end-to-bridge encryption") + return nil +} + +func decodeWebp(r io.Reader) (image.Image, error) { + return webp.Decode(r) } diff --git a/portal.go b/portal.go index 87723fc..9c52fd9 100644 --- a/portal.go +++ b/portal.go @@ -34,7 +34,6 @@ import ( "sync" "time" - "github.com/chai2010/webp" "github.com/pkg/errors" log "maunium.net/go/maulogger/v2" @@ -989,7 +988,7 @@ func (portal *Portal) HandleMediaMessage(source *User, download func() ([]byte, // synapse doesn't handle webp well, so we convert it. This can be dropped once https://github.com/matrix-org/synapse/issues/4382 is fixed if mimeType == "image/webp" { - img, err := webp.Decode(bytes.NewReader(data)) + img, err := decodeWebp(bytes.NewReader(data)) if err != nil { portal.log.Errorfln("Failed to decode media for %s: %v", err) return @@ -1188,7 +1187,7 @@ func (portal *Portal) sendMatrixConnectionError(sender *User, eventID id.EventID if sender.IsLoginInProgress() { reconnect = "You have a login attempt in progress, please wait." } - msg := format.RenderMarkdown("\u26a0 You are not connected to WhatsApp, so your message was not bridged. " + reconnect, true, false) + msg := format.RenderMarkdown("\u26a0 You are not connected to WhatsApp, so your message was not bridged. "+reconnect, true, false) msg.MsgType = event.MsgNotice _, err := portal.sendMainIntentMessage(msg) if err != nil { @@ -1229,7 +1228,6 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) { } portal.log.Debugfln("Received event %s", evt.ID) - ts := uint64(evt.Timestamp / 1000) status := waProto.WebMessageInfo_ERROR fromMe := true diff --git a/webp.go b/webp.go new file mode 100644 index 0000000..79b5be2 --- /dev/null +++ b/webp.go @@ -0,0 +1,14 @@ +// +build cgo + +package main + +import ( + "image" + "io" + + "github.com/chai2010/webp" +) + +func decodeWebp(r io.Reader) (image.Image, error) { + return webp.Decode(r) +}