1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

fix upload attachments (#6481)

* fix upload attachments

* add migration for new column uploader_id on table attachment

* fix imports sequence
This commit is contained in:
Lunny Xiao
2019-04-03 03:25:05 +08:00
committed by techknowlogick
parent 0a8e63c682
commit 09fb036ad6
7 changed files with 76 additions and 14 deletions

View File

@@ -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 {