diff options
Diffstat (limited to 'cmd/web.go')
-rw-r--r-- | cmd/web.go | 60 |
1 files changed, 47 insertions, 13 deletions
@@ -228,14 +228,16 @@ func runWeb(ctx *cli.Context) { }) // Repositories. - m.Combo("/user/repos", middleware.ApiReqToken()).Get(v1.ListMyRepos).Post(bind(api.CreateRepoOption{}), v1.CreateRepo) + m.Combo("/user/repos", middleware.ApiReqToken()).Get(v1.ListMyRepos). + Post(bind(api.CreateRepoOption{}), v1.CreateRepo) m.Post("/org/:org/repos", middleware.ApiReqToken(), bind(api.CreateRepoOption{}), v1.CreateOrgRepo) m.Group("/repos", func() { m.Get("/search", v1.SearchRepos) m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo) m.Group("/:username/:reponame", func() { - m.Combo("/hooks").Get(v1.ListRepoHooks).Post(bind(api.CreateHookOption{}), v1.CreateRepoHook) + m.Combo("/hooks").Get(v1.ListRepoHooks). + Post(bind(api.CreateHookOption{}), v1.CreateRepoHook) m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), v1.EditRepoHook) m.Get("/raw/*", middleware.RepoRef(), v1.GetRepoRawFile) }, middleware.ApiRepoAssignment(), middleware.ApiReqToken()) @@ -325,7 +327,36 @@ func runWeb(ctx *cli.Context) { }) }, adminReq) - m.Get("/:username", ignSignIn, user.Profile) + m.Group("", func() { + m.Get("/:username", user.Profile) + m.Get("/attachments/:uuid", func(ctx *middleware.Context) { + attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid")) + if err != nil { + if models.IsErrAttachmentNotExist(err) { + ctx.Error(404) + } else { + ctx.Handle(500, "GetAttachmentByUUID", err) + } + return + } + + fr, err := os.Open(attach.LocalPath()) + if err != nil { + ctx.Handle(500, "Open", err) + return + } + defer fr.Close() + + ctx.Header().Set("Cache-Control", "public,max-age=86400") + // Fix #312. Attachments with , in their name are not handled correctly by Google Chrome. + // We must put the name in " manually. + if err = repo.ServeData(ctx, "\""+attach.Name+"\"", fr); err != nil { + ctx.Handle(500, "ServeData", err) + return + } + }) + m.Post("/issues/attachments", repo.UploadIssueAttachment) + }, ignSignIn) if macaron.Env == macaron.DEV { m.Get("/template/*", dev.TemplatePreview) @@ -419,13 +450,16 @@ func runWeb(ctx *cli.Context) { m.Get("/action/:action", repo.Action) m.Group("/issues", func() { - m.Get("/new", repo.CreateIssue) - m.Post("/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost) - m.Post("/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) - m.Post("/:index/label", repo.UpdateIssueLabel) - m.Post("/:index/milestone", repo.UpdateIssueMilestone) - m.Post("/:index/assignee", repo.UpdateAssignee) - m.Get("/:index/attachment/:id", repo.IssueGetAttachment) + m.Combo("/new").Get(repo.NewIssue). + Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost) + + m.Group("/:index", func() { + m.Post("", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) + m.Post("/label", repo.UpdateIssueLabel) + m.Post("/milestone", repo.UpdateIssueMilestone) + m.Post("/assignee", repo.UpdateAssignee) + m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) + }) }) m.Group("/labels", func() { m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) @@ -441,14 +475,14 @@ func runWeb(ctx *cli.Context) { m.Post("/delete", repo.DeleteMilestone) }, reqRepoAdmin) - m.Post("/comment/:action", repo.Comment) - m.Group("/releases", func() { m.Get("/new", repo.NewRelease) m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) m.Get("/edit/:tagname", repo.EditRelease) m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) }, reqRepoAdmin, middleware.RepoRef()) + + m.Combo("/compare/*").Get(repo.CompareAndPullRequest) }, reqSignIn, middleware.RepoAssignment(true)) m.Group("/:username/:reponame", func() { @@ -469,7 +503,7 @@ func runWeb(ctx *cli.Context) { m.Get("/commit/*", repo.Diff) }, middleware.RepoRef()) - m.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff) + m.Get("/compare/:before([a-z0-9]{40})...:after([a-z0-9]{40})", repo.CompareDiff) }, ignSignIn, middleware.RepoAssignment(true)) m.Group("/:username", func() { |