forked from forgejo/forgejo
Add an updated_at field to the API call for comment's attachment creation
The update date is applied to the comment, and is set as the asset creation date.
This commit is contained in:
parent
cf787ad7fd
commit
1e4ff424d3
3 changed files with 53 additions and 9 deletions
|
@ -5,6 +5,7 @@ package repo
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
|
@ -144,6 +145,11 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
|
|||
// description: name of the attachment
|
||||
// type: string
|
||||
// required: false
|
||||
// - name: updated_at
|
||||
// in: query
|
||||
// description: time of the attachment's creation. This is a timestamp in RFC 3339 format
|
||||
// type: string
|
||||
// format: date-time
|
||||
// - name: attachment
|
||||
// in: formData
|
||||
// description: attachment to upload
|
||||
|
@ -167,6 +173,25 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
updatedAt := ctx.Req.FormValue("updated_at")
|
||||
if len(updatedAt) != 0 {
|
||||
updated, err := time.Parse(time.RFC3339, updatedAt)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "time.Parse", err)
|
||||
return
|
||||
}
|
||||
err = comment.LoadIssue(ctx)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
||||
return
|
||||
}
|
||||
err = issue_service.SetIssueUpdateDate(ctx, comment.Issue, &updated, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusForbidden, "SetIssueUpdateDate", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Get uploaded file from request
|
||||
file, header, err := ctx.Req.FormFile("attachment")
|
||||
if err != nil {
|
||||
|
@ -181,11 +206,13 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
attachment, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{
|
||||
Name: filename,
|
||||
UploaderID: ctx.Doer.ID,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
IssueID: comment.IssueID,
|
||||
CommentID: comment.ID,
|
||||
Name: filename,
|
||||
UploaderID: ctx.Doer.ID,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
IssueID: comment.IssueID,
|
||||
CommentID: comment.ID,
|
||||
NoAutoTime: comment.Issue.NoAutoTime,
|
||||
CreatedUnix: comment.Issue.UpdatedUnix,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UploadAttachment", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue