浏览代码

Add options to disable or force-enable caching media

Tulir Asokan 2 年之前
父节点
当前提交
cc2d0ae40d
共有 4 个文件被更改,包括 7 次插入1 次删除
  1. 1 1
      attachments.go
  2. 1 0
      config/bridge.go
  3. 1 0
      config/upgrade.go
  4. 4 0
      example-config.yaml

+ 1 - 1
attachments.go

@@ -246,7 +246,7 @@ func (br *DiscordBridge) convertLottie(data []byte) ([]byte, string, error) {
 }
 
 func (br *DiscordBridge) copyAttachmentToMatrix(intent *appservice.IntentAPI, url string, encrypt bool, meta AttachmentMeta) (returnDBFile *database.File, returnErr error) {
-	isCacheable := !encrypt
+	isCacheable := br.Config.Bridge.CacheMedia != "never" && (br.Config.Bridge.CacheMedia == "always" || !encrypt)
 	returnDBFile = br.DB.File.Get(url, encrypt)
 	if returnDBFile == nil {
 		transferKey := attachmentKey{url, encrypt}

+ 1 - 0
config/bridge.go

@@ -52,6 +52,7 @@ type BridgeConfig struct {
 	DeleteGuildOnLeave          bool `yaml:"delete_guild_on_leave"`
 	FederateRooms               bool `yaml:"federate_rooms"`
 
+	CacheMedia    string        `yaml:"cache_media"`
 	MediaPatterns MediaPatterns `yaml:"media_patterns"`
 
 	AnimatedSticker struct {

+ 1 - 0
config/upgrade.go

@@ -56,6 +56,7 @@ func DoUpgrade(helper *up.Helper) {
 	helper.Copy(up.Bool, "bridge", "delete_guild_on_leave")
 	helper.Copy(up.Bool, "bridge", "federate_rooms")
 	helper.Copy(up.Bool, "bridge", "media_patterns", "enabled")
+	helper.Copy(up.Str, "bridge", "cache_media")
 	helper.Copy(up.Str|up.Null, "bridge", "media_patterns", "attachments")
 	helper.Copy(up.Str|up.Null, "bridge", "media_patterns", "emojis")
 	helper.Copy(up.Str|up.Null, "bridge", "media_patterns", "stickers")

+ 4 - 0
example-config.yaml

@@ -145,6 +145,10 @@ bridge:
     # Whether or not created rooms should have federation enabled.
     # If false, created portal rooms will never be federated.
     federate_rooms: true
+    # Should mxc uris copied from Discord be cached?
+    # This can be `never` to never cache, `unencrypted` to only cache unencrypted mxc uris, or `always` to cache everything.
+    # If you have a media repo that generates non-unique mxc uris, you should set this to never.
+    cache_media: unencrypted
     # Patterns for converting Discord media to custom mxc:// URIs instead of reuploading.
     # Each of the patterns can be set to null to disable custom URIs for that type of media.
     # More details can be found at https://docs.mau.fi/bridges/go/discord/direct-media.html