Correctly show timestamps of files
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2019-10-13 22:34:41 +02:00
parent bcf3a98b46
commit 07233b2604
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 25 additions and 16 deletions

View File

@ -32,11 +32,10 @@ type File struct {
Mime string `xorm:"text null" json:"mime"`
Size int64 `xorm:"int(11) not null" json:"size"`
Created time.Time `xorm:"datetime" json:"created"`
Updated time.Time `xorm:"datetime" json:"updated"`
Created time.Time `xorm:"-" json:"created"`
InsertedUnix int64 `xorm:"created" json:"inserted_unix"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
CreatedUnix int64 `xorm:"created" json:"-"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
File afero.File `xorm:"-" json:"-"`
}
@ -62,6 +61,7 @@ func (f *File) LoadFileMetaByID() (err error) {
if !exists {
return ErrFileDoesNotExist{FileID: f.ID}
}
f.Created = time.Unix(f.CreatedUnix, 0)
return
}

View File

@ -19,20 +19,15 @@ package migration
import (
"github.com/go-xorm/xorm"
"src.techknowlogick.com/xormigrate"
"time"
)
type file20191008194238 struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
Name string `xorm:"text not null" json:"name"`
Mime string `xorm:"text null" json:"mime"`
Size int64 `xorm:"int(11) not null default 0" json:"size"`
Created time.Time `xorm:"datetime" json:"created"`
Updated time.Time `xorm:"datetime" json:"updated"`
InsertedUnix int64 `xorm:"created" json:"inserted_unix"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
Name string `xorm:"text not null" json:"name"`
Mime string `xorm:"text null" json:"mime"`
Size int64 `xorm:"int(11) not null default 0" json:"size"`
CreatedUnix int64 `xorm:"created" json:"inserted_unix"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
}
func (file20191008194238) TableName() string {

View File

@ -21,6 +21,7 @@ import (
"code.vikunja.io/web"
"io"
"os"
"time"
)
// TaskAttachment is the definition of a task attachment
@ -34,7 +35,7 @@ type TaskAttachment struct {
File *files.File `xorm:"-" json:"file"`
Created int64 `xorm:"created"`
Created int64 `xorm:"created" json:"created"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`
@ -105,15 +106,28 @@ func (ta *TaskAttachment) ReadAll(s string, a web.Auth, page int) (interface{},
}
fileIDs := make([]int64, 0, len(attachments))
userIDs := make([]int64, 0, len(attachments))
for _, r := range attachments {
fileIDs = append(fileIDs, r.ID)
userIDs = append(userIDs, r.CreatedByID)
}
fs := make(map[int64]*files.File)
err = x.In("id", fileIDs).Find(&fs)
if err != nil {
return nil, err
}
us := make(map[int64]*User)
err = x.In("id", userIDs).Find(&us)
if err != nil {
return nil, err
}
for _, r := range attachments {
r.File = fs[r.FileID]
r.File.Created = time.Unix(r.File.CreatedUnix, 0)
r.CreatedBy = us[r.CreatedByID]
}
return attachments, err