Skip to content

Commit 34debec

Browse files
committed
.
1 parent 6264953 commit 34debec

2 files changed

Lines changed: 29 additions & 23 deletions

File tree

run.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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{

static/start.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ upbutton.onchange = function(e){
3434

3535
}
3636
dbutton.onclick =function(){
37-
window.location = "/download/"+codeplace.value
37+
let xhr = new XMLHttpRequest()
38+
xhr.open('GET', "/download/"+codeplace.value)
39+
40+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
41+
xhr.send()
42+
xhr.onload = () => {
43+
window.location = xhr.responseText;
44+
45+
}
46+
3847
}
3948

4049

0 commit comments

Comments
 (0)