diff --git a/app/internal/logic/createpostlogic.go b/app/internal/logic/createpostlogic.go index 29805ee..e9e0ffc 100644 --- a/app/internal/logic/createpostlogic.go +++ b/app/internal/logic/createpostlogic.go @@ -9,7 +9,6 @@ import ( "git.cialloo.com/CiallooWeb/Blog/app/internal/types" "git.cialloo.com/CiallooWeb/Blog/app/internal/utils" - "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/zeromicro/go-zero/core/logx" ) @@ -99,28 +98,18 @@ func (l *CreatePostLogic) migrateFileFromTmpToFiles(tx *sql.Tx, fileKey string) return 0, err } - // Verify file exists in S3 bucket - _, err = l.svcCtx.S3Client.HeadObject(l.ctx, &s3.HeadObjectInput{ - Bucket: &l.svcCtx.Config.S3.Bucket, - Key: &fileKey, - }) - if err != nil { - l.Errorf("File not found in S3 bucket: %s, error: %v", fileKey, err) - return 0, fmt.Errorf("file not found in storage") - } - - // Get file name from tmpfiles (if exists) + // Verify file exists in tmpfiles table var fileName string tmpQuery := `SELECT file_name FROM tmpfiles WHERE key = $1` err = tx.QueryRowContext(l.ctx, tmpQuery, fileKey).Scan(&fileName) - if err != nil && err != sql.ErrNoRows { + if err != nil { + if err == sql.ErrNoRows { + l.Errorf("File not found in tmpfiles with key: %s", fileKey) + return 0, fmt.Errorf("file not found") + } l.Errorf("Failed to get tmpfile: %v", err) return 0, err } - if err == sql.ErrNoRows { - // File not in tmpfiles, use file key as name - fileName = fileKey - } // Insert into files table var fileID int64 @@ -131,7 +120,7 @@ func (l *CreatePostLogic) migrateFileFromTmpToFiles(tx *sql.Tx, fileKey string) return 0, err } - // Delete from tmpfiles if exists + // Delete from tmpfiles deleteQuery := `DELETE FROM tmpfiles WHERE key = $1` _, err = tx.ExecContext(l.ctx, deleteQuery, fileKey) if err != nil { diff --git a/app/internal/logic/editpostlogic.go b/app/internal/logic/editpostlogic.go index 6546dec..280bdfb 100644 --- a/app/internal/logic/editpostlogic.go +++ b/app/internal/logic/editpostlogic.go @@ -9,7 +9,6 @@ import ( "git.cialloo.com/CiallooWeb/Blog/app/internal/types" "git.cialloo.com/CiallooWeb/Blog/app/internal/utils" - "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/zeromicro/go-zero/core/logx" ) @@ -127,28 +126,18 @@ func (l *EditPostLogic) migrateFileFromTmpToFiles(tx *sql.Tx, fileKey string) (i return 0, err } - // Verify file exists in S3 bucket - _, err = l.svcCtx.S3Client.HeadObject(l.ctx, &s3.HeadObjectInput{ - Bucket: &l.svcCtx.Config.S3.Bucket, - Key: &fileKey, - }) - if err != nil { - l.Errorf("File not found in S3 bucket: %s, error: %v", fileKey, err) - return 0, fmt.Errorf("file not found in storage") - } - - // Get file name from tmpfiles (if exists) + // Verify file exists in tmpfiles table var fileName string tmpQuery := `SELECT file_name FROM tmpfiles WHERE key = $1` err = tx.QueryRowContext(l.ctx, tmpQuery, fileKey).Scan(&fileName) - if err != nil && err != sql.ErrNoRows { + if err != nil { + if err == sql.ErrNoRows { + l.Errorf("File not found in tmpfiles with key: %s", fileKey) + return 0, fmt.Errorf("file not found") + } l.Errorf("Failed to get tmpfile: %v", err) return 0, err } - if err == sql.ErrNoRows { - // File not in tmpfiles, use file key as name - fileName = fileKey - } // Insert into files table var fileID int64 @@ -159,7 +148,7 @@ func (l *EditPostLogic) migrateFileFromTmpToFiles(tx *sql.Tx, fileKey string) (i return 0, err } - // Delete from tmpfiles if exists + // Delete from tmpfiles deleteQuery := `DELETE FROM tmpfiles WHERE key = $1` _, err = tx.ExecContext(l.ctx, deleteQuery, fileKey) if err != nil {