aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/main.go b/main.go
index 755a0ec..a84bb7d 100644
--- a/main.go
+++ b/main.go
@@ -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)
+}