api: mirror user photos for better privacy
This commit is contained in:
parent
95093326e0
commit
d4b466b04f
34
api/commenter_photo.go
Normal file
34
api/commenter_photo.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func commenterPhotoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := commenterGetByHex(r.FormValue("commenterHex"))
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
url := c.Photo
|
||||
if c.Provider == "google" {
|
||||
url += "?sz=50"
|
||||
} else if c.Provider == "github" {
|
||||
url += "&s=50"
|
||||
} else if c.Provider == "twitter" {
|
||||
url += "?size=normal"
|
||||
} else if c.Provider == "gitlab" {
|
||||
url += "?width=50"
|
||||
}
|
||||
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
io.Copy(w, resp.Body)
|
||||
}
|
@ -27,6 +27,7 @@ func apiRouterInit(router *mux.Router) error {
|
||||
router.HandleFunc("/api/commenter/new", commenterNewHandler).Methods("POST")
|
||||
router.HandleFunc("/api/commenter/login", commenterLoginHandler).Methods("POST")
|
||||
router.HandleFunc("/api/commenter/self", commenterSelfHandler).Methods("POST")
|
||||
router.HandleFunc("/api/commenter/photo", commenterPhotoHandler).Methods("GET")
|
||||
|
||||
router.HandleFunc("/api/email/get", emailGetHandler).Methods("POST")
|
||||
router.HandleFunc("/api/email/update", emailUpdateHandler).Methods("POST")
|
||||
|
@ -258,15 +258,7 @@
|
||||
classAdd(avatar, "avatar");
|
||||
} else {
|
||||
avatar = create("img");
|
||||
if (commenter.provider === "google") {
|
||||
attrSet(avatar, "src", commenter.photo + "?sz=50");
|
||||
} else if (commenter.provider === "github") {
|
||||
attrSet(avatar, "src", commenter.photo + "&s=50");
|
||||
} else if (commenter.provider === "twitter") {
|
||||
attrSet(avatar, "src", commenter.photo + "?size=normal");
|
||||
} else {
|
||||
attrSet(avatar, "src", commenter.photo);
|
||||
}
|
||||
attrSet(avatar, "src", cdn + "/api/commenter/photo?commenterHex=" + commenter.commenterHex);
|
||||
classAdd(avatar, "avatar-img");
|
||||
}
|
||||
|
||||
@ -743,15 +735,7 @@
|
||||
classAdd(avatar, "avatar");
|
||||
} else {
|
||||
avatar = create("img");
|
||||
if (commenter.provider === "google") {
|
||||
attrSet(avatar, "src", commenter.photo + "?sz=50");
|
||||
} else if (commenter.provider === "github") {
|
||||
attrSet(avatar, "src", commenter.photo + "&s=50");
|
||||
} else if (commenter.provider === "twitter") {
|
||||
attrSet(avatar, "src", commenter.photo + "?size=normal");
|
||||
} else {
|
||||
attrSet(avatar, "src", commenter.photo);
|
||||
}
|
||||
attrSet(avatar, "src", cdn + "/api/commenter/photo?commenterHex=" + commenter.commenterHex);
|
||||
classAdd(avatar, "avatar-img");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user