add comments

This commit is contained in:
Umputun
2018-03-04 02:03:01 -06:00
parent 2be0eace55
commit 86de8d5fa4
5 changed files with 13 additions and 11 deletions
+1
View File
@@ -1,3 +1,4 @@
// Package auth provides oauth2 support as well as related middlewares.
package auth
import (
+6 -4
View File
@@ -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))
+2 -6
View File
@@ -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")
+3
View File
@@ -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 {
+1 -1
View File
@@ -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