mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 22:35:52 +01:00
mediaproxy: add basic config structs
This commit is contained in:
parent
7b845c947f
commit
3e302fb46f
3 changed files with 37 additions and 12 deletions
|
|
@ -10,6 +10,8 @@ import (
|
|||
"go.mau.fi/util/dbutil"
|
||||
"go.mau.fi/zeroconfig"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"maunium.net/go/mautrix/mediaproxy"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
|
@ -48,11 +50,8 @@ type ProvisioningConfig struct {
|
|||
}
|
||||
|
||||
type DirectMediaConfig struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
AllowProxy bool `yaml:"allow_proxy"`
|
||||
ServerName string `yaml:"server_name"`
|
||||
WellKnownResponse string `yaml:"well_known_response"`
|
||||
ServerKey string `yaml:"server_key"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
mediaproxy.BasicConfig `yaml:",inline"`
|
||||
}
|
||||
|
||||
type DoublePuppetConfig struct {
|
||||
|
|
|
|||
|
|
@ -35,16 +35,10 @@ func (br *Connector) initDirectMedia() error {
|
|||
return fmt.Errorf("direct media is enabled in config, but the network connector does not support it")
|
||||
}
|
||||
var err error
|
||||
br.MediaProxy, err = mediaproxy.New(br.Config.DirectMedia.ServerName, br.Config.DirectMedia.ServerKey, br.getDirectMedia)
|
||||
br.MediaProxy, err = mediaproxy.NewFromConfig(br.Config.DirectMedia.BasicConfig, br.getDirectMedia)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize media proxy: %w", err)
|
||||
}
|
||||
if br.Config.DirectMedia.WellKnownResponse != "" {
|
||||
br.MediaProxy.KeyServer.WellKnownTarget = br.Config.DirectMedia.WellKnownResponse
|
||||
}
|
||||
if !br.Config.DirectMedia.AllowProxy {
|
||||
br.MediaProxy.DisallowProxying()
|
||||
}
|
||||
br.MediaProxy.RegisterRoutes(br.AS.Router)
|
||||
br.dmaSigKey = sha256.Sum256(br.MediaProxy.GetServerKey().Priv.Seed())
|
||||
dmn.SetUseDirectMedia()
|
||||
|
|
|
|||
|
|
@ -94,6 +94,38 @@ func New(serverName string, serverKey string, getMedia GetMediaFunc) (*MediaProx
|
|||
}, nil
|
||||
}
|
||||
|
||||
type BasicConfig struct {
|
||||
ServerName string `yaml:"server_name" json:"server_name"`
|
||||
ServerKey string `yaml:"server_key" json:"server_key"`
|
||||
AllowProxy bool `yaml:"allow_proxy" json:"allow_proxy"`
|
||||
WellKnownResponse string `yaml:"well_known_response" json:"well_known_response"`
|
||||
}
|
||||
|
||||
func NewFromConfig(cfg BasicConfig, getMedia GetMediaFunc) (*MediaProxy, error) {
|
||||
mp, err := New(cfg.ServerName, cfg.ServerKey, getMedia)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !cfg.AllowProxy {
|
||||
mp.DisallowProxying()
|
||||
}
|
||||
if cfg.WellKnownResponse != "" {
|
||||
mp.KeyServer.WellKnownTarget = cfg.WellKnownResponse
|
||||
}
|
||||
return mp, nil
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Hostname string `yaml:"hostname" json:"hostname"`
|
||||
Port uint16 `yaml:"port" json:"port"`
|
||||
}
|
||||
|
||||
func (mp *MediaProxy) Listen(cfg ServerConfig) error {
|
||||
router := mux.NewRouter()
|
||||
mp.RegisterRoutes(router)
|
||||
return http.ListenAndServe(fmt.Sprintf("%s:%d", cfg.Hostname, cfg.Port), router)
|
||||
}
|
||||
|
||||
func (mp *MediaProxy) GetServerName() string {
|
||||
return mp.serverName
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue