feat(posts): add preview URL fields for post images
Add PreviewURL and PreviewURLLarge fields to PostImage model and responses. Image data now supports format "url|preview_url|preview_url_large" for storing multiple image variants. Also change comment cursor pagination to sort by created_at ASC (oldest first) to display earliest comments as first floor, and make AdminReviewVerificationRequest.Approve field optional.
This commit is contained in:
@@ -148,11 +148,22 @@ func (r *postRepository) UpdateWithImages(post *model.Post, images *[]string) er
|
||||
return err
|
||||
}
|
||||
|
||||
for i, url := range *images {
|
||||
for i, imageData := range *images {
|
||||
parts := strings.Split(imageData, "|")
|
||||
url := parts[0]
|
||||
var previewURL, previewURLLarge string
|
||||
if len(parts) >= 2 && parts[1] != "" {
|
||||
previewURL = parts[1]
|
||||
}
|
||||
if len(parts) >= 3 && parts[2] != "" {
|
||||
previewURLLarge = parts[2]
|
||||
}
|
||||
image := &model.PostImage{
|
||||
PostID: post.ID,
|
||||
URL: url,
|
||||
SortOrder: i,
|
||||
PostID: post.ID,
|
||||
URL: url,
|
||||
PreviewURL: previewURL,
|
||||
PreviewURLLarge: previewURLLarge,
|
||||
SortOrder: i,
|
||||
}
|
||||
if err := tx.Create(image).Error; err != nil {
|
||||
return err
|
||||
@@ -695,11 +706,23 @@ func (r *postRepository) createWithTx(tx *gorm.DB, post *model.Post, images []st
|
||||
}
|
||||
|
||||
// 创建图片记录
|
||||
for i, url := range images {
|
||||
// 支持格式:["url", "url|preview_url|preview_url_large", ...]
|
||||
for i, imageData := range images {
|
||||
parts := strings.Split(imageData, "|")
|
||||
url := parts[0]
|
||||
var previewURL, previewURLLarge string
|
||||
if len(parts) >= 2 && parts[1] != "" {
|
||||
previewURL = parts[1]
|
||||
}
|
||||
if len(parts) >= 3 && parts[2] != "" {
|
||||
previewURLLarge = parts[2]
|
||||
}
|
||||
image := &model.PostImage{
|
||||
PostID: post.ID,
|
||||
URL: url,
|
||||
SortOrder: i,
|
||||
PostID: post.ID,
|
||||
URL: url,
|
||||
PreviewURL: previewURL,
|
||||
PreviewURLLarge: previewURLLarge,
|
||||
SortOrder: i,
|
||||
}
|
||||
if err := tx.Create(image).Error; err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user