summaryrefslogtreecommitdiffstats
path: root/models/attachment.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-04-03 03:25:05 +0800
committertechknowlogick <matti@mdranta.net>2019-04-02 15:25:05 -0400
commit09fb036ad625ec5178319c30df47aac313fdbbe3 (patch)
tree4e5389c39924532023041d530b02a94d3bf987d2 /models/attachment.go
parent0a8e63c68292a08d8a7bc4fa397ae41235f086a7 (diff)
downloadgitea-09fb036ad625ec5178319c30df47aac313fdbbe3.tar.gz
gitea-09fb036ad625ec5178319c30df47aac313fdbbe3.zip
fix upload attachments (#6481)
* fix upload attachments * add migration for new column uploader_id on table attachment * fix imports sequence
Diffstat (limited to 'models/attachment.go')
-rw-r--r--models/attachment.go9
1 files changed, 3 insertions, 6 deletions
diff --git a/models/attachment.go b/models/attachment.go
index 808bc243dc..bbb88939b1 100644
--- a/models/attachment.go
+++ b/models/attachment.go
@@ -7,7 +7,6 @@ package models
import (
"fmt"
"io"
- "mime/multipart"
"os"
"path"
@@ -25,6 +24,7 @@ type Attachment struct {
UUID string `xorm:"uuid UNIQUE"`
IssueID int64 `xorm:"INDEX"`
ReleaseID int64 `xorm:"INDEX"`
+ UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
CommentID int64
Name string
DownloadCount int64 `xorm:"DEFAULT 0"`
@@ -72,11 +72,8 @@ func (a *Attachment) DownloadURL() string {
}
// NewAttachment creates a new attachment object.
-func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment, err error) {
- attach := &Attachment{
- UUID: gouuid.NewV4().String(),
- Name: name,
- }
+func NewAttachment(attach *Attachment, buf []byte, file io.Reader) (_ *Attachment, err error) {
+ attach.UUID = gouuid.NewV4().String()
localPath := attach.LocalPath()
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {