浏览代码

Code clean up for new config options

tags/v0.9.99
Unknwon 7 年前
父节点
当前提交
15845cb287

+ 1
- 1
cmd/web.go 查看文件

m.Post("/branches", bindIgnErr(auth.NewBranchForm{}), repo.NewBranchPost) m.Post("/branches", bindIgnErr(auth.NewBranchForm{}), repo.NewBranchPost)
m.Post("/upload-file", repo.UploadFileToServer) m.Post("/upload-file", repo.UploadFileToServer)
m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer) m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
}, context.RepoRef(), context.RepoAssignment(), reqRepoWriter)
}, reqRepoWriter, context.RepoRef())
}, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare) }, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare)


m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {

+ 5
- 5
conf/app.ini 查看文件

; Patch test queue length, make it as large as possible ; Patch test queue length, make it as large as possible
PULL_REQUEST_QUEUE_LENGTH = 10000 PULL_REQUEST_QUEUE_LENGTH = 10000


[editor]
[repository.editor]
; List of file extensions that should have line wraps in the CodeMirror editor ; List of file extensions that should have line wraps in the CodeMirror editor
; Separate extensions with a comma. To line wrap files w/o extension, just put a comma ; Separate extensions with a comma. To line wrap files w/o extension, just put a comma
LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd, LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,
; Valid file modes that have a preview API associated with them, such as api/v1/markdown ; Valid file modes that have a preview API associated with them, such as api/v1/markdown
; Separate values by commas. Preview tab in edit mode won't show if the file extension doesn't match ; Separate values by commas. Preview tab in edit mode won't show if the file extension doesn't match
PREVIEW_TAB_APIS = markdown
PREVIEWABLE_FILE_MODES = markdown


[upload]
[repository.upload]
; Whether repository file uploads are enabled. Defaults to `true` ; Whether repository file uploads are enabled. Defaults to `true`
ENABLE_UPLOADS = true
ENABLED = true
; Path for uploads. Defaults to `data/tmp/uploads` (tmp gets deleted on gogs restart) ; Path for uploads. Defaults to `data/tmp/uploads` (tmp gets deleted on gogs restart)
TEMP_PATH = data/tmp/uploads TEMP_PATH = data/tmp/uploads
; One or more allowed types, e.g. image/jpeg|image/png. Nothing means any file type ; One or more allowed types, e.g. image/jpeg|image/png. Nothing means any file type
CUSTOM_URL_SCHEMES = CUSTOM_URL_SCHEMES =
; List of file extensions that should be rendered/edited as Markdown ; List of file extensions that should be rendered/edited as Markdown
; Separate extensions with a comma. To render files w/o extension as markdown, just put a comma ; Separate extensions with a comma. To render files w/o extension as markdown, just put a comma
MD_FILE_EXTENSIONS = .md,.markdown,.mdown,.mkd
FILE_EXTENSIONS = .md,.markdown,.mdown,.mkd


[server] [server]
PROTOCOL = http PROTOCOL = http

+ 2
- 2
models/error.go 查看文件

} }


func (err ErrRepoFileAlreadyExist) Error() string { func (err ErrRepoFileAlreadyExist) Error() string {
return fmt.Sprintf("repository file already exists [file name: %s]", err.FileName)
return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
} }


// __________ .__ // __________ .__
} }


func (err ErrUploadNotExist) Error() string { func (err ErrUploadNotExist) Error() string {
return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s, user_id: %d, repo_id: %d]", err.ID, err.UUID, err.UserID, err.RepoID)
} }

+ 2
- 2
models/issue.go 查看文件

if IsErrAttachmentNotExist(err) { if IsErrAttachmentNotExist(err) {
continue continue
} }
return fmt.Errorf("getAttachmentByUUID[%s]: %v", uuid, err)
return fmt.Errorf("getAttachmentByUUID [%s]: %v", uuid, err)
} }
attachment.IssueID = issue.ID attachment.IssueID = issue.ID
// No assign value could be 0, so ignore AllCols(). // No assign value could be 0, so ignore AllCols().
if _, err = e.Id(attachment.ID).Update(attachment); err != nil { if _, err = e.Id(attachment.ID).Update(attachment); err != nil {
return fmt.Errorf("update attachment[%d]: %v", attachment.ID, err)
return fmt.Errorf("update attachment [%d]: %v", attachment.ID, err)
} }
} }



+ 1
- 1
models/repo.go 查看文件



// UploadLocalPath returns where uploads is stored in local file system based on given UUID. // UploadLocalPath returns where uploads is stored in local file system based on given UUID.
func UploadLocalPath(uuid string) string { func UploadLocalPath(uuid string) string {
return path.Join(setting.UploadTempPath, uuid[0:1], uuid[1:2], uuid)
return path.Join(setting.Repository.Upload.TempPath, uuid[0:1], uuid[1:2], uuid)
} }


// LocalPath returns where uploads are temporarily stored in local file system. // LocalPath returns where uploads are temporarily stored in local file system.

+ 1
- 1
models/ssh_key_test.go 查看文件

"rsa-2048": {"rsa", 2048, "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMZXh+1OBUwSH9D45wTaxErQIN9IoC9xl7MKJkqvTvv6O5RR9YW/IK9FbfjXgXsppYGhsCZo1hFOOsXHMnfOORqu/xMDx4yPuyvKpw4LePEcg4TDipaDFuxbWOqc/BUZRZcXu41QAWfDLrInwsltWZHSeG7hjhpacl4FrVv9V1pS6Oc5Q1NxxEzTzuNLS/8diZrTm/YAQQ/+B+mzWI3zEtF4miZjjAljWd1LTBPvU23d29DcBmmFahcZ441XZsTeAwGxG/Q6j8NgNXj9WxMeWwxXV2jeAX/EBSpZrCVlCQ1yJswT6xCp8TuBnTiGWYMBNTbOZvPC4e0WI2/yZW/s5F nocomment"}, "rsa-2048": {"rsa", 2048, "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMZXh+1OBUwSH9D45wTaxErQIN9IoC9xl7MKJkqvTvv6O5RR9YW/IK9FbfjXgXsppYGhsCZo1hFOOsXHMnfOORqu/xMDx4yPuyvKpw4LePEcg4TDipaDFuxbWOqc/BUZRZcXu41QAWfDLrInwsltWZHSeG7hjhpacl4FrVv9V1pS6Oc5Q1NxxEzTzuNLS/8diZrTm/YAQQ/+B+mzWI3zEtF4miZjjAljWd1LTBPvU23d29DcBmmFahcZ441XZsTeAwGxG/Q6j8NgNXj9WxMeWwxXV2jeAX/EBSpZrCVlCQ1yJswT6xCp8TuBnTiGWYMBNTbOZvPC4e0WI2/yZW/s5F nocomment"},
"ecdsa-256": {"ecdsa", 256, "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFQacN3PrOll7PXmN5B/ZNVahiUIqI05nbBlZk1KXsO3d06ktAWqbNflv2vEmA38bTFTfJ2sbn2B5ksT52cDDbA= nocomment"}, "ecdsa-256": {"ecdsa", 256, "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFQacN3PrOll7PXmN5B/ZNVahiUIqI05nbBlZk1KXsO3d06ktAWqbNflv2vEmA38bTFTfJ2sbn2B5ksT52cDDbA= nocomment"},
"ecdsa-384": {"ecdsa", 384, "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBINmioV+XRX1Fm9Qk2ehHXJ2tfVxW30ypUWZw670Zyq5GQfBAH6xjygRsJ5wWsHXBsGYgFUXIHvMKVAG1tpw7s6ax9oA+dJOJ7tj+vhn8joFqT+sg3LYHgZkHrfqryRasQ== nocomment"}, "ecdsa-384": {"ecdsa", 384, "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBINmioV+XRX1Fm9Qk2ehHXJ2tfVxW30ypUWZw670Zyq5GQfBAH6xjygRsJ5wWsHXBsGYgFUXIHvMKVAG1tpw7s6ax9oA+dJOJ7tj+vhn8joFqT+sg3LYHgZkHrfqryRasQ== nocomment"},
"ecdsa-521": {"ecdsa", 521, "ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACGt3UG3EzRwNOI17QR84l6PgiAcvCE7v6aXPj/SC6UWKg4EL8vW9ZBcdYL9wzs4FZXh4MOV8jAzu3KRWNTwb4k2wFNUpGOt7l28MztFFEtH5BDDrtAJSPENPy8pvPLMfnPg5NhvWycqIBzNcHipem5wSJFN5PdpNOC2xMrPWKNqj+ZjQ== nocomment"},
// "ecdsa-521": {"ecdsa", 521, "ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACGt3UG3EzRwNOI17QR84l6PgiAcvCE7v6aXPj/SC6UWKg4EL8vW9ZBcdYL9wzs4FZXh4MOV8jAzu3KRWNTwb4k2wFNUpGOt7l28MztFFEtH5BDDrtAJSPENPy8pvPLMfnPg5NhvWycqIBzNcHipem5wSJFN5PdpNOC2xMrPWKNqj+ZjQ== nocomment"},
} }


Convey("Parse public keys in both native and ssh-keygen", t, func() { Convey("Parse public keys in both native and ssh-keygen", t, func() {

+ 14
- 10
models/update.go 查看文件

return err return err
} }


// CommitToPushCommit transforms a git.Commit to PushCommit type.
func CommitToPushCommit(commit *git.Commit) *PushCommit {
return &PushCommit{
Sha1: commit.ID.String(),
Message: commit.Message(),
AuthorEmail: commit.Author.Email,
AuthorName: commit.Author.Name,
CommitterEmail: commit.Committer.Email,
CommitterName: commit.Committer.Name,
Timestamp: commit.Author.When,
}
}

func ListToPushCommits(l *list.List) *PushCommits { func ListToPushCommits(l *list.List) *PushCommits {
commits := make([]*PushCommit, 0) commits := make([]*PushCommit, 0)
var actEmail string var actEmail string
if actEmail == "" { if actEmail == "" {
actEmail = commit.Committer.Email actEmail = commit.Committer.Email
} }
commits = append(commits,
&PushCommit{
Sha1: commit.ID.String(),
Message: commit.Message(),
AuthorEmail: commit.Author.Email,
AuthorName: commit.Author.Name,
CommitterEmail: commit.Committer.Email,
CommitterName: commit.Committer.Name,
Timestamp: commit.Author.When,
})
commits = append(commits, CommitToPushCommit(commit))
} }
return &PushCommits{l.Len(), commits, "", nil} return &PushCommits{l.Len(), commits, "", nil}
} }

+ 2
- 2
modules/bindata/bindata.go
文件差异内容过多而无法显示
查看文件


+ 1
- 1
modules/markdown/markdown.go 查看文件

// based on its extension. // based on its extension.
func IsMarkdownFile(name string) bool { func IsMarkdownFile(name string) bool {
extension := strings.ToLower(filepath.Ext(name)) extension := strings.ToLower(filepath.Ext(name))
for _, ext := range setting.Markdown.MdFileExtensions {
for _, ext := range setting.Markdown.FileExtensions {
if strings.ToLower(ext) == extension { if strings.ToLower(ext) == extension {
return true return true
} }

+ 23
- 29
modules/setting/setting.go 查看文件

ForcePrivate bool ForcePrivate bool
MaxCreationLimit int MaxCreationLimit int
PullRequestQueueLength int PullRequestQueueLength int

// Repository editor settings
Editor struct {
LineWrapExtensions []string
PreviewableFileModes []string
} `ini:"-"`

// Repository upload settings
Upload struct {
Enabled bool
TempPath string
AllowedTypes []string `delim:"|"`
FileMaxSize int64
MaxFiles int
} `ini:"-"`
} }
RepoRootPath string RepoRootPath string
ScriptType string ScriptType string


// Repo editor settings
Editor struct {
LineWrapExtensions []string
PreviewTabApis []string
}

// UI settings // UI settings
UI struct { UI struct {
ExplorePagingNum int ExplorePagingNum int
Markdown struct { Markdown struct {
EnableHardLineBreak bool EnableHardLineBreak bool
CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"` CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
MdFileExtensions []string
FileExtensions []string
} }


// Picture settings // Picture settings
AttachmentMaxFiles int AttachmentMaxFiles int
AttachmentEnabled bool AttachmentEnabled bool


// Repo Upload settings
UploadTempPath string
UploadAllowedTypes string
UploadMaxSize int64
UploadMaxFiles int
UploadEnabled bool

// Time settings // Time settings
TimeFormat string TimeFormat string


ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash") ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
if err = Cfg.Section("repository").MapTo(&Repository); err != nil { if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
log.Fatal(4, "Fail to map Repository settings: %v", err) log.Fatal(4, "Fail to map Repository settings: %v", err)
} else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
log.Fatal(4, "Fail to map Repository.Editor settings: %v", err)
} else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
log.Fatal(4, "Fail to map Repository.Upload settings: %v", err)
} }


sec = Cfg.Section("upload")
UploadTempPath = sec.Key("UPLOAD_TEMP_PATH").MustString(path.Join(AppDataPath, "tmp/uploads"))
if !filepath.IsAbs(UploadTempPath) {
UploadTempPath = path.Join(workDir, UploadTempPath)
if !filepath.IsAbs(Repository.Upload.TempPath) {
Repository.Upload.TempPath = path.Join(workDir, Repository.Upload.TempPath)
} }
UploadAllowedTypes = strings.Replace(sec.Key("UPLOAD_ALLOWED_TYPES").MustString(""), "|", ",", -1)
UploadMaxSize = sec.Key("UPLOAD_FILE_MAX_SIZE").MustInt64(32)
UploadMaxFiles = sec.Key("UPLOAD_MAX_FILES").MustInt(10)
UploadEnabled = sec.Key("ENABLE_UPLOADS").MustBool(true)


sec = Cfg.Section("picture") sec = Cfg.Section("picture")
AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(AppDataPath, "avatars")) AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(AppDataPath, "avatars"))
} else if err = Cfg.Section("git").MapTo(&Git); err != nil { } else if err = Cfg.Section("git").MapTo(&Git); err != nil {
log.Fatal(4, "Fail to map Git settings: %v", err) log.Fatal(4, "Fail to map Git settings: %v", err)
} else if err = Cfg.Section("mirror").MapTo(&Mirror); err != nil { } else if err = Cfg.Section("mirror").MapTo(&Mirror); err != nil {
log.Fatal(4, "Fail to map API settings: %v", err)
log.Fatal(4, "Fail to map Mirror settings: %v", err)
} else if err = Cfg.Section("api").MapTo(&API); err != nil { } else if err = Cfg.Section("api").MapTo(&API); err != nil {
log.Fatal(4, "Fail to map API settings: %v", err) log.Fatal(4, "Fail to map API settings: %v", err)
} else if err = Cfg.Section("editor").MapTo(&Editor); err != nil {
log.Fatal(4, "Fail to map Editor settings: %v", err)
} }


if Mirror.DefaultInterval <= 0 { if Mirror.DefaultInterval <= 0 {
ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool() ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool()


HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt")) HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))

Markdown.MdFileExtensions = Cfg.Section("markdown").Key("MD_FILE_EXTENSIONS").Strings(",")
Editor.LineWrapExtensions = Cfg.Section("editor").Key("LINE_WRAP_EXTENSIONS").Strings(",")
Editor.PreviewTabApis = Cfg.Section("editor").Key("PREVIEW_TAB_APIS").Strings(",")
} }


var Service struct { var Service struct {

+ 6
- 6
public/js/gogs.js 查看文件

} }


var previewTab; var previewTab;
var previewTabApis;
var previewFileModes;


function initEditPreviewTab($form) { function initEditPreviewTab($form) {
var $tab_menu = $form.find('.tabular.menu'); var $tab_menu = $form.find('.tabular.menu');
previewTab = $tab_menu.find('.item[data-tab="' + $tab_menu.data('preview') + '"]'); previewTab = $tab_menu.find('.item[data-tab="' + $tab_menu.data('preview') + '"]');


if (previewTab.length) { if (previewTab.length) {
previewTabApis = previewTab.data('preview-apis').split(',');
previewFileModes = previewTab.data('preview-file-modes').split(',');
previewTab.click(function () { previewTab.click(function () {
var $this = $(this); var $this = $(this);
$.post($this.data('url'), { $.post($this.data('url'), {
var editFilename; var editFilename;
var smdEditor; var smdEditor;
var cmEditor; var cmEditor;
var mdFileExtensions;
var markdownFileExts;
var lineWrapExtensions; var lineWrapExtensions;


// For IE // For IE
if (!editArea.length) if (!editArea.length)
return; return;


mdFileExtensions = editArea.data("md-file-extensions").split(",");
markdownFileExts = editArea.data("markdown-file-exts").split(",");
lineWrapExtensions = editArea.data("line-wrap-extensions").split(","); lineWrapExtensions = editArea.data("line-wrap-extensions").split(",");


editFilename.on("keyup", function (e) { editFilename.on("keyup", function (e) {
apiCall = extension apiCall = extension
} }


if (previewLink.length && apiCall && previewTabApis && previewTabApis.length && previewTabApis.indexOf(apiCall) >= 0) {
if (previewLink.length && apiCall && previewFileModes && previewFileModes.length && previewFileModes.indexOf(apiCall) >= 0) {
dataUrl = previewLink.data('url'); dataUrl = previewLink.data('url');
previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, '$1/' + mode)); previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, '$1/' + mode));
previewLink.show(); previewLink.show();
} }


// If this file is a Markdown extensions, we will load that editor and return // If this file is a Markdown extensions, we will load that editor and return
if (mdFileExtensions.indexOf(extWithDot) >= 0) {
if (markdownFileExts.indexOf(extWithDot) >= 0) {
if (setSimpleMDE()) { if (setSimpleMDE()) {
return; return;
} }

+ 2
- 7
routers/repo/branch.go 查看文件

log.Error(4, "branch.GetCommit(): %v", err) log.Error(4, "branch.GetCommit(): %v", err)
} else { } else {
pc := &models.PushCommits{ 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 oldCommitID := "0000000000000000000000000000000000000000" // New Branch so we use all 0s
newCommitID := commit.ID.String() newCommitID := commit.ID.String()

+ 2
- 7
routers/repo/delete.go 查看文件

log.Error(4, "branch.GetCommit(): %v", err) log.Error(4, "branch.GetCommit(): %v", err)
} else { } else {
pc := &models.PushCommits{ 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 oldCommitID := ctx.Repo.CommitID
newCommitID := commit.ID.String() newCommitID := commit.ID.String()

+ 11
- 16
routers/repo/edit.go 查看文件

d, _ := ioutil.ReadAll(dataRc) d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...) buf = append(buf, d...)


if err, content := template.ToUtf8WithErr(buf); err != nil {
if err, content := template.ToUTF8WithErr(buf); err != nil {
if err != nil { if err != nil {
log.Error(4, "Convert content encoding: %s", err) log.Error(4, "Convert content encoding: %s", err)
} }
ctx.Data["CommitDirectlyToThisBranch"] = ctx.Tr("repo.commit_directly_to_this_branch", "<strong class=\"branch-name\">"+branchName+"</strong>") 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["CreateNewBranch"] = ctx.Tr("repo.create_new_branch", "<strong>"+ctx.Tr("repo.new_branch")+"</strong>")
ctx.Data["LastCommit"] = ctx.Repo.Commit.ID 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) ctx.HTML(200, EDIT)
} }
ctx.Data["CommitDirectlyToThisBranch"] = ctx.Tr("repo.commit_directly_to_this_branch", "<strong class=\"branch-name\">"+oldBranchName+"</strong>") 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["CreateNewBranch"] = ctx.Tr("repo.create_new_branch", "<strong>"+ctx.Tr("repo.new_branch")+"</strong>")
ctx.Data["LastCommit"] = ctx.Repo.Commit.ID 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() { if ctx.HasError() {
ctx.HTML(200, EDIT) ctx.HTML(200, EDIT)
log.Error(4, "branch.GetCommit(): %v", err) log.Error(4, "branch.GetCommit(): %v", err)
} else { } else {
pc := &models.PushCommits{ 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 oldCommitID := ctx.Repo.CommitID
newCommitID := commit.ID.String() newCommitID := commit.ID.String()

+ 10
- 16
routers/repo/upload.go 查看文件



func renderUploadSettings(ctx *context.Context) { func renderUploadSettings(ctx *context.Context) {
ctx.Data["RequireDropzone"] = true 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) { func UploadFile(ctx *context.Context) {
log.Error(4, "branch.GetCommit(): %v", err) log.Error(4, "branch.GetCommit(): %v", err)
} else { } else {
pc := &models.PushCommits{ 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 oldCommitID := ctx.Repo.CommitID
newCommitID := commit.ID.String() newCommitID := commit.ID.String()
} }


func UploadFileToServer(ctx *context.Context) { func UploadFileToServer(ctx *context.Context) {
if !setting.UploadEnabled {
if !setting.Repository.Upload.Enabled {
ctx.Error(404, "upload is not enabled") ctx.Error(404, "upload is not enabled")
return return
} }
} }
fileType := http.DetectContentType(buf) fileType := http.DetectContentType(buf)


if len(setting.UploadAllowedTypes) > 0 {
allowedTypes := strings.Split(setting.UploadAllowedTypes, ",")
if len(setting.Repository.Upload.AllowedTypes) > 0 {
allowed := false allowed := false
for _, t := range allowedTypes {
for _, t := range setting.Repository.Upload.AllowedTypes {
t := strings.Trim(t, " ") t := strings.Trim(t, " ")
if t == "*/*" || t == fileType { if t == "*/*" || t == fileType {
allowed = true allowed = true
} }


func RemoveUploadFileFromServer(ctx *context.Context, form auth.RemoveUploadFileForm) { func RemoveUploadFileFromServer(ctx *context.Context, form auth.RemoveUploadFileForm) {
if !setting.UploadEnabled {
if !setting.Repository.Upload.Enabled {
ctx.Error(404, "upload is not enabled") ctx.Error(404, "upload is not enabled")
return return
} }

+ 1
- 1
routers/repo/view.go 查看文件

ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit) ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit)
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch { if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
ctx.Data["NewFileLink"] = newFileLink + "/" + treename ctx.Data["NewFileLink"] = newFileLink + "/" + treename
if setting.UploadEnabled {
if !setting.Repository.Upload.Enabled {
ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treename ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treename
} }
} }

+ 3
- 3
templates/repo/edit.tmpl 查看文件

<div class="field"> <div class="field">
<div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff"> <div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff">
<a class="active item" data-tab="write"><i class="octicon octicon-code"></i> {{.i18n.Tr "repo.edit_file"}}</a> <a class="active item" data-tab="write"><i class="octicon octicon-code"></i> {{.i18n.Tr "repo.edit_file"}}</a>
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}" data-preview-apis="{{.PreviewTabApis}}"><i class="octicon octicon-eye"></i> {{.i18n.Tr "repo.release.preview"}}</a>
<a class="item" data-tab="diff" data-url="{{.PreviewDiffUrl}}" data-context="{{.BranchLink}}"><i class="octicon octicon-diff"></i> {{.i18n.Tr "repo.preview_changes"}}</a>
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}" data-preview-file-modes="{{.PreviewableFileModes}}"><i class="octicon octicon-eye"></i> {{.i18n.Tr "repo.release.preview"}}</a>
<a class="item" data-tab="diff" data-url="{{.PreviewDiffURL}}" data-context="{{.BranchLink}}"><i class="octicon octicon-diff"></i> {{.i18n.Tr "repo.preview_changes"}}</a>
</div> </div>
<div class="ui bottom attached active tab segment" data-tab="write"> <div class="ui bottom attached active tab segment" data-tab="write">
<textarea id="edit_area" name="content" data-id="repo-{{.Repository.Name}}-{{.TreeName}}" <textarea id="edit_area" name="content" data-id="repo-{{.Repository.Name}}-{{.TreeName}}"
data-url="{{AppSubUrl}}/api/v1/markdown" data-url="{{AppSubUrl}}/api/v1/markdown"
data-context="{{.RepoLink}}" data-context="{{.RepoLink}}"
data-md-file-extensions="{{.MdFileExtensions}}"
data-markdown-file-exts="{{.MarkdownFileExts}}"
data-line-wrap-extensions="{{.LineWrapExtensions}}"> data-line-wrap-extensions="{{.LineWrapExtensions}}">
{{.FileContent}}</textarea required> {{.FileContent}}</textarea required>
</div> </div>

正在加载...
取消
保存