@@ -24,6 +24,8 @@ export class AttachmentModalComponent implements OnChanges {
24
24
selectedTestResultAttachment : TestResultAttachment ;
25
25
supportedPreviewTypes = [ 'text' , 'image' , 'message' ] ;
26
26
icon = faFile ;
27
+ private readonly maxFileSizeBytes = 10 * 1024 * 1024 ;
28
+ private readonly base64SizeMultiplier = 4 / 3 ;
27
29
28
30
constructor ( private sanitizer : DomSanitizer , private testResultService : TestResultService ) {
29
31
}
@@ -35,6 +37,10 @@ export class AttachmentModalComponent implements OnChanges {
35
37
}
36
38
}
37
39
40
+ get sortedTestResultAttachmentsById ( ) : TestResultAttachment [ ] {
41
+ return this . testResultAttachments ?. sort ( ( a , b ) => a . id - b . id ) || [ ] ;
42
+ }
43
+
38
44
isSupportedPreviewFileType ( ) : boolean {
39
45
let isSupported = false ;
40
46
this . supportedPreviewTypes . forEach ( type => {
@@ -48,7 +54,16 @@ export class AttachmentModalComponent implements OnChanges {
48
54
}
49
55
50
56
isSupportedPreviewFileSize ( ) : boolean {
51
- return this . testResultAttachment . attachment . toString ( ) . length / 1024 / 1024 < 5 ;
57
+ let attachmentSize = 0 ;
58
+
59
+ if ( typeof this . testResultAttachment ?. attachment === 'string' ) {
60
+ const base64Length = this . testResultAttachment . attachment . length ;
61
+ attachmentSize = base64Length / this . base64SizeMultiplier ;
62
+ } else if ( this . testResultAttachment ?. attachment instanceof ArrayBuffer ) {
63
+ attachmentSize = this . testResultAttachment . attachment . byteLength ;
64
+ }
65
+
66
+ return attachmentSize <= this . maxFileSizeBytes ;
52
67
}
53
68
54
69
getNotSupportedMessage ( ) : string {
@@ -57,7 +72,7 @@ export class AttachmentModalComponent implements OnChanges {
57
72
message = 'Preview is not available for this file type.' ;
58
73
}
59
74
if ( ! this . isSupportedPreviewFileSize ( ) ) {
60
- message = 'Preview is not available, the file size should be less than 5Mb .' ;
75
+ message = 'Preview is not available, the file size should be less than 10MB .' ;
61
76
} else { message = 'Preview is not available for the file.' ; }
62
77
return `${ message } You can download the file.` ;
63
78
}
0 commit comments