feat: 添加内容置顶功能,更新相关数据模型和前端视图
This commit is contained in:
@@ -101,7 +101,7 @@ func (s *common) InitUpload(ctx context.Context, userID int64, form *common_dto.
|
||||
localPath = "./storage"
|
||||
}
|
||||
tempDir := filepath.Join(localPath, "temp", uploadID)
|
||||
if err := os.MkdirAll(tempDir, 0755); err != nil {
|
||||
if err := os.MkdirAll(tempDir, 0o755); err != nil {
|
||||
return nil, errorx.ErrInternalError.WithCause(err)
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ func (s *common) CompleteUpload(ctx context.Context, userID int64, form *common_
|
||||
}
|
||||
|
||||
hash := hex.EncodeToString(hasher.Sum(nil))
|
||||
dst.Close(); // Ensure flush before potential removal
|
||||
dst.Close() // Ensure flush before potential removal
|
||||
os.RemoveAll(tempDir)
|
||||
|
||||
// Deduplication Logic (Similar to Upload)
|
||||
|
||||
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
@@ -129,6 +130,7 @@ func (s *creator) ListContents(
|
||||
}
|
||||
}
|
||||
if filter.Key != nil && *filter.Key != "" {
|
||||
fmt.Printf("DEBUG: Filter Key: '%s'\n", *filter.Key)
|
||||
q = q.Where(tbl.Key.Eq(*filter.Key))
|
||||
}
|
||||
if filter.Keyword != nil && *filter.Keyword != "" {
|
||||
@@ -205,6 +207,7 @@ func (s *creator) ListContents(
|
||||
VideoCount: videoCount,
|
||||
AudioCount: audioCount,
|
||||
Status: string(item.Status),
|
||||
IsPinned: item.IsPinned,
|
||||
IsPurchased: false,
|
||||
})
|
||||
}
|
||||
@@ -311,11 +314,48 @@ func (s *creator) UpdateContent(
|
||||
if form.Status != "" {
|
||||
contentUpdates.Status = consts.ContentStatus(form.Status)
|
||||
}
|
||||
|
||||
// Determine final status
|
||||
finalStatus := c.Status
|
||||
if form.Status != "" {
|
||||
finalStatus = consts.ContentStatus(form.Status)
|
||||
}
|
||||
|
||||
// Validation: Only published content can be pinned
|
||||
if form.IsPinned != nil && *form.IsPinned && finalStatus != consts.ContentStatusPublished {
|
||||
return errorx.ErrBadRequest.WithMsg("只有已发布的内容支持置顶")
|
||||
}
|
||||
|
||||
// Perform standard updates
|
||||
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(contentUpdates)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Handle IsPinned Logic
|
||||
if finalStatus != consts.ContentStatusPublished {
|
||||
// Force Unpin if not published
|
||||
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.IsPinned.Value(false))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if form.IsPinned != nil {
|
||||
// Explicit Pin Update requested
|
||||
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.IsPinned.Value(*form.IsPinned))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If setting to true, unpin others
|
||||
if *form.IsPinned {
|
||||
if _, err := tx.Content.WithContext(ctx).
|
||||
Where(tx.Content.TenantID.Eq(tid), tx.Content.ID.Neq(cid)).
|
||||
UpdateSimple(tx.Content.IsPinned.Value(false)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Update Price
|
||||
// Check if price exists
|
||||
if form.Price != nil {
|
||||
|
||||
Reference in New Issue
Block a user