Skip to content
Merged

. #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const requestListener = function (req, res) {
let intcode = "" + crypto.randomInt(999999);

if (req.url!=="/favicon.ico") {
log( String(new Date) + ": " + req.method + " => " + String(req.url))
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

log( String(new Date) + ": " + req.method + " => " + String(req.url) + " => User IP: " + ip)

}
if (req.url === "/test"){
Expand Down Expand Up @@ -110,7 +112,8 @@ const requestListener = function (req, res) {
//console.log(lines)
/* fs.writeFileSync(intcode, lines); */
//fs.writeFileSync(intcode+".type",type)
console.log("File uploaded to "+"\x1b[32m"+intcode.replace("./data/keys/","")+"\x1b[37m" +" Type: " + type)

console.log("File uploaded to "+"\x1b[32m"+intcode.replace("./data/keys/","")+"\x1b[37m" +" Type: " /*+ type*/)

/*})*/;

Expand All @@ -128,7 +131,7 @@ console.log("File uploaded to "+"\x1b[32m"+intcode.replace("./data/keys/","")+"\
res.end(data);
});

} else if(String(req.url).startsWith("/download/") && false){
} else if(String(req.url).startsWith("/download/") ){
//log(String(req.url).replace("/download/",""))
let pathh = (String(req.url).replace("/download/",""))
pathh = "./data/keys/" + pathh + ".type"
Expand Down
28 changes: 26 additions & 2 deletions static/start.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
window.onload = function(){
let codeplace = document.getElementById("code")

let upbutton = document.getElementById("upb")
let upbutton = document.getElementById("fileupload")

let dbutton = document.getElementById("downb")
console.log(upbutton)

console.log("Script included.")
upbutton.onclick = function(){
upbutton.onchange = function(e){
var file = upbutton.files[0];

var reader = new FileReader();

reader.onload = function(e) {
console.log(reader.result)
console.log(file.type)
console.log(file.name)
let xhr = new XMLHttpRequest()
xhr.open('POST', '/upload')
xhr.setRequestHeader('Content-Type', file.type);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.send(reader.result)
xhr.onload = () => {
window.alert(xhr.responseText);

}
}

reader.readAsBinaryString(file);




}
dbutton.onclick =function(){
Expand Down
8 changes: 6 additions & 2 deletions templates/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@

<div height = 5%></div>

<input type="text" name="Code" id = "code" size="15"> <button id = "downb">Download file</button></br>
<button id = "upb">Upload file</button>
<input type="text" name="Code" id = "code" size="15">
<button id = "downb">Download file</button></br>

<input type="file" id="fileupload">


<script src = "start.js"></script>


Expand Down