mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-04 08:17:24 -05:00
save custom avatar as PNG
This commit is contained in:
parent
6a664e88c7
commit
1559bd58e7
@ -13,7 +13,7 @@ watch_dirs = [
|
||||
watch_exts = [".go"]
|
||||
build_delay = 1500
|
||||
cmds = [
|
||||
["go", "install"], # sqlite redis memcache cert pam tidb
|
||||
["go", "build"],
|
||||
["go", "install", "-race"], # sqlite redis memcache cert pam tidb
|
||||
["go", "build", "-race"],
|
||||
["./gogs", "web"]
|
||||
]
|
@ -14,6 +14,7 @@ import (
|
||||
"image"
|
||||
"image/jpeg"
|
||||
_ "image/jpeg"
|
||||
"image/png"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -253,11 +254,9 @@ func (u *User) ValidatePassword(passwd string) bool {
|
||||
// UploadAvatar saves custom avatar for user.
|
||||
// FIXME: split uploads to different subdirs in case we have massive users.
|
||||
func (u *User) UploadAvatar(data []byte) error {
|
||||
u.UseCustomAvatar = true
|
||||
|
||||
img, _, err := image.Decode(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Decode: %v", err)
|
||||
}
|
||||
|
||||
m := resize.Resize(234, 234, img, resize.NearestNeighbor)
|
||||
@ -268,19 +267,20 @@ func (u *User) UploadAvatar(data []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = sess.Id(u.Id).AllCols().Update(u); err != nil {
|
||||
return err
|
||||
u.UseCustomAvatar = true
|
||||
if err = updateUser(sess, u); err != nil {
|
||||
return fmt.Errorf("updateUser: %v", err)
|
||||
}
|
||||
|
||||
os.MkdirAll(setting.AvatarUploadPath, os.ModePerm)
|
||||
fw, err := os.Create(u.CustomAvatarPath())
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Create: %v", err)
|
||||
}
|
||||
defer fw.Close()
|
||||
|
||||
if err = jpeg.Encode(fw, m, nil); err != nil {
|
||||
return err
|
||||
if err = png.Encode(fw, m); err != nil {
|
||||
return fmt.Errorf("Encode: %v", err)
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
|
@ -39,6 +39,8 @@ import (
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
//FIXME: remove cache module
|
||||
|
||||
var gravatarSource string
|
||||
|
||||
func UpdateGravatarSource() {
|
||||
@ -153,7 +155,7 @@ func (this *Avatar) Encode(wr io.Writer, size int) (err error) {
|
||||
if img, err = decodeImageFile(imgPath); err != nil {
|
||||
return
|
||||
}
|
||||
m := resize.Resize(uint(size), 0, img, resize.NearestNeighbor)
|
||||
m := resize.Resize(uint(size), 0, img, resize.Lanczos3)
|
||||
return jpeg.Encode(wr, m, nil)
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ func Contexter() macaron.Handler {
|
||||
Session: sess,
|
||||
}
|
||||
// Compute current URL for real-time change language.
|
||||
ctx.Data["Link"] = setting.AppSubUrl + ctx.Req.URL.Path
|
||||
ctx.Data["Link"] = setting.AppSubUrl + strings.TrimSuffix(ctx.Req.URL.Path, "/")
|
||||
|
||||
ctx.Data["PageStartTime"] = time.Now()
|
||||
|
||||
|
@ -111,6 +111,7 @@ func Dashboard(ctx *middleware.Context) {
|
||||
|
||||
// Check access of private repositories.
|
||||
feeds := make([]*models.Action, 0, len(actions))
|
||||
unameAvatars := make(map[string]string)
|
||||
for _, act := range actions {
|
||||
if act.IsPrivate {
|
||||
// This prevents having to retrieve the repository for each action
|
||||
@ -122,16 +123,22 @@ func Dashboard(ctx *middleware.Context) {
|
||||
}
|
||||
|
||||
}
|
||||
// FIXME: cache results?
|
||||
u, err := models.GetUserByName(act.ActUserName)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
continue
|
||||
|
||||
// Cache results to reduce queries.
|
||||
_, ok := unameAvatars[act.ActUserName]
|
||||
if !ok {
|
||||
u, err := models.GetUserByName(act.ActUserName)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
continue
|
||||
}
|
||||
ctx.Handle(500, "GetUserByName", err)
|
||||
return
|
||||
}
|
||||
ctx.Handle(500, "GetUserByName", err)
|
||||
return
|
||||
unameAvatars[act.ActUserName] = u.AvatarLink()
|
||||
}
|
||||
act.ActAvatar = u.AvatarLink()
|
||||
|
||||
act.ActAvatar = unameAvatars[act.ActUserName]
|
||||
feeds = append(feeds, act)
|
||||
}
|
||||
ctx.Data["Feeds"] = feeds
|
||||
|
Loading…
Reference in New Issue
Block a user