|
5 | 5 | package models |
6 | 6 |
|
7 | 7 | import ( |
8 | | - "bytes" |
9 | 8 | "fmt" |
10 | | - "io" |
11 | 9 | "path" |
12 | 10 |
|
13 | 11 | "code.gitea.io/gitea/modules/setting" |
14 | 12 | "code.gitea.io/gitea/modules/storage" |
15 | 13 | "code.gitea.io/gitea/modules/timeutil" |
16 | 14 |
|
17 | | - gouuid "github.com/google/uuid" |
18 | 15 | "xorm.io/xorm" |
19 | 16 | ) |
20 | 17 |
|
21 | 18 | // Attachment represent a attachment of issue/comment/release. |
22 | 19 | type Attachment struct { |
23 | 20 | ID int64 `xorm:"pk autoincr"` |
24 | 21 | UUID string `xorm:"uuid UNIQUE"` |
25 | | - IssueID int64 `xorm:"INDEX"` |
26 | | - ReleaseID int64 `xorm:"INDEX"` |
| 22 | + RepoID int64 `xorm:"INDEX"` // this should not be zero |
| 23 | + IssueID int64 `xorm:"INDEX"` // maybe zero when creating |
| 24 | + ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating |
27 | 25 | UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added |
28 | 26 | CommentID int64 |
29 | 27 | Name string |
@@ -81,23 +79,6 @@ func (a *Attachment) LinkedRepository() (*Repository, UnitType, error) { |
81 | 79 | return nil, -1, nil |
82 | 80 | } |
83 | 81 |
|
84 | | -// NewAttachment creates a new attachment object. |
85 | | -func NewAttachment(attach *Attachment, buf []byte, file io.Reader) (_ *Attachment, err error) { |
86 | | - attach.UUID = gouuid.New().String() |
87 | | - |
88 | | - size, err := storage.Attachments.Save(attach.RelativePath(), io.MultiReader(bytes.NewReader(buf), file), -1) |
89 | | - if err != nil { |
90 | | - return nil, fmt.Errorf("Create: %v", err) |
91 | | - } |
92 | | - attach.Size = size |
93 | | - |
94 | | - if _, err := x.Insert(attach); err != nil { |
95 | | - return nil, err |
96 | | - } |
97 | | - |
98 | | - return attach, nil |
99 | | -} |
100 | | - |
101 | 82 | // GetAttachmentByID returns attachment by given id |
102 | 83 | func GetAttachmentByID(id int64) (*Attachment, error) { |
103 | 84 | return getAttachmentByID(x, id) |
@@ -144,6 +125,11 @@ func GetAttachmentByUUID(uuid string) (*Attachment, error) { |
144 | 125 | return getAttachmentByUUID(x, uuid) |
145 | 126 | } |
146 | 127 |
|
| 128 | +// ExistAttachmentsByUUID returns true if attachment is exist by given UUID |
| 129 | +func ExistAttachmentsByUUID(uuid string) (bool, error) { |
| 130 | + return x.Where("`uuid`=?", uuid).Exist(new(Attachment)) |
| 131 | +} |
| 132 | + |
147 | 133 | // GetAttachmentByReleaseIDFileName returns attachment by given releaseId and fileName. |
148 | 134 | func GetAttachmentByReleaseIDFileName(releaseID int64, fileName string) (*Attachment, error) { |
149 | 135 | return getAttachmentByReleaseIDFileName(x, releaseID, fileName) |
|
0 commit comments