@@ -30,7 +30,7 @@ let path = require("path")
3030 console . log ( "Removing " + "\x1b[32m" + String ( filess [ file ] ) + "\x1b[37m" )
3131 fs . unlinkSync ( path . join ( __dirname , "static" , filess [ file ] ) )
3232 }
33- }
33+ }
3434 }
3535 console . log ( "Done!" )
3636 console . log ( "Now we can start the HTTP server lol" )
@@ -122,36 +122,33 @@ console.log("File uploaded to "+"\x1b[32m"+code+"\x1b[37m" +" Type: " + type)
122122 } ) ;
123123
124124 } else if ( String ( req . url ) . startsWith ( "/download/" ) ) {
125- //log(String(req.url).replace("/download/",""))
126- let pathh = ( String ( req . url ) . replace ( "/download/" , "" ) )
127- pathh = "./data/keys/" + pathh + ".type"
128- fs . readFile ( "./data/keys/" + String ( req . url ) . replace ( "/download/" , "" ) , function ( err , data ) {
125+ let number = String ( req . url ) . replace ( "/download/" , "" )
126+ let filepath = new RegExp ( number + "\.upload\." + "*" )
127+ let defpath = "undefined"
128+ let files = fs . readdirSync ( "static" )
129+ console . log ( filepath )
130+ for ( file in files ) {
131+ console . log ( files [ file ] )
132+
133+ if ( String ( files [ file ] ) . match ( filepath ) ) {
134+ defpath = String ( files [ file ] )
135+ console . log ( defpath )
136+ }
137+ }
138+ fs . readFile ( defpath , function ( err , data ) {
129139 if ( err ) {
130-
131- if ( err . code == "ENOENT" ) {
132-
133- fs . readFile ( "templates/404.html" , function ( err , data ) {
134- if ( err ) {
135- res . writeHead ( 203 ) ;
136- res . end ( "<html><body><b>internal error</b></body></html>" + JSON . stringify ( err ) ) ;
137- return ;
138- }
139-
140+ if ( err . code == "ENOENT" ) {
140141 res . writeHead ( 404 ) ;
141142 res . end ( data ) ;
142143 return ;
143- } )
144- return ;
145- }
146-
144+ }
147145 res . writeHead ( 203 ) ;
148146 res . end ( JSON . stringify ( err ) ) ;
149147 return ;
150148 }
151- res . setHeader ( "Content-Type" , pathh )
149+ res . setHeader ( "Content-Type" , "text/plain" )
152150 res . writeHead ( 200 ) ;
153-
154- res . end ( data ) ;
151+ res . end ( defpath ) ;
155152 console . log ( "File downloaded from " + "\x1b[32m" + String ( req . url ) . replace ( "/download/" , "" ) + "\x1b[37m" )
156153 } ) ;
157154 } else {
0 commit comments