From 24734a33e72dbdc1da4f7341cb2cf62521ce53f8 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 13 Mar 2017 05:26:17 -0400 Subject: release: improve attachment handle --- cmd/web.go | 10 ++++----- templates/repo/release/new.tmpl | 46 +++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index 7f97157e..2d83de16 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -15,6 +15,7 @@ import ( "path" "strings" + "github.com/Unknwon/com" "github.com/go-macaron/binding" "github.com/go-macaron/cache" "github.com/go-macaron/captcha" @@ -323,11 +324,10 @@ func runWeb(ctx *cli.Context) error { m.Get("/attachments/:uuid", func(ctx *context.Context) { attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid")) if err != nil { - if models.IsErrAttachmentNotExist(err) { - ctx.Error(404) - } else { - ctx.Handle(500, "GetAttachmentByUUID", err) - } + ctx.NotFoundOrServerError("GetAttachmentByUUID", models.IsErrAttachmentNotExist, err) + return + } else if !com.IsFile(attach.LocalPath()) { + ctx.NotFound() return } diff --git a/templates/repo/release/new.tmpl b/templates/repo/release/new.tmpl index 09b7a9f8..5530bd79 100644 --- a/templates/repo/release/new.tmpl +++ b/templates/repo/release/new.tmpl @@ -48,22 +48,23 @@ - {{if .attachments}} - - - - {{range .attachments}} - - - - {{end}} - -
- {{.Name}} - - -
- {{end}} +
+ {{if .attachments}} + + + {{range .attachments}} + + + + {{end}} + +
+ {{.Name}} + + +
+ {{end}} +
{{if .IsAttachmentEnabled}}
@@ -122,9 +123,18 @@ {{end}} -- cgit v1.2.3