From 592def143a694dbc8d39ddf3475721667422051e Mon Sep 17 00:00:00 2001 From: Umputun Date: Sun, 15 Jul 2018 12:11:48 -0500 Subject: [PATCH] clarify comments --- backend/app/rest/proxy/avatar.go | 18 +++++++++--------- backend/app/rest/proxy/image.go | 2 +- backend/app/store/avatar/store.go | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/app/rest/proxy/avatar.go b/backend/app/rest/proxy/avatar.go index 4c674ba0..7b71bcf1 100644 --- a/backend/app/rest/proxy/avatar.go +++ b/backend/app/rest/proxy/avatar.go @@ -16,7 +16,7 @@ import ( "github.com/umputun/remark/backend/app/store/avatar" ) -// Avatar provides file-system store and http handler for avatars +// Avatar provides http handler for avatars from avatar.Store // On user login auth will call Put and it will retrieve and save picture locally. type Avatar struct { Store avatar.Store @@ -24,7 +24,7 @@ type Avatar struct { RemarkURL string } -// Put stores retrieved avatar to StorePath. Gets image from user info. Returns proxied url +// Put stores retrieved avatar to avatar.Store. Gets image from user info. Returns proxied url func (p *Avatar) Put(u store.User) (avatarURL string, err error) { // no picture for user, try default avatar @@ -54,13 +54,13 @@ func (p *Avatar) Put(u store.User) (avatarURL string, err error) { return "", errors.Errorf("failed to get avatar from the orig, status %s", resp.Status) } - avatar, err := p.Store.Put(u.ID, resp.Body) + avatarID, err := p.Store.Put(u.ID, resp.Body) // put returns avatar base name, like 123456.image if err != nil { return "", err } - log.Printf("[DEBUG] saved avatar from %s to %s, user %q", u.Picture, avatar, u.Name) - return p.RemarkURL + p.RoutePath + "/" + avatar, nil + log.Printf("[DEBUG] saved avatar from %s to %s, user %q", u.Picture, avatarID, u.Name) + return p.RemarkURL + p.RoutePath + "/" + avatarID, nil } // Routes returns auth routes for given provider @@ -71,10 +71,10 @@ func (p *Avatar) Routes(middlewares ...func(http.Handler) http.Handler) (string, // GET /123456789.image router.Get("/{avatar}", func(w http.ResponseWriter, r *http.Request) { - avatar := chi.URLParam(r, "avatar") + avatarID := chi.URLParam(r, "avatar") // enforce client-side caching - etag := `"` + p.Store.ID(avatar) + `"` + etag := `"` + p.Store.ID(avatarID) + `"` w.Header().Set("Etag", etag) w.Header().Set("Cache-Control", "max-age=604800") // 7 days if match := r.Header.Get("If-None-Match"); match != "" { @@ -84,7 +84,7 @@ func (p *Avatar) Routes(middlewares ...func(http.Handler) http.Handler) (string, } } - avReader, size, err := p.Store.Get(avatar) + avReader, size, err := p.Store.Get(avatarID) if err != nil { rest.SendErrorJSON(w, r, http.StatusBadRequest, err, "can't load avatar") return @@ -92,7 +92,7 @@ func (p *Avatar) Routes(middlewares ...func(http.Handler) http.Handler) (string, defer func() { if e := avReader.Close(); e != nil { - log.Printf("[WARN] can't close avatar reader for %s, %s", avatar, e) + log.Printf("[WARN] can't close avatar reader for %s, %s", avatarID, e) } }() diff --git a/backend/app/rest/proxy/image.go b/backend/app/rest/proxy/image.go index 450dafc9..b24cbf04 100644 --- a/backend/app/rest/proxy/image.go +++ b/backend/app/rest/proxy/image.go @@ -113,7 +113,7 @@ func (p Image) extract(commentHTML string) ([]string, error) { return result, nil } -// replace img links in commentHTML with route to proxy with base64 encoded original link +// replace img links in commentHTML with route to proxy, base64 encoded original link func (p Image) replace(commentHTML string, imgs []string) string { for _, img := range imgs { diff --git a/backend/app/store/avatar/store.go b/backend/app/store/avatar/store.go index 276d3ad6..1b612bcf 100644 --- a/backend/app/store/avatar/store.go +++ b/backend/app/store/avatar/store.go @@ -22,9 +22,9 @@ const imgSfx = ".image" // Store defines interface to store and and load avatars type Store interface { - Put(userID string, reader io.Reader) (avatar string, err error) - Get(avatar string) (reader io.ReadCloser, size int, err error) - ID(avatar string) (id string) + Put(userID string, reader io.Reader) (avatarID string, err error) // save avatar data from the given reader and return base name + Get(avatarID string) (reader io.ReadCloser, size int, err error) // load avatar via reader + ID(avatarID string) (id string) // unique id of stored avatar's data } // resize an image of supported format (PNG, JPG, GIF) to the size of "limit" px of the biggest side