Skip to content

Commit d8721fa

Browse files
authored
Merge pull request #12 from J-P-S-O/master
...
2 parents 88c19f2 + 6379b7b commit d8721fa

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

run.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
Code source: https://github.com/J-P-S-O/quickload
3+
THIS CODE IS EXPERIMENTAL AND HAS NO WARRANTS RELATED TO SAFETY AND RELIABILITY.
4+
With love,
5+
- @J-P-S-O (Octopus)
6+
*/
7+
8+
9+
110
let prompt = require("prompt-sync")()
211
let fs = require("fs")
312
let log = console.log;
@@ -65,10 +74,10 @@ const requestListener = function (req, res) {
6574
res.end(data);
6675
});
6776
}else if(String(req.url).split("?")[0]==="/upload"){
68-
console.log("upload")
77+
//console.log("upload")
6978
let body = "";
7079
req.on("data",(chunk)=>{
71-
console.log(String(chunk))
80+
//console.log(String(chunk))
7281
body += chunk
7382

7483
})
@@ -82,8 +91,12 @@ const requestListener = function (req, res) {
8291
fs.readFile(intcode, 'utf8', function(err, data)
8392
{
8493
if (err){ throw err; }
85-
var linesExceptFirst = data.split('\n').slice(3).join('\n');
86-
var lines = linesExceptFirst.split("\n")
94+
var lines = data.split('\n')
95+
var type = lines[2]
96+
type = type.replace("Content-Type: ","")
97+
//log(type)
98+
lines = lines.slice(3).join('\n');
99+
lines = lines.split("\n")
87100
let i = 0
88101
while (i < 6){
89102

@@ -93,6 +106,9 @@ const requestListener = function (req, res) {
93106
lines = lines.join('\n')
94107
//console.log(lines)
95108
fs.writeFileSync(intcode, lines);
109+
fs.writeFileSync(intcode+".type",type)
110+
console.log("File uploaded to "+"\x1b[32m"+intcode.replace("./data/keys/","")+"\x1b[37m" +" Type: " + type)
111+
96112
});
97113
})
98114

@@ -108,8 +124,10 @@ const requestListener = function (req, res) {
108124
});
109125

110126
} 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) {
127+
//log(String(req.url).replace("/download/",""))
128+
let pathh = (String(req.url).replace("/download/",""))
129+
pathh = "./data/keys/" + pathh + ".type"
130+
fs.readFile("./data/keys/" + String(req.url).replace("/download/",""), function (err,data) {
113131
if (err) {
114132

115133
if(err.code=="ENOENT"){
@@ -132,9 +150,11 @@ const requestListener = function (req, res) {
132150
res.end(JSON.stringify(err));
133151
return;
134152
}
135-
153+
res.setHeader("Content-Type", pathh)
136154
res.writeHead(200);
155+
137156
res.end(data);
157+
console.log("File downloaded from "+"\x1b[32m"+String(req.url).replace("/download/","")+"\x1b[37m")
138158
});
139159
}else{
140160
fs.readFile("static" + req.url, function (err,data) {

0 commit comments

Comments
 (0)