|
@@ -8,9 +8,10 @@ import (
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+ "io/ioutil"
|
|
|
|
|
|
log "gopkg.in/clog.v1"
|
|
|
-
|
|
|
+ "github.com/Unknwon/com"
|
|
|
"github.com/gogs/git-module"
|
|
|
|
|
|
"github.com/gogs/gogs/models"
|
|
@@ -19,10 +20,12 @@ import (
|
|
|
"github.com/gogs/gogs/pkg/form"
|
|
|
"github.com/gogs/gogs/pkg/mailer"
|
|
|
"github.com/gogs/gogs/pkg/setting"
|
|
|
+ "github.com/gogs/gogs/pkg/tool"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
SETTINGS_OPTIONS = "repo/settings/options"
|
|
|
+ SETTINGS_REPO_AVATAR = "repo/settings/avatar"
|
|
|
SETTINGS_COLLABORATION = "repo/settings/collaboration"
|
|
|
SETTINGS_BRANCHES = "repo/settings/branches"
|
|
|
SETTINGS_PROTECTED_BRANCH = "repo/settings/protected_branch"
|
|
@@ -632,3 +635,56 @@ func DeleteDeployKey(c *context.Context) {
|
|
|
"redirect": c.Repo.RepoLink + "/settings/keys",
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+func SettingsAvatar(c *context.Context) {
|
|
|
+ c.Title("settings.avatar")
|
|
|
+ c.PageIs("SettingsAvatar")
|
|
|
+ c.Success(SETTINGS_REPO_AVATAR)
|
|
|
+}
|
|
|
+
|
|
|
+func SettingsAvatarPost(c *context.Context, f form.Avatar) {
|
|
|
+ f.Source = form.AVATAR_LOCAL
|
|
|
+ if err := UpdateAvatarSetting(c, f); err != nil {
|
|
|
+ c.Flash.Error(err.Error())
|
|
|
+ } else {
|
|
|
+ c.Flash.Success(c.Tr("settings.update_avatar_success"))
|
|
|
+ }
|
|
|
+ c.SubURLRedirect(c.Repo.RepoLink + "/settings")
|
|
|
+}
|
|
|
+
|
|
|
+func SettingsDeleteAvatar(c *context.Context) {
|
|
|
+ if err := c.Repo.Repository.DeleteAvatar(); err != nil {
|
|
|
+ c.Flash.Error(fmt.Sprintf("DeleteAvatar: %v", err))
|
|
|
+ }
|
|
|
+ c.SubURLRedirect(c.Repo.RepoLink + "/settings")
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func UpdateAvatarSetting(c *context.Context, f form.Avatar) error {
|
|
|
+ ctxRepo := c.Repo.Repository;
|
|
|
+ if f.Avatar != nil {
|
|
|
+ r, err := f.Avatar.Open()
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("Avatar.Open: %v", err)
|
|
|
+ }
|
|
|
+ defer r.Close()
|
|
|
+
|
|
|
+ data, err := ioutil.ReadAll(r)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("ioutil.ReadAll: %v", err)
|
|
|
+ }
|
|
|
+ if !tool.IsImageFile(data) {
|
|
|
+ return errors.New(c.Tr("settings.uploaded_avatar_not_a_image"))
|
|
|
+ }
|
|
|
+ if err = ctxRepo.UploadAvatar(data); err != nil {
|
|
|
+ return fmt.Errorf("UploadAvatar: %v", err)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ if !com.IsFile(ctxRepo.CustomAvatarPath()) {
|
|
|
+ log.Trace("No avatar was uploaded for repo: %d. Default icon will appear instead.", ctxRepo.ID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|