summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorJustin Nuß <justin.nuss@hmmh.de>2014-07-24 13:50:03 +0200
committerJustin Nuß <justin.nuss@hmmh.de>2014-07-24 13:50:03 +0200
commit43e5de7f830a098582b519706f9c5da6eecd2c3e (patch)
tree952610e2ae5f3bfc1be7ad0214f55fc1d659b497 /routers
parentfa1db64ff014d6d06151431a3b1417ebf0104bde (diff)
downloadgitea-43e5de7f830a098582b519706f9c5da6eecd2c3e.tar.gz
gitea-43e5de7f830a098582b519706f9c5da6eecd2c3e.zip
Show attachments in issues/comments and add preview for images
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/issue.go46
1 files changed, 38 insertions, 8 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 6becb2dff7..903a32d968 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -709,6 +709,12 @@ func Comment(ctx *middleware.Context, params martini.Params) {
attachments := strings.Split(params["attachments"], ",")
for _, a := range attachments {
+ a = strings.Trim(a, " ")
+
+ if len(a) == 0 {
+ continue
+ }
+
aId, err := base.StrTo(a).Int64()
if err != nil {
@@ -1002,12 +1008,23 @@ func UpdateMilestonePost(ctx *middleware.Context, params martini.Params, form au
}
func IssuePostAttachment(ctx *middleware.Context, params martini.Params) {
- issueId, _ := base.StrTo(params["index"]).Int64()
+ index, _ := base.StrTo(params["index"]).Int64()
- if issueId == 0 {
+ if index == 0 {
ctx.JSON(400, map[string]interface{}{
"ok": false,
- "error": "invalid issue id",
+ "error": "invalid issue index",
+ })
+
+ return
+ }
+
+ issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, index)
+
+ if err != nil {
+ ctx.JSON(400, map[string]interface{}{
+ "ok": false,
+ "error": "invalid comment id",
})
return
@@ -1089,7 +1106,7 @@ func IssuePostAttachment(ctx *middleware.Context, params martini.Params) {
return
}
- a, err := models.CreateAttachment(issueId, commentId, header.Filename, out.Name())
+ a, err := models.CreateAttachment(issue.Id, commentId, header.Filename, out.Name())
if err != nil {
ctx.JSON(500, map[string]interface{}{
@@ -1121,16 +1138,29 @@ func IssueGetAttachment(ctx *middleware.Context, params martini.Params) {
return
}
+ log.Error("path=%s name=%s", attachment.Path, attachment.Name)
+
ctx.ServeFile(attachment.Path, attachment.Name)
}
func IssueDeleteAttachment(ctx *middleware.Context, params martini.Params) {
- issueId, _ := base.StrTo(params["index"]).Int64()
+ index, _ := base.StrTo(params["index"]).Int64()
- if issueId == 0 {
+ if index == 0 {
ctx.JSON(400, map[string]interface{}{
"ok": false,
- "error": "invalid issue id",
+ "error": "invalid issue index",
+ })
+
+ return
+ }
+
+ issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, index)
+
+ if err != nil {
+ ctx.JSON(400, map[string]interface{}{
+ "ok": false,
+ "error": "invalid comment id",
})
return
@@ -1189,7 +1219,7 @@ func IssueDeleteAttachment(ctx *middleware.Context, params martini.Params) {
return
}
- if attachment.IssueId != issueId {
+ if attachment.IssueId != issue.Id {
ctx.JSON(400, map[string]interface{}{
"ok": false,
"error": "attachment not associated with the given issue",