|
|
@@ -24,7 +24,9 @@ type Image struct { |
|
|
|
Topics []string `xorm:"TEXT JSON" json:"topics"` |
|
|
|
Place string `xorm:"varchar(300)" json:"place"` |
|
|
|
NumStars int `xorm:"NOT NULL DEFAULT 0" json:"numStars"` |
|
|
|
Creator *User `xorm:"-" json:"creator"` |
|
|
|
IsStar bool `xorm:"-" json:"isStar"` |
|
|
|
UserName string `xorm:"-" json:"userName"` |
|
|
|
RelAvatarLink string `xorm:"-" json:"relAvatarLink"` |
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created" json:"createdUnix"` |
|
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated" json:"updatedUnix"` |
|
|
|
} |
|
|
@@ -388,14 +390,14 @@ func SearchImageByCondition(opts *SearchImageOptions, cond builder.Cond) (ImageL |
|
|
|
return nil, 0, fmt.Errorf("Images: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
if err = images.loadAttributes(sess); err != nil { |
|
|
|
if err = images.loadAttributes(sess, opts.UID); err != nil { |
|
|
|
return nil, 0, fmt.Errorf("LoadAttributes: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
return images, count, nil |
|
|
|
} |
|
|
|
|
|
|
|
func (images ImageList) loadAttributes(e Engine) error { |
|
|
|
func (images ImageList) loadAttributes(e Engine, uid int64) error { |
|
|
|
if len(images) == 0 { |
|
|
|
return nil |
|
|
|
} |
|
|
@@ -417,8 +419,13 @@ func (images ImageList) loadAttributes(e Engine) error { |
|
|
|
} |
|
|
|
|
|
|
|
for i := range images { |
|
|
|
images[i].Creator = users[images[i].UID] |
|
|
|
|
|
|
|
images[i].UserName = users[images[i].UID].Name |
|
|
|
images[i].RelAvatarLink = users[images[i].UID].RelAvatarLink() |
|
|
|
if uid == -1 { |
|
|
|
images[i].IsStar = false |
|
|
|
} else { |
|
|
|
images[i].IsStar = isImageStaring(e, uid, images[i].ID) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|