aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--giphyproxy/main.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/giphyproxy/main.go b/giphyproxy/main.go
index c8bed12..3bf1620 100644
--- a/giphyproxy/main.go
+++ b/giphyproxy/main.go
@@ -22,6 +22,7 @@ import (
"fmt"
"os"
"regexp"
+ "slices"
"time"
"go.mau.fi/util/exerrors"
@@ -34,6 +35,7 @@ type Config struct {
mediaproxy.BasicConfig `yaml:",inline"`
mediaproxy.ServerConfig `yaml:",inline"`
Destination string `yaml:"destination"`
+ SplitIdx []int `yaml:"split_idx"`
}
var configPath = flag.String("config", "config.yaml", "config file path")
@@ -41,6 +43,7 @@ var generateServerKey = flag.Bool("generate-key", false, "generate a new server
var giphyIDRegex = regexp.MustCompile(`^[a-zA-Z0-9-_]+$`)
var destination = "https://i.giphy.com/%s.webp"
+var splitIdx []int
func main() {
flag.Parse()
@@ -54,6 +57,9 @@ func main() {
mp.KeyServer.Version.Name = "mautrix-go + maunium-stickerpicker giphy proxy"
if cfg.Destination != "" {
destination = cfg.Destination
+ splitIdx = cfg.SplitIdx
+ slices.Sort(splitIdx)
+ slices.Reverse(splitIdx)
}
exerrors.PanicIfNotNil(mp.Listen(cfg.ServerConfig))
}
@@ -70,6 +76,12 @@ func getMedia(_ context.Context, id string, _ map[string]string) (response media
if !giphyIDRegex.MatchString(id) {
return nil, mediaproxy.ErrInvalidMediaIDSyntax
}
+ for _, idx := range splitIdx {
+ if idx >= len(id) {
+ return nil, mediaproxy.ErrInvalidMediaIDSyntax
+ }
+ id = id[:idx] + "/" + id[idx:]
+ }
return &mediaproxy.GetMediaResponseURL{
URL: fmt.Sprintf(destination, id),
}, nil
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage