aboutsummaryrefslogtreecommitdiffstats
path: root/models/attachment.go
diff options
context:
space:
mode:
authorgdeverlant <e.bekrek@yandex.com>2019-01-06 23:37:30 +0100
committertechknowlogick <hello@techknowlogick.com>2019-01-06 17:37:30 -0500
commitd3dc07f282936849897f861346777b47c8c388d3 (patch)
tree2da810fc1d6671bf8659f9bf868e184698f0fc7c /models/attachment.go
parentdd006db5a719b33aef7887faab48718e4b0f2786 (diff)
downloadgitea-d3dc07f282936849897f861346777b47c8c388d3.tar.gz
gitea-d3dc07f282936849897f861346777b47c8c388d3.zip
Added URL mapping for Release attachments like on github.com (#1707)
Diffstat (limited to 'models/attachment.go')
-rw-r--r--models/attachment.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/models/attachment.go b/models/attachment.go
index 4a5101b385..808bc243dc 100644
--- a/models/attachment.go
+++ b/models/attachment.go
@@ -151,6 +151,11 @@ func GetAttachmentByUUID(uuid string) (*Attachment, error) {
return getAttachmentByUUID(x, uuid)
}
+// GetAttachmentByReleaseIDFileName returns attachment by given releaseId and fileName.
+func GetAttachmentByReleaseIDFileName(releaseID int64, fileName string) (*Attachment, error) {
+ return getAttachmentByReleaseIDFileName(x, releaseID, fileName)
+}
+
func getAttachmentsByIssueID(e Engine, issueID int64) ([]*Attachment, error) {
attachments := make([]*Attachment, 0, 10)
return attachments, e.Where("issue_id = ? AND comment_id = 0", issueID).Find(&attachments)
@@ -171,6 +176,18 @@ func getAttachmentsByCommentID(e Engine, commentID int64) ([]*Attachment, error)
return attachments, x.Where("comment_id=?", commentID).Find(&attachments)
}
+// getAttachmentByReleaseIDFileName return a file based on the the following infos:
+func getAttachmentByReleaseIDFileName(e Engine, releaseID int64, fileName string) (*Attachment, error) {
+ attach := &Attachment{ReleaseID: releaseID, Name: fileName}
+ has, err := e.Get(attach)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, err
+ }
+ return attach, nil
+}
+
// DeleteAttachment deletes the given attachment and optionally the associated file.
func DeleteAttachment(a *Attachment, remove bool) error {
_, err := DeleteAttachments([]*Attachment{a}, remove)