1+ import "./style.css" ;
12import { downloadFile , fetchDownloadUrl } from "./lib/fetch" ;
23
34const main = async ( ) => {
@@ -10,13 +11,29 @@ const main = async () => {
1011 return result . message ;
1112 }
1213
14+ const progressBar = document . getElementById ( "progress" ) ;
15+ const status = document . getElementById ( "result" ) ;
16+
1317 const downloadUrl = result . value ;
14- const result1 = await downloadFile ( downloadUrl ) ;
18+ const result1 = await downloadFile ( downloadUrl , ( progress ) => {
19+ if ( progress < 0 ) {
20+ return ;
21+ }
22+
23+ if ( progressBar ) {
24+ progressBar . setAttribute ( "value" , String ( progress ) ) ;
25+ progressBar . innerText = `${ Math . floor ( progress * 100 ) } %` ;
26+ }
27+ if ( status ) {
28+ status . innerText = `ファイルをダウンロードしています……: ${ Math . floor ( progress * 100 ) } %` ;
29+ }
30+ } ) ;
31+
1532 if ( ! result1 . ok ) {
1633 return result1 . message ;
1734 }
1835
19- const buf = result1 . value ;
36+ const buf = await result1 . value . arrayBuffer ( ) ;
2037 const view = new DataView ( buf ) ;
2138
2239 // end of central directory record(EOCD)を探す
@@ -100,7 +117,6 @@ const main = async () => {
100117 // blobに変換して遷移
101118 const blob = new Blob ( [ fileData ] , { type : "application/pdf" } ) ;
102119 const blobUrl = window . URL . createObjectURL ( blob ) ;
103- history . pushState ( null , "" , `?dist=${ encodeURIComponent ( url ) } ` ) ;
104120 window . location . href = blobUrl ;
105121} ;
106122
@@ -111,6 +127,7 @@ const main = async () => {
111127 }
112128
113129 const error = await main ( ) ;
130+
114131 if ( error ) {
115132 if ( elm ) {
116133 elm . innerText = error ;
0 commit comments