File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ const requestListener = function (req, res) {
9191 i ++
9292 }
9393 lines = lines . join ( '\n' )
94- console . log ( lines )
94+ // console.log(lines)
9595 fs . writeFileSync ( intcode , lines ) ;
9696} ) ;
9797 } )
@@ -107,7 +107,36 @@ const requestListener = function (req, res) {
107107 res . end ( data ) ;
108108 } ) ;
109109
110- } else {
110+ } else if ( String ( req . url ) . startsWith ( "/download/" ) ) {
111+ log ( String ( req . url ) . trim ( "/download/" ) )
112+ fs . readFile ( "./data/keys/" + String ( req . url ) . trimStart ( "/download/" ) , function ( err , data ) {
113+ if ( err ) {
114+
115+ if ( err . code == "ENOENT" ) {
116+
117+ fs . readFile ( "templates/404.html" , function ( err , data ) {
118+ if ( err ) {
119+ res . writeHead ( 203 ) ;
120+ res . end ( "<html><body><b>internal error</b></body></html>" + JSON . stringify ( err ) ) ;
121+ return ;
122+ }
123+
124+ res . writeHead ( 404 ) ;
125+ res . end ( data ) ;
126+ return ;
127+ } )
128+ return ;
129+ }
130+
131+ res . writeHead ( 203 ) ;
132+ res . end ( JSON . stringify ( err ) ) ;
133+ return ;
134+ }
135+
136+ res . writeHead ( 200 ) ;
137+ res . end ( data ) ;
138+ } ) ;
139+ } else {
111140 fs . readFile ( "static" + req . url , function ( err , data ) {
112141 if ( err ) {
113142
Original file line number Diff line number Diff line change 11window . onload = function ( ) {
2+ let codeplace = document . getElementById ( "code" )
23
34//let upbutton = document.getElementById("upb")
45
@@ -9,7 +10,7 @@ console.log("Script included.")
910
1011//}
1112dbutton . onclick = function ( ) {
12-
13+ window . location = "/download/" + codeplace . value
1314}
1415
1516}
Original file line number Diff line number Diff line change 2727
2828 < div height = 5% > </ div >
2929
30- < input type ="text " name ="Code " size ="15 "> < button id = "downb "> Download file</ button > </ br >
30+ < input type ="text " name ="Code " id = " code " size ="15 "> < button id = "downb "> Download file</ button > </ br >
3131 < form action ="/upload " method ="post " enctype ="multipart/form-data ">
3232 < label for ="upload "> File:</ label >
3333 < input type ="file " name ="upload " id ="upload "> < br />
You can’t perform that action at this time.
0 commit comments