ProcessMediaForS3 handles the complete media upload process
(ctx context.Context, userID, contactJID, messageID string, data []byte, mimeType string, fileName string, isIncoming bool)
| 349 | |
| 350 | // ProcessMediaForS3 handles the complete media upload process |
| 351 | func (m *S3Manager) ProcessMediaForS3(ctx context.Context, userID, contactJID, messageID string, |
| 352 | data []byte, mimeType string, fileName string, isIncoming bool) (map[string]interface{}, error) { |
| 353 | |
| 354 | // Generate S3 key |
| 355 | key := m.GenerateS3Key(userID, contactJID, messageID, mimeType, isIncoming) |
| 356 | |
| 357 | // Upload to S3 |
| 358 | err := m.UploadToS3(ctx, userID, key, data, mimeType) |
| 359 | if err != nil { |
| 360 | return nil, fmt.Errorf("failed to upload to S3: %w", err) |
| 361 | } |
| 362 | |
| 363 | // Generate public URL |
| 364 | publicURL := m.GetPublicURL(userID, key) |
| 365 | |
| 366 | // Read the bucket through GetClient, which acquires the read lock — this |
| 367 | // avoids racing with a concurrent reconfigure/removal of the configs map and |
| 368 | // the nil deref the previous unlocked read could hit. |
| 369 | bucket := "" |
| 370 | if _, config, ok := m.GetClient(userID); ok && config != nil { |
| 371 | bucket = config.Bucket |
| 372 | } |
| 373 | |
| 374 | // Return S3 metadata |
| 375 | s3Data := map[string]interface{}{ |
| 376 | "url": publicURL, |
| 377 | "key": key, |
| 378 | "bucket": bucket, |
| 379 | "size": len(data), |
| 380 | "mimeType": mimeType, |
| 381 | "fileName": fileName, |
| 382 | } |
| 383 | |
| 384 | return s3Data, nil |
| 385 | } |
| 386 | |
| 387 | // DeleteAllUserObjects deletes all user files from S3 |
| 388 | func (m *S3Manager) DeleteAllUserObjects(ctx context.Context, userID string) error { |
no test coverage detected