Merge pull request #36 from mozilla/prettier

added prettier for js formatting
This commit is contained in:
Danny Coates 2017-06-01 12:48:36 -07:00 committed by GitHub
commit e3611ded17
5 changed files with 754 additions and 224 deletions

82
app.js
View File

@ -1,98 +1,94 @@
const express = require("express") const express = require('express');
const busboy = require("connect-busboy"); const busboy = require('connect-busboy');
const path = require("path"); const path = require('path');
const fs = require("fs-extra"); const fs = require('fs-extra');
const bodyParser = require("body-parser"); const bodyParser = require('body-parser');
const crypto = require("crypto"); const crypto = require('crypto');
const app = express() const app = express();
const redis = require("redis"), const redis = require('redis'), client = redis.createClient();
client = redis.createClient();
client.on("error", function(err) { client.on('error', function(err) {
console.log(err); console.log(err);
}) });
app.use(busboy()); app.use(busboy());
app.use(bodyParser.json()); 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) { app.get('/download/:id', function(req, res) {
res.sendFile(path.join(__dirname + "/public/download.html")); 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; let id = req.params.id;
if (!validateID(id)){ if (!validateID(id)) {
res.send(404); res.send(404);
return; return;
} }
client.hget(id, 'filename', function(err, reply) {
client.hget(id, "filename", function(err, reply) { // maybe some expiration logic too // maybe some expiration logic too
if (!reply) { if (!reply) {
res.sendStatus(404); res.sendStatus(404);
} else { } else {
res.setHeader("Content-Disposition", "attachment; filename=" + reply); res.setHeader('Content-Disposition', 'attachment; filename=' + reply);
res.setHeader("Content-Type", "application/octet-stream"); res.setHeader('Content-Type', 'application/octet-stream');
res.download(__dirname + "/static/" + id, reply, function(err) { res.download(__dirname + '/static/' + id, reply, function(err) {
if (!err) { if (!err) {
client.del(id); 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; let id = req.params.id;
if (!validateID(id)){ if (!validateID(id)) {
res.send(404); res.send(404);
return; return;
} }
let delete_token = req.body.delete_token; let delete_token = req.body.delete_token;
if (!delete_token){ if (!delete_token) {
res.sendStatus(404); res.sendStatus(404);
} }
client.hget(id, "delete", function(err, reply) { client.hget(id, 'delete', function(err, reply) {
if (!reply) { if (!reply) {
res.sendStatus(404); res.sendStatus(404);
} else { } else {
client.del(id); client.del(id);
fs.unlinkSync(__dirname + "/static/" + id); fs.unlinkSync(__dirname + '/static/' + id);
res.sendStatus(200); res.sendStatus(200);
} }
}) });
}); });
app.post("/upload/:id", function (req, res, next) { app.post('/upload/:id', function(req, res, next) {
if (!validateID(req.params.id)) {
if (!validateID(req.params.id)){
res.send(404); res.send(404);
return; return;
} }
var fstream; var fstream;
req.pipe(req.busboy); req.pipe(req.busboy);
req.busboy.on("file", function (fieldname, file, filename) { req.busboy.on('file', function(fieldname, file, filename) {
console.log("Uploading: " + filename); console.log('Uploading: ' + filename);
//Path where image will be uploaded //Path where image will be uploaded
fstream = fs.createWriteStream(__dirname + "/static/" + req.params.id); fstream = fs.createWriteStream(__dirname + '/static/' + req.params.id);
file.pipe(fstream); file.pipe(fstream);
fstream.on("close", function () { fstream.on('close', function() {
let id = req.params.id; let id = req.params.id;
let uuid = crypto.randomBytes(10).toString('hex'); 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 // delete the file off the server in 24 hours
// setTimeout(function() { // setTimeout(function() {
@ -100,15 +96,15 @@ app.post("/upload/:id", function (req, res, next) {
// }, 86400000); // }, 86400000);
client.expire(id, 86400000); client.expire(id, 86400000);
console.log("Upload Finished of " + filename); console.log('Upload Finished of ' + filename);
res.send(uuid); res.send(uuid);
}); });
}); });
}); });
app.listen(3000, function () { app.listen(3000, function() {
console.log("Portal app listening on port 3000!") console.log('Portal app listening on port 3000!');
}) });
function validateID(route_id) { function validateID(route_id) {
return route_id.match(/^[0-9a-fA-F]{32}$/) !== null; 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", "version": "1.0.0",
"description": "", "description": "",
"scripts": { "scripts": {
"format": "prettier --single-quote --write 'public/*.js' 'app.js'",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js" "start": "node app.js"
}, },
@ -14,6 +15,7 @@
"express": "^4.15.3", "express": "^4.15.3",
"fs-extra": "^3.0.1", "fs-extra": "^3.0.1",
"path": "^0.12.7", "path": "^0.12.7",
"prettier": "^1.3.1",
"redis": "^2.7.1" "redis": "^2.7.1"
} }
} }

View File

@ -1,26 +1,24 @@
function download() { function download() {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("get", "/assets" + location.pathname.slice(0, -1), true); xhr.open('get', '/assets' + location.pathname.slice(0, -1), true);
xhr.responseType = "blob"; xhr.responseType = 'blob';
var li = document.createElement("li"); var li = document.createElement('li');
var progress = document.createElement("p"); var progress = document.createElement('p');
li.appendChild(progress); li.appendChild(progress);
document.getElementById("downloaded_files").appendChild(li); document.getElementById('downloaded_files').appendChild(li);
xhr.addEventListener("progress", returnBindedLI(li, progress));
xhr.addEventListener('progress', returnBindedLI(li, progress));
xhr.onload = function(e) { xhr.onload = function(e) {
// maybe send a separate request before this one to get the filename? // 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 // maybe render the html itself with the filename, since it's generated server side
// after a get request with the unique id // after a get request with the unique id
var name = document.createElement("p"); var name = document.createElement('p');
name.innerHTML = xhr.getResponseHeader("Content-Disposition").match(/filename="(.+)"/)[1]; name.innerHTML = xhr
.getResponseHeader('Content-Disposition')
.match(/filename="(.+)"/)[1];
li.insertBefore(name, li.firstChild); li.insertBefore(name, li.firstChild);
if (this.status == 200) { if (this.status == 200) {
@ -33,59 +31,69 @@ function download() {
var array = new Uint8Array(arrayBuffer); var array = new Uint8Array(arrayBuffer);
salt = strToIv(location.pathname.slice(10, -1)); salt = strToIv(location.pathname.slice(10, -1));
window.crypto.subtle.importKey( window.crypto.subtle
"jwk", .importKey(
'jwk',
{ {
kty: "oct", kty: 'oct',
k: location.hash.slice(1), k: location.hash.slice(1),
alg: "A128CBC", alg: 'A128CBC',
ext: true, ext: true
}, },
{ {
name: "AES-CBC", name: 'AES-CBC'
}, },
true, true,
["encrypt", "decrypt"]) ['encrypt', 'decrypt']
.then(function(key){ )
window.crypto.subtle.decrypt( .then(function(key) {
window.crypto.subtle
.decrypt(
{ {
name: "AES-CBC", name: 'AES-CBC',
iv: salt, iv: salt
}, },
key, key,
array) array
.then(function(decrypted){ )
.then(function(decrypted) {
var dataView = new DataView(decrypted); var dataView = new DataView(decrypted);
var blob = new Blob([dataView]); var blob = new Blob([dataView]);
var downloadUrl = URL.createObjectURL(blob); var downloadUrl = URL.createObjectURL(blob);
var a = document.createElement("a"); var a = document.createElement('a');
a.href = downloadUrl; a.href = downloadUrl;
a.download = xhr.getResponseHeader("Content-Disposition").match(/filename="(.+)"/)[1]; a.download = xhr
.getResponseHeader('Content-Disposition')
.match(/filename="(.+)"/)[1];
document.body.appendChild(a); document.body.appendChild(a);
a.click(); a.click();
}) })
.catch(function(err){ .catch(function(err) {
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.'
);
console.error(err); console.error(err);
}); });
}) })
.catch(function(err){ .catch(function(err) {
console.error(err); console.error(err);
}); });
}; };
fileReader.readAsArrayBuffer(blob); fileReader.readAsArrayBuffer(blob);
} else { } 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(); xhr.send();
} }
function ivToStr(iv) { function ivToStr(iv) {
let hexStr = ""; let hexStr = '';
for (var i in iv) { for (var i in iv) {
if (iv[i] < 16) { if (iv[i] < 16) {
hexStr += "0" + iv[i].toString(16); hexStr += '0' + iv[i].toString(16);
} else { } else {
hexStr += iv[i].toString(16); hexStr += iv[i].toString(16);
} }
@ -97,7 +105,7 @@ function ivToStr(iv) {
function strToIv(str) { function strToIv(str) {
var iv = new Uint8Array(16); var iv = new Uint8Array(16);
for (var i = 0; i < str.length; i += 2) { 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; return iv;
@ -106,23 +114,22 @@ function strToIv(str) {
function returnBindedLI(li, progress) { function returnBindedLI(li, progress) {
return function updateProgress(e) { return function updateProgress(e) {
if (e.lengthComputable) { if (e.lengthComputable) {
var percentComplete = Math.floor((e.loaded / e.total) * 100); var percentComplete = Math.floor(e.loaded / e.total * 100);
progress.innerHTML = "Progress: " + percentComplete + "%"; progress.innerHTML = 'Progress: ' + percentComplete + '%';
} }
if (percentComplete === 100) { if (percentComplete === 100) {
var finished = document.createElement("p"); var finished = document.createElement('p');
finished.innerHTML = "Your download has finished."; finished.innerHTML = 'Your download has finished.';
li.appendChild(finished); li.appendChild(finished);
var close = document.createElement("button"); var close = document.createElement('button');
close.innerHTML = "Ok"; close.innerHTML = 'Ok';
close.addEventListener("click", function() { close.addEventListener('click', function() {
document.getElementById("downloaded_files").removeChild(li); 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(); var reader = new FileReader();
reader.onload = function(event) { reader.onload = function(event) {
let self = this; let self = this;
window.crypto.subtle.generateKey({ window.crypto.subtle
name: "AES-CBC", .generateKey(
{
name: 'AES-CBC',
length: 128 length: 128
}, },
true, true,
["encrypt", "decrypt"]) ['encrypt', 'decrypt']
.then(function(key){ )
.then(function(key) {
var arrayBuffer = self.result; var arrayBuffer = self.result;
var array = new Uint8Array(arrayBuffer); 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({ window.crypto.subtle
name: "AES-CBC", .encrypt(
iv: random_iv }, {
name: 'AES-CBC',
iv: random_iv
},
key, key,
array) array
.then(function(encrypted){ )
.then(function(encrypted) {
var dataView = new DataView(encrypted); var dataView = new DataView(encrypted);
var blob = new Blob([dataView], { type: file.type }); var blob = new Blob([dataView], { type: file.type });
var fd = new FormData(); var fd = new FormData();
fd.append("fname", file.name); fd.append('fname', file.name);
fd.append("data", blob, file.name); fd.append('data', blob, file.name);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
var hex = ivToStr(random_iv); var hex = ivToStr(random_iv);
xhr.open("post", "/upload/" + hex, true); xhr.open('post', '/upload/' + hex, true);
var li = document.createElement("li"); var li = document.createElement('li');
var name = document.createElement("p"); var name = document.createElement('p');
name.innerHTML = file.name; name.innerHTML = file.name;
li.appendChild(name); li.appendChild(name);
var link = document.createElement("a"); var link = document.createElement('a');
li.appendChild(link); li.appendChild(link);
var progress = document.createElement("p"); var progress = document.createElement('p');
li.appendChild(progress); li.appendChild(progress);
document.getElementById("uploaded_files").appendChild(li); document.getElementById('uploaded_files').appendChild(li);
xhr.upload.addEventListener(
xhr.upload.addEventListener("progress", returnBindedLI(progress, name, link, li)); 'progress',
returnBindedLI(progress, name, link, li)
);
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) { if (xhr.readyState == XMLHttpRequest.DONE) {
window.crypto.subtle.exportKey("jwk", key).then(function(keydata) { window.crypto.subtle
.exportKey('jwk', key)
.then(function(keydata) {
var curr_name = localStorage.getItem(file.name); var curr_name = localStorage.getItem(file.name);
localStorage.setItem(hex, xhr.responseText); localStorage.setItem(hex, xhr.responseText);
link.innerHTML = "http://localhost:3000/download/" + hex + "/#" + keydata.k; link.innerHTML =
link.setAttribute("href", "http://localhost:3000/download/" + hex + "/#" + keydata.k); '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); console.log(
}) 'Share this link with a friend: http://localhost:3000/download/' +
hex +
'/#' +
keydata.k
);
});
} }
}; };
xhr.send(fd); xhr.send(fd);
}) })
.catch(function(err){ .catch(function(err) {
console.error(err); console.error(err);
}); });
}) })
.catch(function(err){ .catch(function(err) {
console.error(err); console.error(err);
}); });
}; };
reader.readAsArrayBuffer(file); reader.readAsArrayBuffer(file);
} }
function ivToStr(iv) { function ivToStr(iv) {
let hexStr = ""; let hexStr = '';
for (var i in iv) { for (var i in iv) {
if (iv[i] < 16) { if (iv[i] < 16) {
hexStr += "0" + iv[i].toString(16); hexStr += '0' + iv[i].toString(16);
} else { } else {
hexStr += iv[i].toString(16); hexStr += iv[i].toString(16);
} }
@ -93,7 +114,7 @@ function ivToStr(iv) {
function strToIv(str) { function strToIv(str) {
var iv = new Uint8Array(16); var iv = new Uint8Array(16);
for (var i = 0; i < str.length; i += 2) { 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; return iv;
@ -102,40 +123,38 @@ function strToIv(str) {
function returnBindedLI(a_element, name, link, li) { function returnBindedLI(a_element, name, link, li) {
return function updateProgress(e) { return function updateProgress(e) {
if (e.lengthComputable) { if (e.lengthComputable) {
var percentComplete = Math.floor((e.loaded / e.total) * 100); var percentComplete = Math.floor(e.loaded / e.total * 100);
a_element.innerHTML = "Progress: " + percentComplete + "%"; a_element.innerHTML = 'Progress: ' + percentComplete + '%';
if (percentComplete === 100) { if (percentComplete === 100) {
var btn = document.createElement("button"); var btn = document.createElement('button');
btn.innerHTML = "Delete from server"; btn.innerHTML = 'Delete from server';
btn.addEventListener("click", function() { btn.addEventListener('click', function() {
var segments = link.innerHTML.split("/"); var segments = link.innerHTML.split('/');
var key = segments[segments.length - 2]; var key = segments[segments.length - 2];
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("post", "/delete/" + key, true); xhr.open('post', '/delete/' + key, true);
xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader('Content-Type', 'application/json');
if (!localStorage.getItem(key)) return; 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() { xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.readyState === XMLHttpRequest.DONE) {
document.getElementById("uploaded_files").removeChild(li); document.getElementById('uploaded_files').removeChild(li);
localStorage.removeItem(key); localStorage.removeItem(key);
} }
if (xhr.status === 200) { if (xhr.status === 200) {
console.log("The file was successfully deleted."); console.log('The file was successfully deleted.');
} else { } else {
console.log("The file has expired, or has already been deleted."); console.log('The file has expired, or has already been deleted.');
} }
} };
}); });
li.appendChild(btn); li.appendChild(btn);
} }
} }
} };
} }