@@ -63,13 +63,12 @@ class CoCreateFileSystem {
63
63
} ) ;
64
64
65
65
if ( ! file || ! file . document || ! file . document [ 0 ] )
66
- return res . status ( 404 ) . send ( `${ url } could not be found for ${ organization_id } ` ) ;
66
+ return res . status ( 404 ) . send ( `${ url } could not be found for ${ organization_id } ` ) ;
67
67
68
68
file = file . document [ 0 ]
69
- if ( ! file [ 'public' ] || file [ 'public' ] === "false" )
69
+ if ( ! file [ 'public' ] || file [ 'public' ] === "false" )
70
70
return res . status ( 404 ) . send ( `access not allowed` ) ;
71
71
72
- console . log ( 'file found' , url )
73
72
let src ;
74
73
if ( file [ 'src' ] )
75
74
src = file [ 'src' ] ;
@@ -84,43 +83,23 @@ class CoCreateFileSystem {
84
83
src = fileSrc [ file [ 'name' ] ] ;
85
84
}
86
85
87
- if ( ! src ) {
88
- console . log ( 'src not found' )
89
- // res.send('could not find src');
90
- }
86
+ if ( ! src )
87
+ return res . status ( 404 ) . send ( `src could not be found` ) ;
91
88
92
89
let contentType = file [ 'content-type' ] || mime . lookup ( url ) || 'text/html' ;
93
- console . log ( 'src' , contentType )
94
90
95
91
if ( contentType . startsWith ( 'image/' ) || contentType . startsWith ( 'audio/' ) || contentType . startsWith ( 'video/' ) ) {
96
-
97
- var base64Data = src . replace ( / ^ d a t a : i m a g e \/ ( p n g | j p e g | j p g ) ; b a s e 6 4 , / , '' ) ;
98
- let file = Buffer . from ( base64Data , 'base64' ) ;
99
-
100
- // res.writeHead(200, {
101
- // 'Content-Type': contentType,
102
- // 'Content-Length': file.length
103
- // });
104
- console . log ( 'after' , contentType )
105
- res . type ( contentType ) ;
106
- res . send ( file ) ;
92
+ src = src . replace ( / ^ d a t a : i m a g e \/ ( p n g | j p e g | j p g ) ; b a s e 6 4 , / , '' ) ;
93
+ src = Buffer . from ( base64Data , 'base64' ) ;
107
94
} else if ( contentType === 'text/html' ) {
108
95
try {
109
- let html = await render . HTML ( src , organization_id ) ;
110
- if ( html )
111
- src = html
112
- }
113
- catch ( err ) {
96
+ src = await render . HTML ( src , organization_id ) ;
97
+ } catch ( err ) {
114
98
console . warn ( 'server-render: ' + err . message )
115
- } finally {
116
- console . log ( 'returned html' )
117
- res . type ( contentType ) ;
118
- res . send ( src )
119
99
}
120
- } else {
121
- res . type ( contentType ) ;
122
- res . send ( src ) ;
123
- }
100
+ }
101
+
102
+ return res . type ( contentType ) . send ( src ) ;
124
103
125
104
} )
126
105
0 commit comments