46
46
47
47
<div class =" col ul-status-message" >
48
48
<label class =" select-file-btn" >
49
- <input :name =" 'ul-' + componentId" type =" file" @change =" processFile" class =" d-none" >
49
+
50
+ <input v-if =" expectsZip"
51
+ :name =" 'ul-' + componentId"
52
+ accept =" .zip,application/zip,application/x-zip-compressed,multipart/x-zip"
53
+ type =" file"
54
+ @change =" processFile"
55
+ class =" d-none" >
56
+ <input v-else-if =" blueprints[0].format === 'json'"
57
+ :name =" 'ul-' + componentId"
58
+ accept =" .json,application/json"
59
+ type =" file"
60
+ @change =" processFile"
61
+ class =" d-none" >
62
+ <input v-else-if =" blueprints[0].format === 'csv'"
63
+ :name =" 'ul-' + componentId"
64
+ accept =" .csv,text/csv"
65
+ type =" file"
66
+ @change =" processFile"
67
+ class =" d-none" >
68
+
50
69
{{ $t('choose-file') }}
51
70
</label >
52
71
</div >
130
149
<div class =" row" >
131
150
<div class =" col extraction-information-container" >
132
151
<template v-for =" bp in blueprints " :key =" bp " >
133
- <div class =" ul-status row align-items-start pt-2 pb-2" :class =" { 'ul-success': blueprintData[bp.id.toString()].status === 'success', 'ul-failed': blueprintData[bp.id.toString()].status === 'failed'}" >
152
+ <div class =" ul-status row align-items-start pt-2 pb-2"
153
+ :class =" { 'ul-success': blueprintData[bp.id.toString()].status === 'success', 'ul-failed': blueprintData[bp.id.toString()].status === 'failed'}" >
134
154
135
155
<!-- Pending -->
136
156
<template v-if =" blueprintData [bp .id .toString ()].status === ' pending' " >
@@ -408,6 +428,23 @@ export default {
408
428
this .emitToParent ();
409
429
},
410
430
methods: {
431
+ /**
432
+ * Validate that a file is a ZIP file.
433
+ * @param file
434
+ */
435
+ checkIsZip (file ) {
436
+ const extensionIsValid = file .name .toLowerCase ().endsWith (' .zip' );
437
+ const mimeIsValid = [
438
+ ' application/zip' ,
439
+ ' application/x-zip-compressed' ,
440
+ ' multipart/x-zip'
441
+ ].includes (file .type );
442
+ if (extensionIsValid && mimeIsValid) {
443
+ return true ;
444
+ } else {
445
+ return false ;
446
+ }
447
+ },
411
448
/**
412
449
* Processes the file uploaded by the participant.
413
450
* @param event
@@ -421,48 +458,57 @@ export default {
421
458
422
459
// Procedure if supplied file is expected to be a zip-folder.
423
460
if (uploader .expectsZip && files .length === 1 ) {
424
- JSZip
425
- .loadAsync (files[0 ])
426
- .then (z => {
427
- uploader .blueprints .forEach (blueprint => {
428
- let re = new RegExp (blueprint .regex_path );
429
- let reHasMatched = false ;
430
- z .file (re).forEach (f => {
431
- reHasMatched = true ;
432
- f
433
- .async (" string" )
434
- .then (c => uploader .processContent (c, blueprint))
435
- .catch (e => {
436
- uploader .postError (4199 , e .message );
437
- uploader .recordError (uploader .$t (' error-generic' ) + e .message , blueprint .id .toString ());
438
- })
461
+
462
+ // Check that file is a ZIP file.
463
+ const uploadedFile = files[0 ]
464
+ if (uploader .checkIsZip (uploadedFile) === false ) {
465
+ uploader .postError (4101 , uploader .$t (' error-not-zip' ));
466
+ uploader .recordError (uploader .$t (' error-not-zip' ), ' general' );
467
+ } else {
468
+
469
+ JSZip
470
+ .loadAsync (uploadedFile)
471
+ .then (z => {
472
+ uploader .blueprints .forEach (blueprint => {
473
+ let re = new RegExp (blueprint .regex_path );
474
+ let reHasMatched = false ;
475
+ z .file (re).forEach (f => {
476
+ reHasMatched = true ;
477
+ f
478
+ .async (" string" )
479
+ .then (c => uploader .processContent (c, blueprint))
480
+ .catch (e => {
481
+ uploader .postError (4199 , e .message );
482
+ uploader .recordError (uploader .$t (' error-generic' ) + e .message , blueprint .id .toString ());
483
+ })
484
+ })
485
+ if (! reHasMatched) {
486
+ uploader .postError (4180 , uploader .$t (' error-regex-not-matched' ), blueprint .id );
487
+ uploader .postError (4181 , ` Files in uploaded folder: ${ Object .keys (z .files )} ` , blueprint .id );
488
+ uploader .recordError (uploader .$t (' error-regex-not-matched' ), blueprint .id .toString ());
489
+ }
439
490
})
440
- if (! reHasMatched) {
441
- uploader .postError (4180 , uploader .$t (' error-regex-not-matched' ), blueprint .id );
442
- uploader .postError (4181 , ` Files in uploaded folder: ${ Object .keys (z .files )} ` , blueprint .id );
443
- uploader .recordError (uploader .$t (' error-regex-not-matched' ), blueprint .id .toString ());
491
+ })
492
+ .catch (e => {
493
+ let myMess = ' ' ;
494
+ let statusCode = 0 ;
495
+ if (e .message .includes (' zip' ) && e .message .includes (' central' )) {
496
+ myMess = uploader .$t (' error-not-zip' );
497
+ statusCode = 4101 ;
498
+ } else if (e .message .includes (' Corrupted zip' )) {
499
+ myMess = uploader .$t (' error-zip-corrupted' );
500
+ statusCode = 4102 ;
501
+ } else if (e .message .includes (' Encrypted zip' )) {
502
+ myMess = uploader .$t (' error-zip-encrypted' );
503
+ statusCode = 4103 ;
504
+ } else {
505
+ myMess = uploader .$t (' error-generic' ) + e .message ;
506
+ statusCode = 4198 ;
444
507
}
508
+ uploader .postError (statusCode, e .message );
509
+ uploader .recordError (myMess, ' general' );
445
510
})
446
- })
447
- .catch (e => {
448
- let myMess = ' ' ;
449
- let statusCode = 0 ;
450
- if (e .message .includes (' zip' ) && e .message .includes (' central' )) {
451
- myMess = uploader .$t (' error-not-zip' );
452
- statusCode = 4101 ;
453
- } else if (e .message .includes (' Corrupted zip' )) {
454
- myMess = uploader .$t (' error-zip-corrupted' );
455
- statusCode = 4102 ;
456
- } else if (e .message .includes (' Encrypted zip' )) {
457
- myMess = uploader .$t (' error-zip-encrypted' );
458
- statusCode = 4103 ;
459
- } else {
460
- myMess = uploader .$t (' error-generic' ) + e .message ;
461
- statusCode = 4198 ;
462
- }
463
- uploader .postError (statusCode, e .message );
464
- uploader .recordError (myMess, ' general' );
465
- })
511
+ }
466
512
}
467
513
468
514
// Procedure if supplied file is expected to be a single file.
0 commit comments