Skip to content

Commit

Permalink
MD5 -> SHA256
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Apr 12, 2024
1 parent c613140 commit f9cf19a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
12 changes: 0 additions & 12 deletions modules/utils/hash.go

This file was deleted.

2 changes: 2 additions & 0 deletions service/modules/avatar/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"sync"
)
Expand Down Expand Up @@ -62,6 +63,7 @@ func github(ctx context.Context, email string, p *Params) (*http.Response, error

githubLock.Lock()
githubEmailCache[email] = avatarURL
log.Println(`请求头像:`, avatarURL)
githubLock.Unlock()
}

Expand Down
11 changes: 7 additions & 4 deletions service/modules/avatar/gravatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ package avatar

import (
"context"
"crypto/sha256"
"errors"
"fmt"
"log"
"net/http"

"github.com/movsb/taoblog/modules/utils"
"strings"
)

const (
gGrAvatarHost = "https://www.gravatar.com/avatar"
)

func gravatar(ctx context.Context, email string, p *Params) (*http.Response, error) {
u := fmt.Sprintf(`%s/%s?d=mm&s=48`, gGrAvatarHost, utils.Md5Str(email))
func gravatar(_ context.Context, email string, p *Params) (*http.Response, error) {
sum := sha256.Sum256([]byte(strings.ToLower(email)))
u := fmt.Sprintf(`%s/%x?d=mm&s=100`, gGrAvatarHost, sum)
log.Println(`请求头像:`, u)
req, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit f9cf19a

Please sign in to comment.