Add archive file key extraction to CreatePost and EditPost logic; enhance file migration handling
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 1m11s

This commit is contained in:
2025-10-27 21:41:23 +08:00
parent ecd7926452
commit 7de60ad0c0
3 changed files with 81 additions and 10 deletions

View File

@@ -43,6 +43,16 @@ func (l *CreatePostLogic) CreatePost(req *types.CreatePostReq) (resp *types.Crea
return nil, fmt.Errorf("invalid content format")
}
// Extract all archive file keys from content
archiveKeys, err := utils.ExtractArchiveKeysFromContent(req.Content)
if err != nil {
l.Errorf("Failed to parse archive files from content: %v", err)
return nil, fmt.Errorf("invalid content format")
}
// Combine all file keys
allFileKeys := append(imageKeys, archiveKeys...)
// Extract all hashtags from content
hashtags, err := utils.ExtractHashtagsFromContent(req.Content)
if err != nil {
@@ -61,12 +71,12 @@ func (l *CreatePostLogic) CreatePost(req *types.CreatePostReq) (resp *types.Crea
coverID.Valid = true
}
// Migrate all content images from tmpfiles to files
for _, imageKey := range imageKeys {
_, err := l.migrateFileFromTmpToFiles(tx, imageKey)
// Migrate all content files (images and archives) from tmpfiles to files
for _, fileKey := range allFileKeys {
_, err := l.migrateFileFromTmpToFiles(tx, fileKey)
if err != nil {
l.Errorf("Failed to migrate content image %s: %v", imageKey, err)
// Continue with other images, don't fail the whole operation
l.Errorf("Failed to migrate content file %s: %v", fileKey, err)
// Continue with other files, don't fail the whole operation
}
}

View File

@@ -56,6 +56,16 @@ func (l *EditPostLogic) EditPost(req *types.EditPostReq) (resp *types.EditPostRe
return nil, fmt.Errorf("invalid content format")
}
// Extract all archive file keys from content
archiveKeys, err := utils.ExtractArchiveKeysFromContent(req.Content)
if err != nil {
l.Errorf("Failed to parse archive files from content: %v", err)
return nil, fmt.Errorf("invalid content format")
}
// Combine all file keys
allFileKeys := append(imageKeys, archiveKeys...)
// Extract all hashtags from content
hashtags, err := utils.ExtractHashtagsFromContent(req.Content)
if err != nil {
@@ -100,12 +110,12 @@ func (l *EditPostLogic) EditPost(req *types.EditPostReq) (resp *types.EditPostRe
}
}
// Migrate all content images from tmpfiles to files
for _, imageKey := range imageKeys {
_, err := l.migrateFileFromTmpToFiles(tx, imageKey)
// Migrate all content files (images and archives) from tmpfiles to files
for _, fileKey := range allFileKeys {
_, err := l.migrateFileFromTmpToFiles(tx, fileKey)
if err != nil {
l.Errorf("Failed to migrate content image %s: %v", imageKey, err)
// Continue with other images, don't fail the whole operation
l.Errorf("Failed to migrate content file %s: %v", fileKey, err)
// Continue with other files, don't fail the whole operation
}
}