@@ -438,19 +438,40 @@ plik.controller('MainCtrl', ['$scope', '$api', '$config', '$route', '$location',
438
438
// Parse URI
439
439
var url = new URL ( window . location . origin + uri ) ;
440
440
441
- var regex = / ^ .* \/ ( f i l e | s t r e a m | a r c h i v e ) \/ ( .* ?) \/ ( .* ?) \/ ( .* ) $ / ;
442
- var match = regex . exec ( url . pathname ) ;
443
- if ( ! match && match . length != 5 ) {
444
- $dialog . alert ( { status : 0 , message : "Unable to get uploadId from yubikey redirect" } ) ;
445
- $location . search ( { } ) ;
446
- $location . hash ( "" ) ;
447
- return ;
441
+ var mode ;
442
+ var uploadId ;
443
+ var fileId ;
444
+ var fileName ;
445
+ if ( url . pathname . startsWith ( "/archive" ) ) {
446
+ var regex = / ^ .* \/ ( a r c h i v e ) \/ ( .* ?) \/ ( .* ) $ / ;
447
+ var match = regex . exec ( url . pathname ) ;
448
+ if ( ! match || match . length !== 4 ) {
449
+ $dialog . alert ( { status : 0 , message : "Unable to get upload from yubikey redirect" } ) ;
450
+ $location . search ( { } ) ;
451
+ $location . hash ( "" ) ;
452
+ return ;
453
+ }
454
+
455
+ mode = match [ 1 ] ;
456
+ uploadId = match [ 2 ] ;
457
+ fileName = match [ 3 ] ;
458
+ } else {
459
+ var regex = / ^ .* \/ ( f i l e | s t r e a m ) \/ ( .* ?) \/ ( .* ?) \/ ( .* ) $ / ;
460
+ var match = regex . exec ( url . pathname ) ;
461
+ if ( ! match || match . length !== 5 ) {
462
+ $dialog . alert ( { status : 0 , message : "Unable to get upload from yubikey redirect" } ) ;
463
+ $location . search ( { } ) ;
464
+ $location . hash ( "" ) ;
465
+ return ;
466
+ }
467
+
468
+ mode = match [ 1 ] ;
469
+ uploadId = match [ 2 ] ;
470
+ fileId = match [ 3 ] ;
471
+ fileName = match [ 4 ] ;
448
472
}
449
473
450
- var mode = match [ 1 ] ;
451
- var uploadId = match [ 2 ] ;
452
- var fileId = match [ 3 ] ;
453
- var fileName = match [ 4 ] ;
474
+ fileName = decodeURIComponent ( fileName ) ;
454
475
455
476
var download = false ;
456
477
if ( url . searchParams . get ( "dl" ) == 1 ) {
@@ -462,7 +483,7 @@ plik.controller('MainCtrl', ['$scope', '$api', '$config', '$route', '$location',
462
483
// And I don't want the user to be asked for two tokens.
463
484
// https://github.com/root-gg/plik/issues/215.
464
485
465
- $scope . downloadWithYubikey ( mode , uploadId , fileId , fileName , download ) ;
486
+ downloadWithYubikey ( mode , uploadId , fileId , fileName , download ) ;
466
487
} else {
467
488
var code = $location . search ( ) . errcode ;
468
489
$dialog . alert ( { status : code , message : err } ) ;
@@ -775,6 +796,10 @@ plik.controller('MainCtrl', ['$scope', '$api', '$config', '$route', '$location',
775
796
return filesize ( size , { base : 2 } ) ;
776
797
} ;
777
798
799
+ $scope . getMode = function ( ) {
800
+ return $scope . upload . stream ? "stream" : "file" ;
801
+ }
802
+
778
803
// Build file download URL
779
804
var getFileUrl = function ( mode , uploadID , fileID , fileName , yubikeyToken , dl ) {
780
805
var domain = $scope . config . downloadDomain ? $scope . config . downloadDomain : $api . base ;
@@ -799,8 +824,7 @@ plik.controller('MainCtrl', ['$scope', '$api', '$config', '$route', '$location',
799
824
// Return file download URL
800
825
$scope . getFileUrl = function ( file , dl ) {
801
826
if ( ! file || ! file . metadata ) return ;
802
- var mode = $scope . upload . stream ? "stream" : "file" ;
803
- return getFileUrl ( mode , $scope . upload . id , file . metadata . id , file . metadata . fileName , null , dl ) ;
827
+ return getFileUrl ( $scope . getMode ( ) , $scope . upload . id , file . metadata . id , file . metadata . fileName , null , dl ) ;
804
828
} ;
805
829
806
830
// Return zip archive download URL
@@ -893,22 +917,32 @@ plik.controller('MainCtrl', ['$scope', '$api', '$config', '$route', '$location',
893
917
} ;
894
918
895
919
// Yubikey OTP download dialog
896
- $scope . downloadWithYubikey = function ( mode , uploadID , fileId , fileName , dl ) {
920
+ downloadWithYubikey = function ( mode , uploadID , fileID , fileName , dl ) {
897
921
$dialog . openDialog ( {
898
922
backdrop : true ,
899
923
backdropClick : true ,
900
924
templateUrl : 'partials/yubikey.html' ,
901
925
controller : 'YubikeyController'
902
926
} ) . result . then (
903
927
function ( token ) {
904
- // Redirect to file download URL with yubikey token
905
- var url = getFileUrl ( mode , uploadID , fileId , fileName , token , dl ) ;
928
+ var url = getFileUrl ( mode , uploadID , fileID , fileName , token , dl ) ;
906
929
window . location . replace ( url ) ;
907
930
} , function ( ) {
908
931
// Avoid "Possibly unhandled rejection"
909
932
} ) ;
910
933
} ;
911
934
935
+ // Download file with Yubikey OTP dialog
936
+ $scope . downloadFileWithYubikey = function ( file , dl ) {
937
+ if ( ! file || ! file . metadata ) return ;
938
+ downloadWithYubikey ( $scope . getMode ( ) , $scope . upload . id , file . metadata . id , file . metadata . fileName , dl ) ;
939
+ } ;
940
+
941
+ // Download archive with Yubikey OTP dialog
942
+ $scope . downloadArchiveWithYubikey = function ( file , dl ) {
943
+ downloadWithYubikey ( "archive" , $scope . upload . id , null , "archive.zip" , dl ) ;
944
+ } ;
945
+
912
946
$scope . ttlUnits = [ "days" , "hours" , "minutes" ] ;
913
947
$scope . ttlUnit = "days" ;
914
948
$scope . ttlValue = 30 ;
0 commit comments