Make giphyproxy destination configurable
This commit is contained in:
parent
333567f481
commit
8cea4a46d0
@ -15,3 +15,6 @@ server_key: CHANGE ME
|
|||||||
hostname: 0.0.0.0
|
hostname: 0.0.0.0
|
||||||
# Port where the proxy should listen on
|
# Port where the proxy should listen on
|
||||||
port: 8008
|
port: 8008
|
||||||
|
|
||||||
|
# Redirect destination. This can be changed to serve a different format.
|
||||||
|
destination: https://i.giphy.com/%s.webp
|
||||||
|
@ -33,12 +33,14 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
mediaproxy.BasicConfig `yaml:",inline"`
|
mediaproxy.BasicConfig `yaml:",inline"`
|
||||||
mediaproxy.ServerConfig `yaml:",inline"`
|
mediaproxy.ServerConfig `yaml:",inline"`
|
||||||
|
Destination string `yaml:"destination"
|
||||||
}
|
}
|
||||||
|
|
||||||
var configPath = flag.String("config", "config.yaml", "config file path")
|
var configPath = flag.String("config", "config.yaml", "config file path")
|
||||||
var generateServerKey = flag.Bool("generate-key", false, "generate a new server key and exit")
|
var generateServerKey = flag.Bool("generate-key", false, "generate a new server key and exit")
|
||||||
|
|
||||||
var giphyIDRegex = regexp.MustCompile(`^[a-zA-Z0-9-_]+$`)
|
var giphyIDRegex = regexp.MustCompile(`^[a-zA-Z0-9-_]+$`)
|
||||||
|
var destination = "https://i.giphy.com/%s.webp"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -51,6 +53,9 @@ func main() {
|
|||||||
mp := exerrors.Must(mediaproxy.NewFromConfig(cfg.BasicConfig, getMedia))
|
mp := exerrors.Must(mediaproxy.NewFromConfig(cfg.BasicConfig, getMedia))
|
||||||
mp.KeyServer.Version.Name = "maunium-stickerpicker giphy proxy"
|
mp.KeyServer.Version.Name = "maunium-stickerpicker giphy proxy"
|
||||||
mp.ForceProxyLegacyFederation = true
|
mp.ForceProxyLegacyFederation = true
|
||||||
|
if cfg.Destination != "" {
|
||||||
|
destination = cfg.Destination
|
||||||
|
}
|
||||||
exerrors.PanicIfNotNil(mp.Listen(cfg.ServerConfig))
|
exerrors.PanicIfNotNil(mp.Listen(cfg.ServerConfig))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,6 +72,6 @@ func getMedia(_ context.Context, id string) (response mediaproxy.GetMediaRespons
|
|||||||
return nil, mediaproxy.ErrInvalidMediaIDSyntax
|
return nil, mediaproxy.ErrInvalidMediaIDSyntax
|
||||||
}
|
}
|
||||||
return &mediaproxy.GetMediaResponseURL{
|
return &mediaproxy.GetMediaResponseURL{
|
||||||
URL: fmt.Sprintf("https://i.giphy.com/%s.webp", id),
|
URL: fmt.Sprintf(destination, id),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user