diff --git a/app/rest/auth/auth.go b/app/rest/auth/auth.go index f2aff163..00afc74f 100644 --- a/app/rest/auth/auth.go +++ b/app/rest/auth/auth.go @@ -1,3 +1,4 @@ +// Package auth provides oauth2 support as well as related middlewares. package auth import ( diff --git a/app/rest/auth/avatar.go b/app/rest/auth/avatar.go index bbd4c554..7e6a41f9 100644 --- a/app/rest/auth/avatar.go +++ b/app/rest/auth/avatar.go @@ -30,9 +30,10 @@ type AvatarProxy struct { const imgSfx = ".image" -// Put gets original avatar url from user info and returns proxied url +// Put stores retrieved avatar to StorePath. Gets image from user info. Returns proxied url func (p *AvatarProxy) Put(u store.User) (avatarURL string, err error) { + // no picture for user, try default avatar if u.Picture == "" { if p.DefaultAvatar != "" { return p.Default(), nil @@ -128,14 +129,15 @@ func (p *AvatarProxy) Default() string { // encodeID hashes user id to sha1 func (p *AvatarProxy) encodeID(id string) string { h := sha1.New() - _, err := h.Write([]byte(id)) - if err != nil { + if _, err := h.Write([]byte(id)); err != nil { + log.Printf("[WARN] can't hash id %s, %s", id, err) return id } return fmt.Sprintf("%x", h.Sum(nil)) } -// get location for user id by adding partion to final path +// get location for user id by adding partion to final path in order to keep files +// in different subdirectories and avoid too many files in a single place. // the end result is a full path like this - /tmp/avatars.test/92 func (p *AvatarProxy) location(id string) string { checksum64 := crc64.Checksum([]byte(id), crc64.MakeTable(crc64.ECMA)) diff --git a/app/rest/auth/provider.go b/app/rest/auth/provider.go index 54d9352a..5d683ec2 100644 --- a/app/rest/auth/provider.go +++ b/app/rest/auth/provider.go @@ -1,4 +1,3 @@ -// Package auth provides oauth2 support as well as related middlewares. package auth import ( @@ -30,7 +29,7 @@ type Provider struct { InfoURL string Endpoint oauth2.Endpoint Scopes []string - MapUser func(userData, []byte) store.User + MapUser func(userData, []byte) store.User // map info from InfoURL to User avatarProxy *AvatarProxy conf *oauth2.Config @@ -198,10 +197,7 @@ func (p Provider) LogoutHandler(w http.ResponseWriter, r *http.Request) { return } - session.Values["uinfo"] = "" - session.Values["from"] = "" - session.Values["state"] = "" - + session.Values["uinfo"], session.Values["from"], session.Values["state"] = "", "", "" delete(session.Values, "uinfo") delete(session.Values, "from") delete(session.Values, "state") diff --git a/app/store/bolt.go b/app/store/bolt.go index 59a57ecb..448ad9b6 100644 --- a/app/store/bolt.go +++ b/app/store/bolt.go @@ -317,6 +317,7 @@ func (b *BoltDB) IsBlocked(siteID string, userID string) (blocked bool) { } // Blocked get lists of blocked users for given site +// bucket uses userID: func (b *BoltDB) Blocked(siteID string) (users []BlockedUser, err error) { users = []BlockedUser{} bdb, err := b.db(siteID) @@ -467,6 +468,7 @@ func (b *BoltDB) Put(locator Locator, comment Comment) error { }) } +// getPostBucket return bucket with all comments for postURL func (b *BoltDB) getPostBucket(tx *bolt.Tx, postURL string) (*bolt.Bucket, error) { postsBkt := tx.Bucket([]byte(postsBucketName)) if postsBkt == nil { @@ -479,6 +481,7 @@ func (b *BoltDB) getPostBucket(tx *bolt.Tx, postURL string) (*bolt.Bucket, error return res, nil } +// makePostBucket create new bucket for postURL as a key. This bucket holds all comments for the post. func (b *BoltDB) makePostBucket(tx *bolt.Tx, postURL string) (*bolt.Bucket, error) { postsBkt := tx.Bucket([]byte(postsBucketName)) if postsBkt == nil { diff --git a/app/store/comment.go b/app/store/comment.go index 8738049c..080c16ea 100644 --- a/app/store/comment.go +++ b/app/store/comment.go @@ -71,7 +71,7 @@ func (c *Comment) Sanitize() { c.Text = strings.Replace(c.Text, "\t", "", -1) } -// SetDeleted clears comment info, reset to "Deleted/Blocked" +// SetDeleted clears comment info, reset to deleted state func (c *Comment) SetDeleted() { c.Text = "this comment was deleted" c.Score = 0