@@ -28,7 +28,6 @@ const Card = ({
28
28
} , [ isSelected ] ) ;
29
29
30
30
const handleDownload = async ( paper : Paper ) => {
31
-
32
31
const extension = paper . finalUrl . split ( "." ) . pop ( ) ;
33
32
const fileName = `${ extractBracketContent ( paper . subject ) } -${ paper . exam } -${ paper . slot } -${ paper . year } .${ extension } ` ;
34
33
await downloadFile ( paper . finalUrl , fileName ) ;
@@ -40,23 +39,16 @@ const Card = ({
40
39
}
41
40
42
41
async function downloadFile ( url : string , filename : string ) {
43
- if ( / M o b i | A n d r o i d / i. test ( navigator . userAgent ) ) {
44
- window . location . href = url ;
45
- } else {
46
- try {
47
- const response = await axios . get ( url , { responseType : "blob" } ) ;
48
- const blob = new Blob ( [ response . data ] ) ;
49
- const link = document . createElement ( "a" ) ;
50
- link . href = window . URL . createObjectURL ( blob ) ;
51
- link . download = filename ;
52
-
53
- document . body . appendChild ( link ) ;
54
- link . click ( ) ;
55
- document . body . removeChild ( link ) ;
56
- window . URL . revokeObjectURL ( link . href ) ;
57
- } catch ( error ) {
58
- console . error ( "Error downloading file:" , error ) ;
59
- }
42
+ try {
43
+ const response = await axios . get ( url , { responseType : "blob" } ) ;
44
+ const blob = new Blob ( [ response . data ] ) ;
45
+ const link = document . createElement ( "a" ) ;
46
+ link . href = window . URL . createObjectURL ( blob ) ;
47
+ link . download = filename ;
48
+ link . click ( ) ;
49
+ window . URL . revokeObjectURL ( link . href ) ;
50
+ } catch ( error ) {
51
+ console . error ( "Error downloading file:" , error ) ;
60
52
}
61
53
}
62
54
0 commit comments