added features and fixes

This commit is contained in:
2026-07-02 15:34:00 +00:00
parent eb5b7d55a4
commit 89f8381e2d
30 changed files with 1718 additions and 206 deletions
+36
View File
@@ -3,8 +3,10 @@ package main
import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"net/url"
"os"
"strings"
@@ -262,6 +264,34 @@ func main() {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(gifs)
})
r.Get("/gifs/proxy", func(w http.ResponseWriter, r *http.Request) {
targetURL := r.URL.Query().Get("url")
if targetURL == "" {
http.Error(w, `{"error":"missing url"}`, http.StatusBadRequest)
return
}
// Verify it's a Giphy domain to prevent general proxy abuse
parsed, err := url.Parse(targetURL)
if err != nil || parsed.Scheme != "https" || !strings.HasSuffix(parsed.Host, ".giphy.com") {
http.Error(w, `{"error":"invalid proxy target"}`, http.StatusBadRequest)
return
}
resp, err := http.Get(targetURL)
if err != nil {
http.Error(w, `{"error":"failed to fetch image"}`, http.StatusInternalServerError)
return
}
defer resp.Body.Close()
// Stream response
w.Header().Set("Content-Type", resp.Header.Get("Content-Type"))
w.Header().Set("Content-Length", resp.Header.Get("Content-Length"))
w.Header().Set("Cache-Control", "public, max-age=604800") // Cache for 7 days
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
})
}
// File upload
@@ -312,6 +342,12 @@ func main() {
// File serving (public, for viewing uploaded files)
if uploadHandler != nil {
r.Get("/files/*", uploadHandler.Serve)
// Legacy redirect: old uploads returned /{bucket}/objectName
r.Get("/dumpster-files/*", func(w http.ResponseWriter, r *http.Request) {
objectName := strings.TrimPrefix(r.URL.Path, "/dumpster-files/")
http.Redirect(w, r, "/files/"+objectName, http.StatusMovedPermanently)
})
}
// Public webhook execution (no auth required)