added prettier for js formatting. use 'npm run format'

This commit is contained in:
Danny Coates 2017-06-01 12:41:29 -07:00
parent 0f64dcad85
commit 57461ead7f
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
5 changed files with 754 additions and 224 deletions

122
app.js
View File

@ -1,115 +1,111 @@
const express = require("express")
const busboy = require("connect-busboy");
const path = require("path");
const fs = require("fs-extra");
const bodyParser = require("body-parser");
const crypto = require("crypto");
const express = require('express');
const busboy = require('connect-busboy');
const path = require('path');
const fs = require('fs-extra');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const app = express()
const redis = require("redis"),
client = redis.createClient();
const app = express();
const redis = require('redis'), client = redis.createClient();
client.on("error", function(err) {
client.on('error', function(err) {
console.log(err);
})
});
app.use(busboy());
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "public")));
app.use(express.static(path.join(__dirname, 'public')));
app.get("/download/:id", function(req, res) {
res.sendFile(path.join(__dirname + "/public/download.html"));
app.get('/download/:id', function(req, res) {
res.sendFile(path.join(__dirname + '/public/download.html'));
});
app.get("/assets/download/:id", function(req, res) {
app.get('/assets/download/:id', function(req, res) {
let id = req.params.id;
if (!validateID(id)){
if (!validateID(id)) {
res.send(404);
return;
}
client.hget(id, "filename", function(err, reply) { // maybe some expiration logic too
client.hget(id, 'filename', function(err, reply) {
// maybe some expiration logic too
if (!reply) {
res.sendStatus(404);
} else {
res.setHeader("Content-Disposition", "attachment; filename=" + reply);
res.setHeader("Content-Type", "application/octet-stream");
res.download(__dirname + "/static/" + id, reply, function(err) {
res.setHeader('Content-Disposition', 'attachment; filename=' + reply);
res.setHeader('Content-Type', 'application/octet-stream');
res.download(__dirname + '/static/' + id, reply, function(err) {
if (!err) {
client.del(id);
fs.unlinkSync(__dirname + "/static/" + id);
fs.unlinkSync(__dirname + '/static/' + id);
}
});
}
})
});
});
app.post("/delete/:id", function(req, res) {
app.post('/delete/:id', function(req, res) {
let id = req.params.id;
if (!validateID(id)){
if (!validateID(id)) {
res.send(404);
return;
}
let delete_token = req.body.delete_token;
if (!delete_token){
if (!delete_token) {
res.sendStatus(404);
}
client.hget(id, "delete", function(err, reply) {
client.hget(id, 'delete', function(err, reply) {
if (!reply) {
res.sendStatus(404);
} else {
client.del(id);
fs.unlinkSync(__dirname + "/static/" + id);
fs.unlinkSync(__dirname + '/static/' + id);
res.sendStatus(200);
}
})
});
});
app.post("/upload/:id", function (req, res, next) {
if (!validateID(req.params.id)){
res.send(404);
return;
}
app.post('/upload/:id', function(req, res, next) {
if (!validateID(req.params.id)) {
res.send(404);
return;
}
var fstream;
req.pipe(req.busboy);
req.busboy.on("file", function (fieldname, file, filename) {
console.log("Uploading: " + filename);
var fstream;
req.pipe(req.busboy);
req.busboy.on('file', function(fieldname, file, filename) {
console.log('Uploading: ' + filename);
//Path where image will be uploaded
fstream = fs.createWriteStream(__dirname + "/static/" + req.params.id);
file.pipe(fstream);
fstream.on("close", function () {
let id = req.params.id;
let uuid = crypto.randomBytes(10).toString('hex');
//Path where image will be uploaded
fstream = fs.createWriteStream(__dirname + '/static/' + req.params.id);
file.pipe(fstream);
fstream.on('close', function() {
let id = req.params.id;
let uuid = crypto.randomBytes(10).toString('hex');
client.hmset([id, "filename", filename, "delete", uuid]);
client.hmset([id, 'filename', filename, 'delete', uuid]);
// delete the file off the server in 24 hours
// setTimeout(function() {
// fs.unlinkSync(__dirname + "/static/" + id);
// }, 86400000);
// delete the file off the server in 24 hours
// setTimeout(function() {
// fs.unlinkSync(__dirname + "/static/" + id);
// }, 86400000);
client.expire(id, 86400000);
console.log("Upload Finished of " + filename);
res.send(uuid);
});
client.expire(id, 86400000);
console.log('Upload Finished of ' + filename);
res.send(uuid);
});
});
});
app.listen(3000, function () {
console.log("Portal app listening on port 3000!")
})
app.listen(3000, function() {
console.log('Portal app listening on port 3000!');
});
function validateID(route_id) {
return route_id.match(/^[0-9a-fA-F]{32}$/) !== null;
}
}

506
package-lock.json generated Normal file
View File

@ -0,0 +1,506 @@
{
"name": "portal-alpha",
"version": "1.0.0",
"lockfileVersion": 1,
"dependencies": {
"accepts": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.3.tgz",
"integrity": "sha1-w8p0NJOGSMPg2cHjKN1otiLChMo="
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
},
"ansi-styles": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4="
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"ast-types": {
"version": "0.9.8",
"resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.9.8.tgz",
"integrity": "sha1-bLakC+ujH0nyCSjihDn8FKPasHg="
},
"babel-code-frame": {
"version": "6.22.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.22.0.tgz",
"integrity": "sha1-AnYgvuVnqIwyVhV05/0IAdMxGOQ="
},
"babylon": {
"version": "7.0.0-beta.8",
"resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.8.tgz",
"integrity": "sha1-K9xa42YEFELCfgaMzm8NfAbqmUk="
},
"balanced-match": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-0.4.2.tgz",
"integrity": "sha1-yz8+PHMtwPAe5wtAPzAuYddwmDg="
},
"body-parser": {
"version": "1.17.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.17.2.tgz",
"integrity": "sha1-+IkqvI+eYn1Crtr7yma/WrmRBO4="
},
"brace-expansion": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.7.tgz",
"integrity": "sha1-Pv/DxQ4ABTH7cg6v+A8K6O8jz1k="
},
"busboy": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
"integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM="
},
"bytes": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz",
"integrity": "sha1-fZcZb51br39pNeJZhVSe3SpsIzk="
},
"chalk": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg="
},
"color-convert": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.0.tgz",
"integrity": "sha1-Gsz5fdc5uYO/mU1W/sj5WFNkG3o="
},
"color-name": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.2.tgz",
"integrity": "sha1-XIq3K2S9IhXWF66VWeuxSEdc+Y0="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"connect-busboy": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/connect-busboy/-/connect-busboy-0.0.2.tgz",
"integrity": "sha1-rFyclmchcYheV2xmsr/ZXTuxEJc="
},
"content-disposition": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz",
"integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ="
},
"content-type": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz",
"integrity": "sha1-t9ETrueo3Se9IRM8TcJSnfFyHu0="
},
"cookie": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
},
"cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"debug": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz",
"integrity": "sha1-krrR9tBbu2u6Isyoi80OyJTChh4="
},
"depd": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.0.tgz",
"integrity": "sha1-4b2Cxqq2ztlluXuIsX7T5SjKGMM="
},
"destroy": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"dicer": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
"integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8="
},
"double-ended-queue": {
"version": "2.1.0-0",
"resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz",
"integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"encodeurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz",
"integrity": "sha1-eePVhlU0aQn+bw9Fpd5oEDspTSA="
},
"escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
},
"esutils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz",
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs="
},
"etag": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.0.tgz",
"integrity": "sha1-b2Ma7zNtbEY2K1F2QETOIWvjwFE="
},
"express": {
"version": "4.15.3",
"resolved": "https://registry.npmjs.org/express/-/express-4.15.3.tgz",
"integrity": "sha1-urZdDwOqgMNYQIly/HAPkWlEtmI="
},
"finalhandler": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.3.tgz",
"integrity": "sha1-70fneVDpmXgOhgIqVg4yF+DQzIk="
},
"flow-parser": {
"version": "0.45.0",
"resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.45.0.tgz",
"integrity": "sha1-qinUrifwaqAoF3crug/L7+9+YvA="
},
"forwarded": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz",
"integrity": "sha1-Ge+YdMSuHCl7zweP3mOgm2aoQ2M="
},
"fresh": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz",
"integrity": "sha1-9HTKXmqSRtb9jglTz6m5yAWvp44="
},
"fs-extra": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-3.0.1.tgz",
"integrity": "sha1-N5TzeMWLNC6n27sjCVEJxLO2IpE="
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"get-stdin": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.1.tgz",
"integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g="
},
"glob": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
"integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg="
},
"graceful-fs": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
},
"has-ansi": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
"integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE="
},
"http-errors": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.1.tgz",
"integrity": "sha1-X4uO2YrKVFZWv1cplzh/kEpyIlc="
},
"iconv-lite": {
"version": "0.4.15",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.15.tgz",
"integrity": "sha1-/iZaIYrGpXz+hUkn6dBMGYJe3es="
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk="
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"ipaddr.js": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.3.0.tgz",
"integrity": "sha1-HgOlL9rYOou7KyXL9JmLTP/NPew="
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"jest-matcher-utils": {
"version": "19.0.0",
"resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-19.0.0.tgz",
"integrity": "sha1-Xs2bY1ZdKwAfYfv37Ex/U3lkVk0="
},
"jest-validate": {
"version": "19.0.0",
"resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-19.0.0.tgz",
"integrity": "sha1-jGMYog7P6roLpTeL+7gner3tQXM="
},
"js-tokens": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.1.tgz",
"integrity": "sha1-COnxMkhKLEWjCQfp3E1VZ7fxFNc="
},
"jsonfile": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.0.tgz",
"integrity": "sha1-kufHRE5f/V+jLmqa6LhQNN+DR9A="
},
"leven": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/leven/-/leven-2.1.0.tgz",
"integrity": "sha1-wuep93IJTe6dNCAq6KzORoeHVYA="
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
},
"merge-descriptors": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E="
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
},
"mime": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz",
"integrity": "sha1-EV+eO2s9rylZmDyzjxSaLUDrXVM="
},
"mime-db": {
"version": "1.27.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz",
"integrity": "sha1-gg9XIpa70g7CXtVeW13oaeVDbrE="
},
"mime-types": {
"version": "2.1.15",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz",
"integrity": "sha1-pOv1BkCUVpI3uM9wBGd20J/JKu0="
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA=="
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"negotiator": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
"integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E="
},
"parseurl": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz",
"integrity": "sha1-yKuMkiO6NIiKpkopeyiFO+wY2lY="
},
"path": {
"version": "0.12.7",
"resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz",
"integrity": "sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8="
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"prettier": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.3.1.tgz",
"integrity": "sha1-+g6oS0WsC6beah5M7Nz/kA1WMVE="
},
"pretty-format": {
"version": "19.0.0",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-19.0.0.tgz",
"integrity": "sha1-VlMNMqy5ij+khRxOK503tCBoTIQ=",
"dependencies": {
"ansi-styles": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.0.0.tgz",
"integrity": "sha1-VATpOlRMT+x/BIJil3vr/jFV4ME="
}
}
},
"process": {
"version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
"integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI="
},
"proxy-addr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.4.tgz",
"integrity": "sha1-J+VF9pYKRKYn2bREZ+NcG2tM4vM="
},
"qs": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz",
"integrity": "sha1-E+JtKK1rD/qpExLNO/cI7TUecjM="
},
"range-parser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
"integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4="
},
"raw-body": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.2.0.tgz",
"integrity": "sha1-mUl2z2pQlqQRYoQEkvC9xdbn+5Y="
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk="
},
"redis": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/redis/-/redis-2.7.1.tgz",
"integrity": "sha1-fVb3h1uYsgQQtxU58dh47Vjr9Go="
},
"redis-commands": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.3.1.tgz",
"integrity": "sha1-gdgm9F+pyLIBH0zXoP5ZfSQdRCs="
},
"redis-parser": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz",
"integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs="
},
"send": {
"version": "0.15.3",
"resolved": "https://registry.npmjs.org/send/-/send-0.15.3.tgz",
"integrity": "sha1-UBP5+ZAj31DRvZiSwZ4979HVMwk="
},
"serve-static": {
"version": "1.12.3",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.3.tgz",
"integrity": "sha1-n0uhni8wMMVH+K+ZEHg47DjVseI="
},
"setprototypeof": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz",
"integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ="
},
"statuses": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz",
"integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4="
},
"streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8="
},
"supports-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc="
},
"type-is": {
"version": "1.6.15",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz",
"integrity": "sha1-yrEPtJCeRByChC6v4a1kbIGARBA="
},
"universalify": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.0.tgz",
"integrity": "sha1-nrHEZR3rzGcMyU8adXYjMruWd3g="
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
},
"util": {
"version": "0.10.3",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz",
"integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=",
"dependencies": {
"inherits": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz",
"integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE="
}
}
},
"utils-merge": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz",
"integrity": "sha1-ApT7kiu5N1FTVBxPcJYjHyh8ivg="
},
"vary": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.1.tgz",
"integrity": "sha1-Z1Neu2lMHVIldFeYRmUyP1h+jTc="
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}
}
}

View File

@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "",
"scripts": {
"format": "prettier --single-quote --write 'public/*.js' 'app.js'",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
@ -14,6 +15,7 @@
"express": "^4.15.3",
"fs-extra": "^3.0.1",
"path": "^0.12.7",
"prettier": "^1.3.1",
"redis": "^2.7.1"
}
}

View File

@ -1,26 +1,24 @@
function download() {
var xhr = new XMLHttpRequest();
xhr.open("get", "/assets" + location.pathname.slice(0, -1), true);
xhr.responseType = "blob";
xhr.open('get', '/assets' + location.pathname.slice(0, -1), true);
xhr.responseType = 'blob';
var li = document.createElement("li");
var progress = document.createElement("p");
var li = document.createElement('li');
var progress = document.createElement('p');
li.appendChild(progress);
document.getElementById("downloaded_files").appendChild(li);
xhr.addEventListener("progress", returnBindedLI(li, progress));
xhr.onload = function(e) {
document.getElementById('downloaded_files').appendChild(li);
xhr.addEventListener('progress', returnBindedLI(li, progress));
xhr.onload = function(e) {
// maybe send a separate request before this one to get the filename?
// maybe render the html itself with the filename, since it's generated server side
// after a get request with the unique id
var name = document.createElement("p");
name.innerHTML = xhr.getResponseHeader("Content-Disposition").match(/filename="(.+)"/)[1];
var name = document.createElement('p');
name.innerHTML = xhr
.getResponseHeader('Content-Disposition')
.match(/filename="(.+)"/)[1];
li.insertBefore(name, li.firstChild);
if (this.status == 200) {
@ -33,59 +31,69 @@ function download() {
var array = new Uint8Array(arrayBuffer);
salt = strToIv(location.pathname.slice(10, -1));
window.crypto.subtle.importKey(
"jwk",
{
kty: "oct",
window.crypto.subtle
.importKey(
'jwk',
{
kty: 'oct',
k: location.hash.slice(1),
alg: "A128CBC",
ext: true,
},
{
name: "AES-CBC",
},
true,
["encrypt", "decrypt"])
.then(function(key){
window.crypto.subtle.decrypt(
alg: 'A128CBC',
ext: true
},
{
name: 'AES-CBC'
},
true,
['encrypt', 'decrypt']
)
.then(function(key) {
window.crypto.subtle
.decrypt(
{
name: "AES-CBC",
iv: salt,
name: 'AES-CBC',
iv: salt
},
key,
array)
.then(function(decrypted){
var dataView = new DataView(decrypted);
var blob = new Blob([dataView]);
var downloadUrl = URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = downloadUrl;
a.download = xhr.getResponseHeader("Content-Disposition").match(/filename="(.+)"/)[1];
document.body.appendChild(a);
a.click();
})
.catch(function(err){
alert("This link is either invalid or has expired, or the uploader has deleted the file.");
console.error(err);
});
})
.catch(function(err){
array
)
.then(function(decrypted) {
var dataView = new DataView(decrypted);
var blob = new Blob([dataView]);
var downloadUrl = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = downloadUrl;
a.download = xhr
.getResponseHeader('Content-Disposition')
.match(/filename="(.+)"/)[1];
document.body.appendChild(a);
a.click();
})
.catch(function(err) {
alert(
'This link is either invalid or has expired, or the uploader has deleted the file.'
);
console.error(err);
});
})
.catch(function(err) {
console.error(err);
});
});
};
fileReader.readAsArrayBuffer(blob);
} else {
alert("This link is either invalid or has expired, or the uploader has deleted the file.")
alert(
'This link is either invalid or has expired, or the uploader has deleted the file.'
);
}
};
xhr.send();
}
function ivToStr(iv) {
let hexStr = "";
let hexStr = '';
for (var i in iv) {
if (iv[i] < 16) {
hexStr += "0" + iv[i].toString(16);
hexStr += '0' + iv[i].toString(16);
} else {
hexStr += iv[i].toString(16);
}
@ -97,7 +105,7 @@ function ivToStr(iv) {
function strToIv(str) {
var iv = new Uint8Array(16);
for (var i = 0; i < str.length; i += 2) {
iv[i/2] = parseInt((str.charAt(i) + str.charAt(i + 1)), 16);
iv[i / 2] = parseInt(str.charAt(i) + str.charAt(i + 1), 16);
}
return iv;
@ -105,24 +113,23 @@ function strToIv(str) {
function returnBindedLI(li, progress) {
return function updateProgress(e) {
if (e.lengthComputable) {
var percentComplete = Math.floor((e.loaded / e.total) * 100);
progress.innerHTML = "Progress: " + percentComplete + "%";
}
if (e.lengthComputable) {
var percentComplete = Math.floor(e.loaded / e.total * 100);
progress.innerHTML = 'Progress: ' + percentComplete + '%';
}
if (percentComplete === 100) {
var finished = document.createElement("p");
finished.innerHTML = "Your download has finished.";
li.appendChild(finished);
if (percentComplete === 100) {
var finished = document.createElement('p');
finished.innerHTML = 'Your download has finished.';
li.appendChild(finished);
var close = document.createElement("button");
close.innerHTML = "Ok";
close.addEventListener("click", function() {
document.getElementById("downloaded_files").removeChild(li);
});
var close = document.createElement('button');
close.innerHTML = 'Ok';
close.addEventListener('click', function() {
document.getElementById('downloaded_files').removeChild(li);
});
li.appendChild(close);
}
}
}
li.appendChild(close);
}
};
}

View File

@ -3,85 +3,106 @@ function onChange(event) {
var reader = new FileReader();
reader.onload = function(event) {
let self = this;
window.crypto.subtle.generateKey({
name: "AES-CBC",
length: 128
},
true,
["encrypt", "decrypt"])
.then(function(key){
var arrayBuffer = self.result;
var array = new Uint8Array(arrayBuffer);
window.crypto.subtle
.generateKey(
{
name: 'AES-CBC',
length: 128
},
true,
['encrypt', 'decrypt']
)
.then(function(key) {
var arrayBuffer = self.result;
var array = new Uint8Array(arrayBuffer);
var random_iv = window.crypto.getRandomValues(new Uint8Array(16));
var random_iv = window.crypto.getRandomValues(new Uint8Array(16));
window.crypto.subtle.encrypt({
name: "AES-CBC",
iv: random_iv },
key,
array)
.then(function(encrypted){
var dataView = new DataView(encrypted);
var blob = new Blob([dataView], { type: file.type });
var fd = new FormData();
fd.append("fname", file.name);
fd.append("data", blob, file.name);
window.crypto.subtle
.encrypt(
{
name: 'AES-CBC',
iv: random_iv
},
key,
array
)
.then(function(encrypted) {
var dataView = new DataView(encrypted);
var blob = new Blob([dataView], { type: file.type });
var xhr = new XMLHttpRequest();
var hex = ivToStr(random_iv);
xhr.open("post", "/upload/" + hex, true);
var fd = new FormData();
fd.append('fname', file.name);
fd.append('data', blob, file.name);
var li = document.createElement("li");
var name = document.createElement("p");
name.innerHTML = file.name;
li.appendChild(name);
var link = document.createElement("a");
li.appendChild(link);
var xhr = new XMLHttpRequest();
var hex = ivToStr(random_iv);
xhr.open('post', '/upload/' + hex, true);
var progress = document.createElement("p");
li.appendChild(progress);
document.getElementById("uploaded_files").appendChild(li);
var li = document.createElement('li');
var name = document.createElement('p');
name.innerHTML = file.name;
li.appendChild(name);
var link = document.createElement('a');
li.appendChild(link);
xhr.upload.addEventListener("progress", returnBindedLI(progress, name, link, li));
var progress = document.createElement('p');
li.appendChild(progress);
document.getElementById('uploaded_files').appendChild(li);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
window.crypto.subtle.exportKey("jwk", key).then(function(keydata) {
var curr_name = localStorage.getItem(file.name);
localStorage.setItem(hex, xhr.responseText);
xhr.upload.addEventListener(
'progress',
returnBindedLI(progress, name, link, li)
);
link.innerHTML = "http://localhost:3000/download/" + hex + "/#" + keydata.k;
link.setAttribute("href", "http://localhost:3000/download/" + hex + "/#" + keydata.k);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
window.crypto.subtle
.exportKey('jwk', key)
.then(function(keydata) {
var curr_name = localStorage.getItem(file.name);
console.log("Share this link with a friend: http://localhost:3000/download/" + hex + "/#" + keydata.k);
})
}
};
localStorage.setItem(hex, xhr.responseText);
xhr.send(fd);
})
.catch(function(err){
console.error(err);
});
link.innerHTML =
'http://localhost:3000/download/' +
hex +
'/#' +
keydata.k;
link.setAttribute(
'href',
'http://localhost:3000/download/' + hex + '/#' + keydata.k
);
console.log(
'Share this link with a friend: http://localhost:3000/download/' +
hex +
'/#' +
keydata.k
);
});
}
};
xhr.send(fd);
})
.catch(function(err) {
console.error(err);
});
})
.catch(function(err){
.catch(function(err) {
console.error(err);
});
});
};
reader.readAsArrayBuffer(file);
}
function ivToStr(iv) {
let hexStr = "";
let hexStr = '';
for (var i in iv) {
if (iv[i] < 16) {
hexStr += "0" + iv[i].toString(16);
hexStr += '0' + iv[i].toString(16);
} else {
hexStr += iv[i].toString(16);
}
@ -93,7 +114,7 @@ function ivToStr(iv) {
function strToIv(str) {
var iv = new Uint8Array(16);
for (var i = 0; i < str.length; i += 2) {
iv[i/2] = parseInt((str.charAt(i) + str.charAt(i + 1)), 16);
iv[i / 2] = parseInt(str.charAt(i) + str.charAt(i + 1), 16);
}
return iv;
@ -101,41 +122,39 @@ function strToIv(str) {
function returnBindedLI(a_element, name, link, li) {
return function updateProgress(e) {
if (e.lengthComputable) {
var percentComplete = Math.floor((e.loaded / e.total) * 100);
a_element.innerHTML = "Progress: " + percentComplete + "%";
if (e.lengthComputable) {
var percentComplete = Math.floor(e.loaded / e.total * 100);
a_element.innerHTML = 'Progress: ' + percentComplete + '%';
if (percentComplete === 100) {
var btn = document.createElement("button");
btn.innerHTML = "Delete from server";
btn.addEventListener("click", function() {
var segments = link.innerHTML.split("/");
var key = segments[segments.length - 2];
if (percentComplete === 100) {
var btn = document.createElement('button');
btn.innerHTML = 'Delete from server';
btn.addEventListener('click', function() {
var segments = link.innerHTML.split('/');
var key = segments[segments.length - 2];
var xhr = new XMLHttpRequest();
xhr.open("post", "/delete/" + key, true);
xhr.setRequestHeader("Content-Type", "application/json");
if (!localStorage.getItem(key)) return;
var xhr = new XMLHttpRequest();
xhr.open('post', '/delete/' + key, true);
xhr.setRequestHeader('Content-Type', 'application/json');
if (!localStorage.getItem(key)) return;
xhr.send(JSON.stringify({delete_token: localStorage.getItem(key)}));
xhr.send(JSON.stringify({ delete_token: localStorage.getItem(key) }));
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
document.getElementById("uploaded_files").removeChild(li);
localStorage.removeItem(key);
}
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
document.getElementById('uploaded_files').removeChild(li);
localStorage.removeItem(key);
}
if (xhr.status === 200) {
console.log("The file was successfully deleted.");
} else {
console.log("The file has expired, or has already been deleted.");
}
}
});
li.appendChild(btn);
}
}
}
if (xhr.status === 200) {
console.log('The file was successfully deleted.');
} else {
console.log('The file has expired, or has already been deleted.');
}
};
});
li.appendChild(btn);
}
}
};
}