diff --git a/.gitignore b/.gitignore index 78bd0f1..c36ec0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ data node_modules -package-lock.json \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f81533a..2b6d428 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "chalk": "^5.0.0", "g": "^2.0.1", "hyperspace": "^3.19.0", + "istextorbinary": "^6.0.0", "prompt-sync": "^4.2.0" } }, @@ -190,6 +191,17 @@ } ] }, + "node_modules/binaryextensions": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/binaryextensions/-/binaryextensions-4.18.0.tgz", + "integrity": "sha512-PQu3Kyv9dM4FnwB7XGj1+HucW+ShvJzJqjuw1JkKVs1mWdwOKVcRjOi+pV9X52A0tNvrPCsPkbFFQb+wE1EAXw==", + "engines": { + "node": ">=0.8" + }, + "funding": { + "url": "https://bevry.me/fund" + } + }, "node_modules/bitfield-rle": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/bitfield-rle/-/bitfield-rle-2.2.1.tgz", @@ -793,6 +805,21 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "node_modules/istextorbinary": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/istextorbinary/-/istextorbinary-6.0.0.tgz", + "integrity": "sha512-4j3UqQCa06GAf6QHlN3giz2EeFU7qc6Q5uB/aY7Gmb3xmLDLepDOtsZqkb4sCfJgFvTbLUinNw0kHgHs8XOHoQ==", + "dependencies": { + "binaryextensions": "^4.18.0", + "textextensions": "^5.14.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://bevry.me/fund" + } + }, "node_modules/k-bucket": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/k-bucket/-/k-bucket-5.1.0.tgz", @@ -1470,6 +1497,17 @@ "node": ">=6" } }, + "node_modules/textextensions": { + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/textextensions/-/textextensions-5.14.0.tgz", + "integrity": "sha512-4cAYwNFNYlIAHBUo7p6zw8POUvWbZor+/R0Tanv+rIhsauEyV9QSrEXL40pI+GfTQxKX8k6Tyw6CmdSDSmASrg==", + "engines": { + "node": ">=0.8" + }, + "funding": { + "url": "https://bevry.me/fund" + } + }, "node_modules/thunky": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/thunky/-/thunky-1.1.0.tgz", @@ -1734,6 +1772,11 @@ "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" }, + "binaryextensions": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/binaryextensions/-/binaryextensions-4.18.0.tgz", + "integrity": "sha512-PQu3Kyv9dM4FnwB7XGj1+HucW+ShvJzJqjuw1JkKVs1mWdwOKVcRjOi+pV9X52A0tNvrPCsPkbFFQb+wE1EAXw==" + }, "bitfield-rle": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/bitfield-rle/-/bitfield-rle-2.2.1.tgz", @@ -2269,6 +2312,15 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "istextorbinary": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/istextorbinary/-/istextorbinary-6.0.0.tgz", + "integrity": "sha512-4j3UqQCa06GAf6QHlN3giz2EeFU7qc6Q5uB/aY7Gmb3xmLDLepDOtsZqkb4sCfJgFvTbLUinNw0kHgHs8XOHoQ==", + "requires": { + "binaryextensions": "^4.18.0", + "textextensions": "^5.14.0" + } + }, "k-bucket": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/k-bucket/-/k-bucket-5.1.0.tgz", @@ -2880,6 +2932,11 @@ } } }, + "textextensions": { + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/textextensions/-/textextensions-5.14.0.tgz", + "integrity": "sha512-4cAYwNFNYlIAHBUo7p6zw8POUvWbZor+/R0Tanv+rIhsauEyV9QSrEXL40pI+GfTQxKX8k6Tyw6CmdSDSmASrg==" + }, "thunky": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/thunky/-/thunky-1.1.0.tgz", diff --git a/package.json b/package.json index 53f778b..47fef68 100644 --- a/package.json +++ b/package.json @@ -1 +1 @@ -{"dependencies":{"-":"^0.0.1","chalk":"^5.0.0","g":"^2.0.1","hyperspace":"^3.19.0","prompt-sync":"^4.2.0"}} \ No newline at end of file +{"dependencies":{"-":"^0.0.1","chalk":"^5.0.0","g":"^2.0.1","hyperspace":"^3.19.0","istextorbinary":"^6.0.0","prompt-sync":"^4.2.0"}} \ No newline at end of file diff --git a/run.js b/run.js index c584acc..0bbc366 100644 --- a/run.js +++ b/run.js @@ -12,7 +12,7 @@ let fs = require("fs") let log = console.log; let http = require("http") let crypto = require("crypto") - +const { isText } = require('istextorbinary') @@ -88,13 +88,14 @@ const requestListener = function (req, res) { intcode = "./data/keys/" + intcode fs.writeFileSync(intcode,body) - fs.readFile(intcode, 'utf8', function(err, data) -{ + + fs.readFile(intcode, 'utf8', function(err, data){ if (err){ throw err; } var lines = data.split('\n') var type = lines[2] type = type.replace("Content-Type: ","") //log(type) + lines = lines.slice(3).join('\n'); lines = lines.split("\n") let i = 0 @@ -105,11 +106,13 @@ const requestListener = function (req, res) { } lines = lines.join('\n') //console.log(lines) - fs.writeFileSync(intcode, 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) + }); + + }) }else if(req.url.includes("/../")) { diff --git a/templates/start.html b/templates/start.html index 3ec0284..413a5c9 100644 --- a/templates/start.html +++ b/templates/start.html @@ -30,7 +30,7 @@