Explorar o código

Use proxy URLs for all embed media

Tulir Asokan %!s(int64=2) %!d(string=hai) anos
pai
achega
2c3a8fb64e
Modificáronse 3 ficheiros con 7 adicións e 7 borrados
  1. 1 1
      go.mod
  2. 2 2
      go.sum
  3. 4 4
      portal.go

+ 1 - 1
go.mod

@@ -33,4 +33,4 @@ require (
 	maunium.net/go/mauflag v1.0.0 // indirect
 )
 
-replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20230113165952-ad6bb301721d
+replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20230128125530-7c5c85c576ec

+ 2 - 2
go.sum

@@ -1,6 +1,6 @@
 github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
-github.com/beeper/discordgo v0.0.0-20230113165952-ad6bb301721d h1:ce6Ib+y+4Iz5ogGUs23/1dVxvVrV/MqJZ7I2tZA8YH0=
-github.com/beeper/discordgo v0.0.0-20230113165952-ad6bb301721d/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
+github.com/beeper/discordgo v0.0.0-20230128125530-7c5c85c576ec h1:/qfpiffS/BMmkHigNz+3n2216oY67i1UvMoe5B6Baes=
+github.com/beeper/discordgo v0.0.0-20230128125530-7c5c85c576ec/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
 github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

+ 4 - 4
portal.go

@@ -707,9 +707,9 @@ func (portal *Portal) convertDiscordLinkEmbedsToBeeper(intent *appservice.Intent
 		preview.Title = embed.Title
 		preview.Description = embed.Description
 		if embed.Image != nil {
-			portal.convertDiscordLinkEmbedImage(intent, embed.Image.URL, embed.Image.Width, embed.Image.Height, &preview)
+			portal.convertDiscordLinkEmbedImage(intent, embed.Image.ProxyURL, embed.Image.Width, embed.Image.Height, &preview)
 		} else if embed.Thumbnail != nil {
-			portal.convertDiscordLinkEmbedImage(intent, embed.Thumbnail.URL, embed.Thumbnail.Width, embed.Thumbnail.Height, &preview)
+			portal.convertDiscordLinkEmbedImage(intent, embed.Thumbnail.ProxyURL, embed.Thumbnail.Width, embed.Thumbnail.Height, &preview)
 		}
 		previews = append(previews, preview)
 	}
@@ -722,7 +722,7 @@ type ConvertedMessage struct {
 }
 
 func (portal *Portal) convertDiscordVideoEmbed(intent *appservice.IntentAPI, embed *discordgo.MessageEmbed) ConvertedMessage {
-	dbFile, err := portal.bridge.copyAttachmentToMatrix(intent, embed.Video.URL, portal.Encrypted, "", "")
+	dbFile, err := portal.bridge.copyAttachmentToMatrix(intent, embed.Video.ProxyURL, portal.Encrypted, "", "")
 	if err != nil {
 		return ConvertedMessage{Content: portal.createMediaFailedMessage(err)}
 	}
@@ -934,7 +934,7 @@ func (portal *Portal) handleDiscordRichEmbed(intent *appservice.IntentAPI, embed
 }
 
 func isPlainGifMessage(msg *discordgo.Message) bool {
-	return len(msg.Embeds) == 1 && msg.Embeds[0].Video != nil && msg.Embeds[0].URL == msg.Content
+	return len(msg.Embeds) == 1 && msg.Embeds[0].Video != nil && msg.Embeds[0].URL == msg.Content && msg.Embeds[0].Type == discordgo.EmbedTypeGifv
 }
 
 func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Message, thread *Thread) {