11const fourohfour = require ( '../elements/404' )
2- const http = require ( 'nets' )
3- const from = require ( 'from2' )
42const html = require ( 'choo/html' )
53
6- const renderData = module . parent ? function ( ) { } : require ( 'render-data' )
7-
84module . exports = function ( state , emit ) {
95 var display = html `< div id ="item ">
106
@@ -14,9 +10,8 @@ module.exports = function (state, emit) {
1410 body : 'This could take a second..' ,
1511 link : false
1612 } ) }
17-
1813 </ div > `
19- if ( module . parent ) return
14+ if ( module . parent ) return display
2015 const entryName = state . preview . entry && state . preview . entry . name
2116
2217 if ( state . preview . error ) {
@@ -39,34 +34,7 @@ module.exports = function (state, emit) {
3934 link : false
4035 } )
4136 }
42-
43- // proper escape is done, but # is special
44- http ( { url : `/download/${ state . archive . key } /${ entryName . replace ( / # / g, '%23' ) } ` , method : 'GET' } , function ( err , resp , file ) {
45- if ( resp . statusCode === 400 ) err = new Error ( 'File does not exist.' )
46- if ( err ) return emit ( 'preview:update' , { error : err } )
47- try {
48- renderData . render ( {
49- name : entryName ,
50- createReadStream : function ( ) {
51- return from ( [ file ] )
52- }
53- } , display , function ( err ) {
54- if ( err ) return onerror ( err )
55- } )
56- } catch ( err ) {
57- onerror ( err )
58- }
59-
60- function onerror ( err ) {
61- console . log ( 'got err' , err )
62- var update = { }
63- console . error ( err )
64- var message = 'Unsupported filetype'
65- update . isLoading = false // Allow downloads for unsupported files
66- update . error = { message : message }
67- console . log ( 'sending' , update )
68- return emit ( 'preview:update' , update )
69- }
70- } )
71- return display
37+ return html `< iframe src ="/download/${ state . archive . key } / ${ entryName . replace ( / # / g, '%23' ) } ">
38+ </ frame >
39+ `
7240}
0 commit comments