Skip to content

Commit 9bb86d4

Browse files
author
Swirly
committed
fix the way matrix audio mimetype handling works except dont break everything and also dont die (featuring gofmt!)
1 parent c9412fd commit 9bb86d4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

bridge/matrix/matrix.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"path"
1313
"regexp"
14+
"slices"
1415
"strings"
1516
"sync"
1617
"time"
@@ -31,6 +32,8 @@ import (
3132
"maunium.net/go/mautrix/id"
3233
)
3334

35+
var Audio_MimeTypes = []string{"aac", "flac", "matroska", "mp4", "mpeg", "ogg", "opus", "vorbis", "wav"}
36+
3437
var (
3538
htmlTag = regexp.MustCompile("</.*?>")
3639
htmlReplacementTag = regexp.MustCompile("<[^>]*>")
@@ -932,7 +935,14 @@ func (b *Bmatrix) handleUploadFile(msg *config.Message, roomID id.RoomID, fi *co
932935
if err != nil {
933936
b.Log.Errorf("sendImage failed: %#v", err)
934937
}
935-
case strings.Contains(mtype, "audio") && regexp.MustCompile(`(aac|flac|matroska|mp4|mpeg|ogg|opus|vorbis|wav)$`).MatchString(mtype): // god this is such a hack
938+
case func() bool {
939+
if strings.HasPrefix(mtype, "audio/") {
940+
s, _ := strings.CutPrefix(mtype, "audio/")
941+
return slices.Contains(Audio_MimeTypes, s)
942+
} else {
943+
return false
944+
}
945+
}():
936946
b.Log.Debugf("sendAudio %s", res.ContentURI)
937947
err = b.retry(func() error {
938948
content := event.MessageEventContent{

0 commit comments

Comments
 (0)