diff options
Diffstat (limited to 'models/upload.go')
-rw-r--r-- | models/upload.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/models/upload.go b/models/upload.go index de2032fb72..ca88c6a393 100644 --- a/models/upload.go +++ b/models/upload.go @@ -12,6 +12,7 @@ import ( "os" "path" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -34,6 +35,10 @@ type Upload struct { Name string } +func init() { + db.RegisterModel(new(Upload)) +} + // UploadLocalPath returns where uploads is stored in local file system based on given UUID. func UploadLocalPath(uuid string) string { return path.Join(setting.Repository.Upload.TempPath, uuid[0:1], uuid[1:2], uuid) @@ -68,7 +73,7 @@ func NewUpload(name string, buf []byte, file multipart.File) (_ *Upload, err err return nil, fmt.Errorf("Copy: %v", err) } - if _, err := x.Insert(upload); err != nil { + if _, err := db.DefaultContext().Engine().Insert(upload); err != nil { return nil, err } @@ -78,7 +83,7 @@ func NewUpload(name string, buf []byte, file multipart.File) (_ *Upload, err err // GetUploadByUUID returns the Upload by UUID func GetUploadByUUID(uuid string) (*Upload, error) { upload := &Upload{} - has, err := x.Where("uuid=?", uuid).Get(upload) + has, err := db.DefaultContext().Engine().Where("uuid=?", uuid).Get(upload) if err != nil { return nil, err } else if !has { @@ -95,7 +100,7 @@ func GetUploadsByUUIDs(uuids []string) ([]*Upload, error) { // Silently drop invalid uuids. uploads := make([]*Upload, 0, len(uuids)) - return uploads, x.In("uuid", uuids).Find(&uploads) + return uploads, db.DefaultContext().Engine().In("uuid", uuids).Find(&uploads) } // DeleteUploads deletes multiple uploads @@ -104,7 +109,7 @@ func DeleteUploads(uploads ...*Upload) (err error) { return nil } - sess := x.NewSession() + sess := db.DefaultContext().NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err |