msgconv: port most of attachment and text message bridging
* Created a separate discordid package to avoid import cycles. * Implemented attachment bridging. We still need to implement direct media, but this will do for now. * Corrected how encrypted files (e.g. embed images and attachments) were bridged. Previously, the URL field would be empty. Still a lot of missing pieces. Thoughts: * Mentions to roles and custom emoji are not rendered properly. We need to maintain our own DB. * We might not need the "attachments" leaf package anymore? It's just there to avoid an import cycle. Bridging actual events (i.e. wiring up discordgo's event handlers) is probably next.
This commit is contained in:
@@ -28,9 +28,8 @@ import (
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/rs/zerolog"
|
||||
"go.mau.fi/mautrix-discord/pkg/attachment"
|
||||
"maunium.net/go/mautrix/bridgev2"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
func downloadDiscordAttachment(cli *http.Client, url string, maxSize int64) ([]byte, error) {
|
||||
@@ -69,20 +68,7 @@ func downloadDiscordAttachment(cli *http.Client, url string, maxSize int64) ([]b
|
||||
}
|
||||
}
|
||||
|
||||
type AttachmentReupload struct {
|
||||
DownloadingURL string
|
||||
FileName string
|
||||
MimeType string
|
||||
}
|
||||
|
||||
type ReuploadedAttachment struct {
|
||||
AttachmentReupload
|
||||
DownloadedSize int
|
||||
MXC id.ContentURIString
|
||||
EncryptedFile *event.EncryptedFileInfo
|
||||
}
|
||||
|
||||
func (d *DiscordConnector) ReuploadMedia(ctx context.Context, intent bridgev2.MatrixAPI, portal *bridgev2.Portal, upload AttachmentReupload) (*ReuploadedAttachment, error) {
|
||||
func (d *DiscordConnector) ReuploadMedia(ctx context.Context, intent bridgev2.MatrixAPI, portal *bridgev2.Portal, upload attachment.AttachmentReupload) (*attachment.ReuploadedAttachment, error) {
|
||||
log := zerolog.Ctx(ctx)
|
||||
// TODO(skip): Do we need to check if we've already downloaded this media before?
|
||||
// TODO(skip): Read a maximum size from the config.
|
||||
@@ -117,7 +103,7 @@ func (d *DiscordConnector) ReuploadMedia(ctx context.Context, intent bridgev2.Ma
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ReuploadedAttachment{
|
||||
return &attachment.ReuploadedAttachment{
|
||||
AttachmentReupload: upload,
|
||||
DownloadedSize: len(data),
|
||||
MXC: mxc,
|
||||
|
||||
Reference in New Issue
Block a user