fix(asset-library): 素材库 - 支持自定义分类、分页、完整预览和批量上传
This commit is contained in:
@@ -22,6 +22,7 @@ type CanvasProjectsSyncRequest struct {
|
||||
|
||||
type UserDataSummary struct {
|
||||
ID string `json:"id"`
|
||||
FolderID string `json:"folderId,omitempty"`
|
||||
Kind string `json:"kind,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
@@ -54,7 +55,7 @@ func (s *Service) UserAssetSummaries(userID string) ([]UserDataSummary, error) {
|
||||
}
|
||||
result := make([]UserDataSummary, 0, len(assets))
|
||||
for _, asset := range assets {
|
||||
result = append(result, UserDataSummary{ID: asset.ID, Kind: asset.Kind, Category: string(asset.Category), Status: string(asset.Status), Title: asset.Title, CreatedAt: asset.CreatedAt, UpdatedAt: asset.UpdatedAt})
|
||||
result = append(result, UserDataSummary{ID: asset.ID, FolderID: asset.FolderID, Kind: asset.Kind, Category: string(asset.Category), Status: string(asset.Status), Title: asset.Title, CreatedAt: asset.CreatedAt, UpdatedAt: asset.UpdatedAt})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -78,6 +79,14 @@ func (s *Service) UpsertUserAsset(userID string, raw json.RawMessage) (UserDataS
|
||||
}
|
||||
s.storageMu.Lock()
|
||||
defer s.storageMu.Unlock()
|
||||
if asset.FolderID != "" {
|
||||
if _, err := s.repo.AssetFolderForUser(userID, asset.FolderID); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return UserDataSummary{}, BadAuthRequest("素材分类不存在")
|
||||
}
|
||||
return UserDataSummary{}, err
|
||||
}
|
||||
}
|
||||
existing, existingErr := s.repo.AssetForUser(userID, asset.ID)
|
||||
if existingErr != nil && !errors.Is(existingErr, gorm.ErrRecordNotFound) {
|
||||
return UserDataSummary{}, existingErr
|
||||
@@ -104,7 +113,7 @@ func (s *Service) UpsertUserAsset(userID string, raw json.RawMessage) (UserDataS
|
||||
if existingErr != nil {
|
||||
s.recordActivity(userID, "asset", 1)
|
||||
}
|
||||
return UserDataSummary{ID: asset.ID, Kind: asset.Kind, Category: string(asset.Category), Status: string(asset.Status), Title: asset.Title, CreatedAt: asset.CreatedAt, UpdatedAt: asset.UpdatedAt}, nil
|
||||
return UserDataSummary{ID: asset.ID, FolderID: asset.FolderID, Kind: asset.Kind, Category: string(asset.Category), Status: string(asset.Status), Title: asset.Title, CreatedAt: asset.CreatedAt, UpdatedAt: asset.UpdatedAt}, nil
|
||||
}
|
||||
|
||||
func (s *Service) DeleteUserAsset(userID string, id string) error {
|
||||
@@ -283,6 +292,7 @@ func assetFromJSON(userID string, raw json.RawMessage) (model.Asset, error) {
|
||||
}
|
||||
var payload struct {
|
||||
ID string `json:"id"`
|
||||
FolderID string `json:"folderId"`
|
||||
Kind string `json:"kind"`
|
||||
Category string `json:"category"`
|
||||
Status string `json:"status"`
|
||||
@@ -316,6 +326,7 @@ func assetFromJSON(userID string, raw json.RawMessage) (model.Asset, error) {
|
||||
return model.Asset{
|
||||
ID: id,
|
||||
UserID: userID,
|
||||
FolderID: strings.TrimSpace(payload.FolderID),
|
||||
Kind: strings.TrimSpace(payload.Kind),
|
||||
Category: category,
|
||||
Status: status,
|
||||
|
||||
Reference in New Issue
Block a user