aboutsummaryrefslogtreecommitdiffstats
path: root/giphyproxy
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2024-12-03 00:03:01 +0200
committerTulir Asokan <tulir@maunium.net>2024-12-03 00:03:01 +0200
commit8cea4a46d03dec1deb90b056bc0bf2c6ec5b6548 (patch)
tree89b28a15db67b8e92dca39623a10d1301b195c34 /giphyproxy
parent333567f481e60443360aa7199d481e1a45b3a523 (diff)
Make giphyproxy destination configurable
Diffstat (limited to 'giphyproxy')
-rw-r--r--giphyproxy/example-config.yaml3
-rw-r--r--giphyproxy/main.go7
2 files changed, 9 insertions, 1 deletions
diff --git a/giphyproxy/example-config.yaml b/giphyproxy/example-config.yaml
index 3bed981..0d7e226 100644
--- a/giphyproxy/example-config.yaml
+++ b/giphyproxy/example-config.yaml
@@ -15,3 +15,6 @@ server_key: CHANGE ME
hostname: 0.0.0.0
# Port where the proxy should listen on
port: 8008
+
+# Redirect destination. This can be changed to serve a different format.
+destination: https://i.giphy.com/%s.webp
diff --git a/giphyproxy/main.go b/giphyproxy/main.go
index 991a021..dc9c49a 100644
--- a/giphyproxy/main.go
+++ b/giphyproxy/main.go
@@ -33,12 +33,14 @@ import (
type Config struct {
mediaproxy.BasicConfig `yaml:",inline"`
mediaproxy.ServerConfig `yaml:",inline"`
+ Destination string `yaml:"destination"
}
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 giphyIDRegex = regexp.MustCompile(`^[a-zA-Z0-9-_]+$`)
+var destination = "https://i.giphy.com/%s.webp"
func main() {
flag.Parse()
@@ -51,6 +53,9 @@ func main() {
mp := exerrors.Must(mediaproxy.NewFromConfig(cfg.BasicConfig, getMedia))
mp.KeyServer.Version.Name = "maunium-stickerpicker giphy proxy"
mp.ForceProxyLegacyFederation = true
+ if cfg.Destination != "" {
+ destination = cfg.Destination
+ }
exerrors.PanicIfNotNil(mp.Listen(cfg.ServerConfig))
}
}
@@ -67,6 +72,6 @@ func getMedia(_ context.Context, id string) (response mediaproxy.GetMediaRespons
return nil, mediaproxy.ErrInvalidMediaIDSyntax
}
return &mediaproxy.GetMediaResponseURL{
- URL: fmt.Sprintf("https://i.giphy.com/%s.webp", id),
+ URL: fmt.Sprintf(destination, id),
}, nil
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage