aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2018-04-24 21:12:44 -0700
committerAdam Mathes <adam@trenchant.org>2018-04-24 21:12:44 -0700
commit5d063b0f8f7dee735cc5eeb8e21c37a9f453bacd (patch)
tree8bd951c97eeb80ce191584c6094a12cb3ea13ee0 /web
parent0f46131d74bc2af6a5dd18f67546944981968c43 (diff)
downloadneko-5d063b0f8f7dee735cc5eeb8e21c37a9f453bacd.tar.gz
neko-5d063b0f8f7dee735cc5eeb8e21c37a9f453bacd.tar.bz2
neko-5d063b0f8f7dee735cc5eeb8e21c37a9f453bacd.zip
wip img proxy
Diffstat (limited to 'web')
-rw-r--r--web/web.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/web/web.go b/web/web.go
index 0dd0025..d871990 100644
--- a/web/web.go
+++ b/web/web.go
@@ -5,9 +5,11 @@ import (
"adammathes.com/neko/crawler"
"adammathes.com/neko/models/feed"
"adammathes.com/neko/models/item"
+ "encoding/base64"
"encoding/json"
"fmt"
"golang.org/x/crypto/bcrypt"
+ "io/ioutil"
"log"
"net/http"
"path"
@@ -128,6 +130,29 @@ func categoryHandler(w http.ResponseWriter, r *http.Request) {
}
}
+func imageProxyHandler(w http.ResponseWriter, r *http.Request) {
+ // caching...???
+
+ imgURL := r.URL.String()
+ fmt.Printf("proxying: %s\n", imgURL)
+ decodedURL, err := base64.URLEncoding.DecodeString(imgURL)
+ fmt.Printf("decoded: %s\n", decodedURL)
+
+ resp, err := http.Get(string(decodedURL))
+ if err != nil {
+ http.Error(w, "sorry", 404)
+ return
+ }
+
+ bts, _ := ioutil.ReadAll(resp.Body)
+
+ etag := crypto.HashFromBytes(body)
+
+ w.Header().Set("Content-Type", "application/json")
+ w.Write(bts)
+ return
+}
+
var AuthCookie = "auth"
var SecondsInAYear = 60 * 60 * 24 * 365
@@ -186,6 +211,7 @@ func Serve() {
http.HandleFunc("/item/", AuthWrap(itemHandler))
http.HandleFunc("/feed/", AuthWrap(feedHandler))
http.HandleFunc("/tag/", AuthWrap(categoryHandler))
+ http.Handle("/image/", http.StripPrefix("/image/", AuthWrap(imageProxyHandler)))
http.HandleFunc("/login/", loginHandler)
http.HandleFunc("/logout/", logoutHandler)