diff options
author | Unknwon <u@gogs.io> | 2016-08-12 02:29:29 -0700 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-08-14 23:52:24 -0700 |
commit | 15845cb28763c1542556ad61d2aa9735541dbf45 (patch) | |
tree | 94b2053202fcf5270e0697fc37c38203310571ed /routers | |
parent | d0a0239bacf02eb004634dfe1bb0a3f7dfe5adb6 (diff) | |
download | gitea-15845cb28763c1542556ad61d2aa9735541dbf45.tar.gz gitea-15845cb28763c1542556ad61d2aa9735541dbf45.zip |
Code clean up for new config options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/branch.go | 9 | ||||
-rw-r--r-- | routers/repo/delete.go | 9 | ||||
-rw-r--r-- | routers/repo/edit.go | 27 | ||||
-rw-r--r-- | routers/repo/upload.go | 26 | ||||
-rw-r--r-- | routers/repo/view.go | 2 |
5 files changed, 26 insertions, 47 deletions
diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 453df3745e..7b8940a943 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -64,13 +64,8 @@ func NewBranchPost(ctx *context.Context, form auth.NewBranchForm) { log.Error(4, "branch.GetCommit(): %v", err) } else { pc := &models.PushCommits{ - Len: 1, - Commits: []*models.PushCommit{&models.PushCommit{ - commit.ID.String(), - commit.Message(), - commit.Author.Email, - commit.Author.Name, - }}, + Len: 1, + Commits: []*models.PushCommit{models.CommitToPushCommit(commit)}, } oldCommitID := "0000000000000000000000000000000000000000" // New Branch so we use all 0s newCommitID := commit.ID.String() diff --git a/routers/repo/delete.go b/routers/repo/delete.go index 0aec7f1a1d..a0c615a6d7 100644 --- a/routers/repo/delete.go +++ b/routers/repo/delete.go @@ -32,13 +32,8 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) { log.Error(4, "branch.GetCommit(): %v", err) } else { pc := &models.PushCommits{ - Len: 1, - Commits: []*models.PushCommit{&models.PushCommit{ - commit.ID.String(), - commit.Message(), - commit.Author.Email, - commit.Author.Name, - }}, + Len: 1, + Commits: []*models.PushCommit{models.CommitToPushCommit(commit)}, } oldCommitID := ctx.Repo.CommitID newCommitID := commit.ID.String() diff --git a/routers/repo/edit.go b/routers/repo/edit.go index d0cacd360e..7148510980 100644 --- a/routers/repo/edit.go +++ b/routers/repo/edit.go @@ -89,7 +89,7 @@ func editFile(ctx *context.Context, isNewFile bool) { d, _ := ioutil.ReadAll(dataRc) buf = append(buf, d...) - if err, content := template.ToUtf8WithErr(buf); err != nil { + if err, content := template.ToUTF8WithErr(buf); err != nil { if err != nil { log.Error(4, "Convert content encoding: %s", err) } @@ -116,10 +116,10 @@ func editFile(ctx *context.Context, isNewFile bool) { ctx.Data["CommitDirectlyToThisBranch"] = ctx.Tr("repo.commit_directly_to_this_branch", "<strong class=\"branch-name\">"+branchName+"</strong>") ctx.Data["CreateNewBranch"] = ctx.Tr("repo.create_new_branch", "<strong>"+ctx.Tr("repo.new_branch")+"</strong>") ctx.Data["LastCommit"] = ctx.Repo.Commit.ID - ctx.Data["MdFileExtensions"] = strings.Join(setting.Markdown.MdFileExtensions, ",") - ctx.Data["LineWrapExtensions"] = strings.Join(setting.Editor.LineWrapExtensions, ",") - ctx.Data["PreviewTabApis"] = strings.Join(setting.Editor.PreviewTabApis, ",") - ctx.Data["PreviewDiffUrl"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName + ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",") + ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",") + ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",") + ctx.Data["PreviewDiffURL"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName ctx.HTML(200, EDIT) } @@ -176,10 +176,10 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo ctx.Data["CommitDirectlyToThisBranch"] = ctx.Tr("repo.commit_directly_to_this_branch", "<strong class=\"branch-name\">"+oldBranchName+"</strong>") ctx.Data["CreateNewBranch"] = ctx.Tr("repo.create_new_branch", "<strong>"+ctx.Tr("repo.new_branch")+"</strong>") ctx.Data["LastCommit"] = ctx.Repo.Commit.ID - ctx.Data["MdFileExtensions"] = strings.Join(setting.Markdown.MdFileExtensions, ",") - ctx.Data["LineWrapExtensions"] = strings.Join(setting.Editor.LineWrapExtensions, ",") - ctx.Data["PreviewTabApis"] = strings.Join(setting.Editor.PreviewTabApis, ",") - ctx.Data["PreviewDiffUrl"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName + ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",") + ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",") + ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",") + ctx.Data["PreviewDiffURL"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName if ctx.HasError() { ctx.HTML(200, EDIT) @@ -293,13 +293,8 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo log.Error(4, "branch.GetCommit(): %v", err) } else { pc := &models.PushCommits{ - Len: 1, - Commits: []*models.PushCommit{&models.PushCommit{ - commit.ID.String(), - commit.Message(), - commit.Author.Email, - commit.Author.Name, - }}, + Len: 1, + Commits: []*models.PushCommit{models.CommitToPushCommit(commit)}, } oldCommitID := ctx.Repo.CommitID newCommitID := commit.ID.String() diff --git a/routers/repo/upload.go b/routers/repo/upload.go index fedf4064d3..efecc208fd 100644 --- a/routers/repo/upload.go +++ b/routers/repo/upload.go @@ -24,10 +24,10 @@ const ( func renderUploadSettings(ctx *context.Context) { ctx.Data["RequireDropzone"] = true - ctx.Data["IsUploadEnabled"] = setting.UploadEnabled - ctx.Data["UploadAllowedTypes"] = setting.UploadAllowedTypes - ctx.Data["UploadMaxSize"] = setting.UploadMaxSize - ctx.Data["UploadMaxFiles"] = setting.UploadMaxFiles + ctx.Data["IsUploadEnabled"] = setting.Repository.Upload.Enabled + ctx.Data["UploadAllowedTypes"] = strings.Join(setting.Repository.Upload.AllowedTypes, ",") + ctx.Data["UploadMaxSize"] = setting.Repository.Upload.FileMaxSize + ctx.Data["UploadMaxFiles"] = setting.Repository.Upload.MaxFiles } func UploadFile(ctx *context.Context) { @@ -154,13 +154,8 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { log.Error(4, "branch.GetCommit(): %v", err) } else { pc := &models.PushCommits{ - Len: 1, - Commits: []*models.PushCommit{&models.PushCommit{ - commit.ID.String(), - commit.Message(), - commit.Author.Email, - commit.Author.Name, - }}, + Len: 1, + Commits: []*models.PushCommit{models.CommitToPushCommit(commit)}, } oldCommitID := ctx.Repo.CommitID newCommitID := commit.ID.String() @@ -184,7 +179,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { } func UploadFileToServer(ctx *context.Context) { - if !setting.UploadEnabled { + if !setting.Repository.Upload.Enabled { ctx.Error(404, "upload is not enabled") return } @@ -203,10 +198,9 @@ func UploadFileToServer(ctx *context.Context) { } fileType := http.DetectContentType(buf) - if len(setting.UploadAllowedTypes) > 0 { - allowedTypes := strings.Split(setting.UploadAllowedTypes, ",") + if len(setting.Repository.Upload.AllowedTypes) > 0 { allowed := false - for _, t := range allowedTypes { + for _, t := range setting.Repository.Upload.AllowedTypes { t := strings.Trim(t, " ") if t == "*/*" || t == fileType { allowed = true @@ -233,7 +227,7 @@ func UploadFileToServer(ctx *context.Context) { } func RemoveUploadFileFromServer(ctx *context.Context, form auth.RemoveUploadFileForm) { - if !setting.UploadEnabled { + if !setting.Repository.Upload.Enabled { ctx.Error(404, "upload is not enabled") return } diff --git a/routers/repo/view.go b/routers/repo/view.go index 08ee16df1a..bbb5e96a4a 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -257,7 +257,7 @@ func Home(ctx *context.Context) { ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit) if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch { ctx.Data["NewFileLink"] = newFileLink + "/" + treename - if setting.UploadEnabled { + if !setting.Repository.Upload.Enabled { ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treename } } |