Permalink
Browse files

upload

  • Loading branch information...
tdjsnelling committed Jan 29, 2018
0 parents commit 370bf23a7fa0edcd1508cf8bf312067b2936a593
Showing with 92 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 README.md
  3. +63 −0 index.js
  4. +11 −0 package.json
  5. +13 −0 public/index.txt
@@ -0,0 +1,2 @@
node_modules/
uploads/
@@ -0,0 +1,3 @@
# 0x1.host
a nodejs clone of https://0x0.st
@@ -0,0 +1,63 @@
var path = require('path');
var express = require('express');
var app = express();
var multer = require('multer');
var mime = require('mime-types');
var crypto = require('crypto');
var fs = require('fs');
var port = 8000;
var maxFileSize = 2.56e8;
var doNotAllow = ['applicaton/x-dosexec', 'application/x-msdos-program'];
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads')
},
filename: function (req, file, cb) {
var mimeType = mime.lookup(file.originalname);
var hInfo = file.originalname + mimeType + file.size;
var hName = crypto.createHmac('sha256', hInfo).digest('hex').substring(0, 8);
cb(null, hName + '.' + mime.extension(mimeType));
}
});
function fileFilter(req, file, cb) {
var mimeType = mime.lookup(file.originalname);
if (doNotAllow.indexOf(mimeType) != -1) {
cb(null, false);
}
else {
cb(null, true);
}
}
var upload = multer({ limits: { fileSize: maxFileSize }, storage: storage, fileFilter: fileFilter });
app.use(express.urlencoded());
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/public', 'index.txt'));
});
app.post('/', upload.single('file'), (req, res) => {
if (req.file) {
res.send(req.file.filename + '\n');
}
else {
res.sendStatus(400);
}
});
app.get('/:fileId', (req, res) => {
var fileToSend = path.join(__dirname, '/uploads', req.params.fileId);
if (fs.existsSync(fileToSend)) {
res.sendFile(fileToSend);
}
else {
res.sendStatus(404);
}
});
app.listen(port, () => { console.log('listening on port ' + port) });
@@ -0,0 +1,11 @@
{
"name": "0x1",
"version": "1.0.0",
"description": "a nodejs clone of https://0x0.st",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Tom Snelling @tdjsnelling",
"license": "MIT"
}
@@ -0,0 +1,13 @@
0x1.host
========
a nodejs clone of https://0x0.st
upload:
curl -F file=@yourfile.txt https://0x1.host
max file size:
256MB
not allowed:
'applicaton/x-dosexec', 'application/x-msdos-program'

0 comments on commit 370bf23

Please sign in to comment.