1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-28 22:55:39 -04:00

api: mirror user photos for better privacy

This commit is contained in:
Adhityaa Chandrasekar
2019-02-22 22:20:55 -05:00
parent 95093326e0
commit d4b466b04f
3 changed files with 37 additions and 18 deletions

34
api/commenter_photo.go Normal file
View 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)
}

View File

@ -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")