diff options
author | FChannel <> | 2021-07-07 10:46:04 -0700 |
---|---|---|
committer | FChannel <> | 2021-07-07 10:46:04 -0700 |
commit | c78d2f1d22e49868870166ead4b115731e054b4f (patch) | |
tree | 0a3e696fa278097b07331245279c3a73eb135aae /main.go | |
parent | e859b3bc4e7e9c5a77ec2283088a042eb7b1b6e1 (diff) |
added media proxy for remote links
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -21,6 +21,8 @@ import ( "bufio" "io" "github.com/gofrs/uuid" + "crypto/sha256" + "encoding/hex" ) var Port = ":" + GetConfigValue("instanceport") @@ -45,6 +47,8 @@ var Salt = GetConfigValue("instancesalt") var activitystreams = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" +var MediaHashs = make(map[string]string) + func main() { CreatedNeededDirectories() @@ -1203,6 +1207,10 @@ func main() { go AddInstanceToIndexDB(db, actor) }) + http.HandleFunc("/api/media", func(w http.ResponseWriter, r *http.Request) { + RouteImages(w, r.URL.Query().Get("hash")) + }) + fmt.Println("Server for " + Domain + " running on port " + Port) fmt.Println("Mod key: " + *Key) @@ -2566,3 +2574,30 @@ func GetCollectionFromReq(path string) Collection { return respCollection } +func HashMedia(media string) string { + h:= sha256.New() + h.Write([]byte(media)) + return hex.EncodeToString(h.Sum(nil)) +} + +func RouteImages(w http.ResponseWriter, media string) { + + req, err := http.NewRequest("GET", MediaHashs[media], nil) + + CheckError(err, "error with Route Images req") + + resp, err := http.DefaultClient.Do(req) + + CheckError(err, "error with Route Images resp") + + defer resp.Body.Close() + + body, _ := ioutil.ReadAll(resp.Body) + for name, values := range resp.Header { + for _, value := range values { + w.Header().Set(name, value) + } + } + + w.Write(body) +} |