ciyidogan commited on
Commit
8ba153e
·
verified ·
1 Parent(s): 9e1ff71

Update flare-ui/src/app/services/conversation-manager.service.ts

Browse files
flare-ui/src/app/services/conversation-manager.service.ts CHANGED
@@ -464,6 +464,11 @@ export class ConversationManagerService implements OnDestroy {
464
  preview: combinedBase64.substring(0, 100)
465
  });
466
 
 
 
 
 
 
467
  const audioBlob = this.base64ToBlob(combinedBase64, message['mime_type'] || 'audio/mpeg');
468
  const audioUrl = URL.createObjectURL(audioBlob);
469
 
@@ -489,10 +494,28 @@ export class ConversationManagerService implements OnDestroy {
489
  }
490
  }
491
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
  private base64ToBlob(base64: string, mimeType: string): Blob {
493
  try {
494
- console.log('Base64 length:', base64.length);
495
- console.log('Base64 preview:', base64.substring(0, 100));
 
 
496
 
497
  const byteCharacters = atob(base64);
498
  const byteNumbers = new Array(byteCharacters.length);
 
464
  preview: combinedBase64.substring(0, 100)
465
  });
466
 
467
+ // Validate base64
468
+ if (!this.isValidBase64(combinedBase64)) {
469
+ throw new Error('Invalid base64 data received');
470
+ }
471
+
472
  const audioBlob = this.base64ToBlob(combinedBase64, message['mime_type'] || 'audio/mpeg');
473
  const audioUrl = URL.createObjectURL(audioBlob);
474
 
 
494
  }
495
  }
496
 
497
+ private isValidBase64(str: string): boolean {
498
+ try {
499
+ // Check if string contains only valid base64 characters
500
+ const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
501
+ if (!base64Regex.test(str)) {
502
+ return false;
503
+ }
504
+
505
+ // Try to decode to verify
506
+ atob(str);
507
+ return true;
508
+ } catch (e) {
509
+ return false;
510
+ }
511
+ }
512
+
513
  private base64ToBlob(base64: string, mimeType: string): Blob {
514
  try {
515
+ console.log('Converting base64 to blob:', {
516
+ length: base64.length,
517
+ mimeType: mimeType
518
+ });
519
 
520
  const byteCharacters = atob(base64);
521
  const byteNumbers = new Array(byteCharacters.length);