Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 49125afb8c057d75b3f7bfe4811921c648fc7896 Author: selfhoster1312 <selfhoster1312@kl.netlib.re> Date: Sun Jan 04 17:21:13 2026 +0000 mediaserver: Deprecate `MediaServerUpload` diff --git a/bridge/config/config.go b/bridge/config/config.go index 7079d42..37a99eb 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -15010 +1509 @@ type Protocol struct {   Login string // mattermost, matrix   LogFile string // general   MediaDownloadBlackList []string - MediaDownloadPath string // Basically MediaServerUpload, but instead of uploading it, just write it to a file on the same server. + MediaDownloadPath string // Write upload to a file on the same server.   MediaDownloadSize int // all protocols   MediaServerDownload string - MediaServerUpload string   MediaConvertTgs string // telegram   MediaConvertWebPToPNG bool // telegram   MessageDelay int // IRC, time in millisecond to wait between messages diff --git a/bridge/mattermost/handlers.go b/bridge/mattermost/handlers.go index a4743b3..88e4475 100644 --- a/bridge/mattermost/handlers.go +++ b/bridge/mattermost/handlers.go @@ -1097 +1097 @@ func (b *Bmattermost) handleMatterClient(messages chan *config.Message) {   }     // only download avatars if we have a place to upload them (configured mediaserver) - if b.General.MediaServerUpload != "" || b.General.MediaDownloadPath != "" { + if b.General.MediaDownloadPath != "" {   b.handleDownloadAvatar(message.UserID, channelName)   }   diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index ea63760..b857b56 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -1477 +1477 @@ func (b *Btelegram) handleUsername(rmsg *config.Message, message *tgbotapi.Messa   }   }   // only download avatars if we have a place to upload them (configured mediaserver) - if b.General.MediaServerUpload != "" || (b.General.MediaServerDownload != "" && b.General.MediaDownloadPath != "") { + if b.General.MediaServerDownload != "" && b.General.MediaDownloadPath != "" {   b.handleDownloadAvatar(message.From.ID, rmsg.Channel)   }   } @@ -1717 +1717 @@ func (b *Btelegram) handleUsername(rmsg *config.Message, message *tgbotapi.Messa   }   }   // only download avatars if we have a place to upload them (configured mediaserver) - if b.General.MediaServerUpload != "" || (b.General.MediaServerDownload != "" && b.General.MediaDownloadPath != "") { + if b.General.MediaServerDownload != "" && b.General.MediaDownloadPath != "" {   b.handleDownloadAvatar(message.SenderChat.ID, rmsg.Channel)   }   } diff --git a/changelog.md b/changelog.md index 03a9239..fcad7f4 100644 --- a/changelog.md +++ b/changelog.md @@ -166 +169 @@  - xmpp: Initial replies/edits support has been removed, because it was incorrect ([#12](https://github.com/matterbridge-org/matterbridge/pull/12))  - xmpp: `NoTls` setting has been deprecated; to disable `StartTls` and start a plaintext connection, use `NoStartTls`  - Go required version is now v1.24 +- `MediaServerUpload` has been deprecated ([#30](https://github.com/matterbridge-org/matterbridge/issues/30)), + because we don't know how to make it work and were improving those parts of the codebase. + If you were successfully using it, your feedback is welcome and we may reintroduce it.    ## New Features   diff --git a/docs/advanced/mediaserver.md b/docs/advanced/mediaserver.md index 2f2bbc8..140f8b2 100644 --- a/docs/advanced/mediaserver.md +++ b/docs/advanced/mediaserver.md @@ -246 +215 @@ Matterbridge is not going to implement it's own "mediaserver" instead we make us  This mediaserver will be used to upload media to services that don't have support for uploading images/video/files.  At this moment this is xmpp and irc   -There are 2 options to set this up: -* You already have a webserver running - * Matterbridge runs on the same server see [local download](#use-local-download) - * Matterbridge runs on another server. If the webserver is using caddy, see [caddy](#use-remote-upload) -* You don't have a webserver running - * See [caddy](#use-remote-upload) +> [!INFO] +> The `MediaServerUpload` option has been deprecated. If you are using it and would like to +> help reimplement and document it, please open an issue or a pull request.   -# Use remote upload -## Caddy -In this case we're using caddy for upload/downloading media. -Caddy has automatic https support, so I'm going to describe this for https only. - - -### caddy install / configuration -Go to https://caddyserver.com/download -Enable `http.upload` as plugin - -Make sure the process you're running caddy with has read/write access to `/var/www/upload/` - -Sample Caddyfile -``` -yourserver.com:443 { - log stdout - root /var/www/upload/ - browse - basicauth /web/upload a_user a_password - upload /upload { - to "/var/www/upload/" - } -} -``` -### matterbridge configuration -configuration needs to happen in `[general]` -``` -[general] -MediaServerUpload="https://a_user:a_password@yourserver.com/upload" -MediaServerDownload="https://yourserver.com/" -``` +Running the media server requires a web server which publicly serves files +in a given directory, where matterbridge can write the files.    # Use local download +  In this case we're using matterbridge to download to a local path your webserver has read access to and matterbridge has write access to.  Matterbridge is running on this same server.   diff --git a/docs/settings.md b/docs/settings.md index e5399ef..67f4f48 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -2099 +2097 @@ Example: do not upload html and htm extension  `MediaDownloadBlacklist=[".html$",".htm$"]`    ## MediaDownloadPath -MediaDownloadPath is the filesystem path where the media file will be placed, instead of uploaded, for if Matterbridge has write access to the directory your webserver is serving. \ -It is an alternative to MediaServerUpload. -More information https://github.com/42wim/matterbridge/wiki/Mediaserver-setup-%28advanced%29 +MediaDownloadPath is the filesystem path where the media file will be placed, instead of uploaded, for if Matterbridge has write access to the directory your webserver is serving. [More information](https://github.com/matterbridge-org/matterbridge/blob/master/docs/advanced/mediaserver.md)    Setting: OPTIONAL, RELOADABLE, GENERAL \  Format: string \ @@ -2207 +2188 @@ Example:  `MediaDownloadPath="/srv/http/yourserver.com/public/download"`    ## MediaDownloadSize -Maximum size in bytes matterbridge will download for use with (`MediaServerUpload` and `MediaDownloadPath`) +Maximum size in bytes matterbridge will download for use with upload to the +media server or to other bridges.    Setting: OPTIONAL, RELOADABLE, GENERAL \  Format: int \ @@ -24019 +2393 @@ Format: string \  Example:    `MediaServerDownload="https://youserver.com/download"` - - -## MediaServerUpload -Used for uploading images/files/video to a remote "mediaserver" (a webserver like caddy for example). \ -When configured images/files uploaded on bridges like mattermost, slack, telegram will be -downloaded and uploaded again to MediaServerUpload URL. -More information https://github.com/42wim/matterbridge/wiki/Mediaserver-setup-%28advanced%29 - -Setting: OPTIONAL, RELOADABLE, GENERAL \ -Format: string \ -Example: - -`MediaServerUpload="https://user:pass@yourserver.com/upload"` - -## RemoteNickFormat -See [RemoteNickFormat](#RemoteNickFormat) diff --git a/gateway/handlers.go b/gateway/handlers.go index a151d58..b934f53 100644 --- a/gateway/handlers.go +++ b/gateway/handlers.go @@ -115 +112 @@  package gateway    import ( - "bytes"   "crypto/sha1" //nolint:gosec   "fmt" - "net/http"   "os"   "path/filepath"   "regexp"   "strings" - "time"     "github.com/matterbridge-org/matterbridge/bridge"   "github.com/matterbridge-org/matterbridge/bridge/config" @@ -719 +687 @@ func (gw *Gateway) handleFiles(msg *config.Message) {   reg := regexp.MustCompile("[^a-zA-Z0-9]+")     // If we don't have a attachfield or we don't have a mediaserver configured return - if msg.Extra == nil || - (gw.BridgeValues().General.MediaServerUpload == "" && - gw.BridgeValues().General.MediaDownloadPath == "") { + if msg.Extra == nil || gw.BridgeValues().General.MediaDownloadPath == "" {   return   }   @@ -9118 +8611 @@ func (gw *Gateway) handleFiles(msg *config.Message) {     sha1sum := fmt.Sprintf("%x", sha1.Sum(*fi.Data))[:8] //nolint:gosec   - if gw.BridgeValues().General.MediaServerUpload != "" { - // Use MediaServerUpload. Upload using a PUT HTTP request and basicauth. - if err := gw.handleFilesUpload(&fi); err != nil { - gw.logger.Error(err) - continue - } - } else { - // Use MediaServerPath. Place the file on the current filesystem. - if err := gw.handleFilesLocal(&fi); err != nil { - gw.logger.Error(err) - continue - } + // Use MediaServerPath. Place the file on the current filesystem. + err := gw.handleFilesLocal(&fi) + if err != nil { + gw.logger.Error(err) + continue   }     // Download URL. @@ -11831 +1066 @@ func (gw *Gateway) handleFiles(msg *config.Message) {   }  }   -// handleFilesUpload uses MediaServerUpload configuration to upload the file. -// Returns error on failure. -func (gw *Gateway) handleFilesUpload(fi *config.FileInfo) error { - client := &http.Client{ - Timeout: time.Second * 5, - } - // Use MediaServerUpload. Upload using a PUT HTTP request and basicauth. - sha1sum := fmt.Sprintf("%x", sha1.Sum(*fi.Data))[:8] //nolint:gosec - url := gw.BridgeValues().General.MediaServerUpload + "/" + sha1sum + "/" + fi.Name - - req, err := http.NewRequest("PUT", url, bytes.NewReader(*fi.Data)) - if err != nil { - return fmt.Errorf("mediaserver upload failed, could not create request: %#v", err) - } - - gw.logger.Debugf("mediaserver upload url: %s", url) - - req.Header.Set("Content-Type", "binary/octet-stream") - _, err = client.Do(req) - if err != nil { - return fmt.Errorf("mediaserver upload failed, could not Do request: %#v", err) - } - return nil -} -  // handleFilesLocal use MediaServerPath configuration, places the file on the current filesystem.  // Returns error on failure.  func (gw *Gateway) handleFilesLocal(fi *config.FileInfo) error { diff --git a/gateway/router.go b/gateway/router.go index f129c1b..a8aad1a 100644 --- a/gateway/router.go +++ b/gateway/router.go @@ -586 +5812 @@ func NewRouter(rootLogger *logrus.Logger, cfg config.Config, bridgeMap map[strin  // Start will connect all gateways belonging to this router and subsequently route messages  // between them.  func (r *Router) Start() error { + // Deprecating MediaServerUpload. Remove in future v2.1 release + deprecatedValue, _ := r.GetString("MediaServerUpload") + if deprecatedValue != "" { + r.logger.Fatal("MediaServerUpload config option has been deprecated. You should either remove this option from your configuration, or help us document it.") + } +   m := make(map[string]*bridge.Bridge)   if len(r.Gateways) == 0 {   return fmt.Errorf("no [[gateway]] configured. See https://github.com/42wim/matterbridge/wiki/How-to-create-your-config for more info") diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 1030436..7653e14 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -162820 +162813 @@ RemoteNickFormat="[{PROTOCOL}] <{NICK}> "  StripNick=false     -#MediaServerUpload (or MediaDownloadPath) and MediaServerDownload are used for uploading -#images/files/video to a remote "mediaserver" (a webserver like caddy for example). -#When configured images/files uploaded on bridges like mattermost, slack, telegram will be -#downloaded and uploaded again to MediaServerUpload URL  #MediaDownloadPath is the filesystem path where the media file will be placed, instead of uploaded,  #for if Matterbridge has write access to the directory your webserver is serving. -#It is an alternative to MediaServerUpload.  #The MediaServerDownload will be used so that bridges without native uploading support:  #irc and xmpp will be shown links to the files on MediaServerDownload  #  #More information https://github.com/42wim/matterbridge/wiki/Mediaserver-setup-%28advanced%29  #OPTIONAL (default empty) -MediaServerUpload="https://user:pass@yourserver.com/upload" -#OPTIONAL (default empty)  MediaDownloadPath="/srv/http/yourserver.com/public/download"  #OPTIONAL (default empty)  MediaServerDownload="https://youserver.com/download"