@@ -12,7 +12,8 @@ let fs = require("fs")
1212let log = console . log ;
1313let http = require ( "http" )
1414let crypto = require ( "crypto" )
15- let path = require ( "path" )
15+ let path = require ( "path" ) ;
16+ const { Console } = require ( 'console' ) ;
1617
1718
1819
@@ -51,10 +52,12 @@ const requestListener = function (req, res) {
5152 if ( req . url !== "/favicon.ico" ) {
5253 var ip = req . headers [ 'x-forwarded-for' ] || req . connection . remoteAddress ;
5354
54- log ( String ( new Date ) + ": " + req . method + " => " + String ( req . url ) + " => User IP: " + ip )
55+ let date = String ( new Date ) . split ( "GMT-" ) [ 0 ]
56+ log ( date + " => " + req . method + " => " + String ( req . url ) + " => User IP: " + ip )
5557
5658 }
5759 if ( req . url === "/test" ) {
60+ console . log ( "[TEST PAGE]" )
5861 fs . readFile ( "templates/rick.html" , function ( err , data ) {
5962 if ( err ) {
6063 res . writeHead ( 203 ) ;
@@ -65,6 +68,7 @@ const requestListener = function (req, res) {
6568 res . end ( data ) ;
6669 } ) ;
6770 } else if ( req . url === "/" ) {
71+ console . log ( "[START PAGE]" )
6872 fs . readFile ( "templates/start.html" , function ( err , data ) {
6973 if ( err ) {
7074 res . writeHead ( 203 ) ;
@@ -83,6 +87,7 @@ const requestListener = function (req, res) {
8387 res . end ( data ) ;
8488 } ) ;
8589 } else if ( String ( req . url ) . split ( "?" ) [ 0 ] === "/upload" ) {
90+ console . log ( "[UPLOAD STARTED]" )
8691 //console.log("upload")
8792 let body = "" ;
8893 req . on ( "data" , ( chunk ) => {
@@ -99,18 +104,12 @@ const requestListener = function (req, res) {
99104 let code = intcode
100105 intcode = "./static/" + intcode + ".upload." + ext
101106 fs . writeFileSync ( intcode , body )
102-
103-
104-
105-
106- console . log ( "File uploaded to " + "\x1b[32m" + code + "\x1b[37m" + " Type: " + type )
107-
108- /*})*/ ;
109-
110-
107+ console . log ( "File uploaded to " + "\x1b[32m" + code + "\x1b[37m" + " Type: " + type )
108+ console . log ( "[UPLOAD ENDED]" )
111109 } )
112110
113111 } else if ( req . url . includes ( "/../" ) ) {
112+ console . log [ "BAD REQUEST" ]
114113 fs . readFile ( "templates/500.html" , function ( err , data ) {
115114 if ( err ) {
116115 res . writeHead ( 203 ) ;
@@ -122,24 +121,29 @@ console.log("File uploaded to "+"\x1b[32m"+code+"\x1b[37m" +" Type: " + type)
122121 } ) ;
123122
124123 } else if ( String ( req . url ) . startsWith ( "/download/" ) ) {
124+ console . log ( "[DOWNLOAD STARTED]" )
125125 let number = String ( req . url ) . replace ( "/download/" , "" )
126126 let filepath = new RegExp ( number + "\.upload\." + "*" )
127127 let defpath = "undefined"
128128 let files = fs . readdirSync ( "static" )
129129 console . log ( filepath )
130130 for ( file in files ) {
131- console . log ( files [ file ] )
131+ console . log ( "Testing... => " + files [ file ] )
132132
133133 if ( String ( files [ file ] ) . match ( filepath ) ) {
134134 defpath = String ( files [ file ] )
135- console . log ( defpath )
135+ console . log ( "Definitive path => " + defpath )
136+ break
136137 }
137138 }
138- fs . readFile ( defpath , function ( err , data ) {
139+ fs . readFile ( path . join ( "static" , defpath ) , function ( err , data ) {
140+
139141 if ( err ) {
142+ console . log ( err )
140143 if ( err . code == "ENOENT" ) {
141144 res . writeHead ( 404 ) ;
142145 res . end ( data ) ;
146+ console . log ( "File not found at " + "\x1b[34m" + defpath + "\x1b[37m" )
143147 return ;
144148 }
145149 res . writeHead ( 203 ) ;
@@ -150,15 +154,19 @@ console.log("File uploaded to "+"\x1b[32m"+code+"\x1b[37m" +" Type: " + type)
150154 res . writeHead ( 200 ) ;
151155 res . end ( defpath ) ;
152156 console . log ( "File downloaded from " + "\x1b[32m" + String ( req . url ) . replace ( "/download/" , "" ) + "\x1b[37m" )
157+ console . log ( "[DOWNLOAD ENDED]" )
153158 } ) ;
154159 } else {
155160 fs . readFile ( "static" + req . url , function ( err , data ) {
161+ console . log [ "STATIC FILE" ]
156162 if ( err ) {
157163
158164 if ( err . code == "ENOENT" ) {
159-
165+ console . log ( "[404 ERROR]" )
160166 fs . readFile ( "templates/404.html" , function ( err , data ) {
161167 if ( err ) {
168+ console . log ( "[INTERNAL CRASH]" )
169+ console . log ( err )
162170 res . writeHead ( 203 ) ;
163171 res . end ( "<html><body><b>internal error</b></body></html>" + JSON . stringify ( err ) ) ;
164172 return ;
0 commit comments