added mozlog and file exists route
This commit is contained in:
parent
f9c2eb1ae4
commit
900fe32460
|
@ -1,4 +1,5 @@
|
|||
const FileReceiver = require('./fileReceiver');
|
||||
const $ = require('jquery');
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#send-file').click(() => {
|
||||
|
@ -12,11 +13,6 @@ $(document).ready(function() {
|
|||
let progress = document.createElement('p');
|
||||
let btn = $('#download-btn');
|
||||
|
||||
// li.appendChild(name);
|
||||
// li.appendChild(progress);
|
||||
|
||||
//document.getElementById('downloaded_files').appendChild(li);
|
||||
|
||||
fileReceiver.on('progress', percentComplete => {
|
||||
progress.innerText = `Progress: ${percentComplete}%`;
|
||||
|
||||
|
@ -24,16 +20,6 @@ $(document).ready(function() {
|
|||
fileReceiver.removeAllListeners('progress');
|
||||
btn.text('Download complete!');
|
||||
btn.attr('disabled', 'true');
|
||||
// let finished = document.createElement('p');
|
||||
// finished.innerText = 'Your download has finished.';
|
||||
// li.appendChild(finished);
|
||||
|
||||
// let close = document.createElement('button');
|
||||
// close.innerText = 'Ok';
|
||||
// close.addEventListener('click', () => {
|
||||
// document.getElementById('downloaded_files').removeChild(li);
|
||||
// });
|
||||
// li.appendChild(close);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -46,7 +32,6 @@ $(document).ready(function() {
|
|||
$('#download-btn').hide();
|
||||
$('#expired-img').show();
|
||||
console.log('The file has expired, or has already been deleted.');
|
||||
// document.getElementById('downloaded_files').removeChild(li);
|
||||
return;
|
||||
})
|
||||
.then(([decrypted, fname]) => {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const FileSender = require('./fileSender');
|
||||
const $ = require('jquery');
|
||||
|
||||
$(document).ready(function() {
|
||||
let copyBtn = $('#copy-btn');
|
||||
|
|
|
@ -27,14 +27,12 @@
|
|||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
|
||||
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
|
||||
"dev": true
|
||||
"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=",
|
||||
"dev": true
|
||||
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4="
|
||||
},
|
||||
"anymatch": {
|
||||
"version": "1.3.0",
|
||||
|
@ -343,8 +341,7 @@
|
|||
"chalk": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
|
||||
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
|
||||
"dev": true
|
||||
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg="
|
||||
},
|
||||
"chokidar": {
|
||||
"version": "1.7.0",
|
||||
|
@ -558,6 +555,11 @@
|
|||
"integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=",
|
||||
"dev": true
|
||||
},
|
||||
"dbug": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/dbug/-/dbug-0.4.2.tgz",
|
||||
"integrity": "sha1-MrSzEF6IYQQ6b5rHVdgOVC02WzE="
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz",
|
||||
|
@ -685,8 +687,7 @@
|
|||
"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=",
|
||||
"dev": true
|
||||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
|
||||
},
|
||||
"esutils": {
|
||||
"version": "2.0.2",
|
||||
|
@ -1557,8 +1558,7 @@
|
|||
"has-ansi": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
|
||||
"integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=",
|
||||
"dev": true
|
||||
"integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE="
|
||||
},
|
||||
"hash-base": {
|
||||
"version": "2.0.2",
|
||||
|
@ -1633,6 +1633,11 @@
|
|||
"integrity": "sha1-wDv04BywhtW15azorQr+eInWOMM=",
|
||||
"dev": true
|
||||
},
|
||||
"intel": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/intel/-/intel-1.2.0.tgz",
|
||||
"integrity": "sha1-EdEUfraz9Fgr31M3s31UFYTp5B4="
|
||||
},
|
||||
"ipaddr.js": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.3.0.tgz",
|
||||
|
@ -1750,6 +1755,11 @@
|
|||
"resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz",
|
||||
"integrity": "sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc="
|
||||
},
|
||||
"jquery": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.2.1.tgz",
|
||||
"integrity": "sha1-XE2d5lKvbNCncBVKYxu6ErAVx4c="
|
||||
},
|
||||
"js-tokens": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.1.tgz",
|
||||
|
@ -1841,6 +1851,11 @@
|
|||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
|
||||
},
|
||||
"merge": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/merge/-/merge-1.2.0.tgz",
|
||||
"integrity": "sha1-dTHjnUlJwoGma4xabgJl6LBYlNo="
|
||||
},
|
||||
"merge-descriptors": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
|
||||
|
@ -1927,6 +1942,11 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"mozlog": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/mozlog/-/mozlog-2.1.1.tgz",
|
||||
"integrity": "sha1-JxCOChxQvOMuo3Q4kRiDrjdO77s="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
|
@ -2356,6 +2376,11 @@
|
|||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz",
|
||||
"integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI="
|
||||
},
|
||||
"stack-trace": {
|
||||
"version": "0.0.10",
|
||||
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
|
||||
"integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
|
||||
},
|
||||
"statuses": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz",
|
||||
|
@ -2470,6 +2495,11 @@
|
|||
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
|
||||
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
|
||||
},
|
||||
"strftime": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/strftime/-/strftime-0.10.0.tgz",
|
||||
"integrity": "sha1-s/D6QZKVICpaKJ9ta+n0kJphcZM="
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
|
||||
|
@ -2478,8 +2508,7 @@
|
|||
"strip-ansi": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8="
|
||||
},
|
||||
"subarg": {
|
||||
"version": "1.0.0",
|
||||
|
@ -2490,8 +2519,12 @@
|
|||
"supports-color": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
|
||||
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
|
||||
"dev": true
|
||||
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc="
|
||||
},
|
||||
"symbol": {
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/symbol/-/symbol-0.3.1.tgz",
|
||||
"integrity": "sha1-tvmpANSWpX8CQI8iGYwQndoGMEE="
|
||||
},
|
||||
"syntax-error": {
|
||||
"version": "1.3.0",
|
||||
|
@ -2602,6 +2635,11 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"utcstring": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/utcstring/-/utcstring-0.1.0.tgz",
|
||||
"integrity": "sha1-Qw/VEKt/yVtdWRDJAteYgMIIQ2s="
|
||||
},
|
||||
"util": {
|
||||
"version": "0.10.3",
|
||||
"resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz",
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
"express": "^4.15.3",
|
||||
"express-handlebars": "^3.0.0",
|
||||
"fs-extra": "^3.0.1",
|
||||
"jquery": "^3.2.1",
|
||||
"mozlog": "^2.1.1",
|
||||
"node-fetch": "^1.7.1",
|
||||
"path": "^0.12.7",
|
||||
"redis": "^2.7.1"
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
const conf = require('./config.js');
|
||||
|
||||
let notLocalHost =
|
||||
conf.env === 'production' &&
|
||||
conf.s3_bucket !== 'localhost' &&
|
||||
conf.bitly_key !== 'localhost';
|
||||
|
||||
const mozlog = require('mozlog') ({
|
||||
app: 'FirefoxFileshare',
|
||||
level: notLocalHost ? 'INFO' : 'verbose',
|
||||
fmt: notLocalHost ? 'heka' : 'pretty',
|
||||
debug: !notLocalHost
|
||||
})
|
||||
|
||||
module.exports = mozlog;
|
|
@ -16,6 +16,10 @@ let notLocalHost =
|
|||
conf.s3_bucket !== 'localhost' &&
|
||||
conf.bitly_key !== 'localhost';
|
||||
|
||||
const mozlog = require('./log.js');
|
||||
|
||||
let log = mozlog('portal.server');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
|
||||
|
@ -30,6 +34,13 @@ app.get('/', (req, res) => {
|
|||
res.render('index');
|
||||
});
|
||||
|
||||
app.get('/exists/:id', (req, res) => {
|
||||
let id = req.params.id;
|
||||
storage.exists(id).then(doesExist => {
|
||||
res.sendStatus(doesExist ? 200 : 404);
|
||||
})
|
||||
});
|
||||
|
||||
app.get('/download/:id', (req, res) => {
|
||||
let id = req.params.id;
|
||||
storage.filename(id).then(filename => {
|
||||
|
@ -70,7 +81,7 @@ app.get('/assets/download/:id', (req, res) => {
|
|||
file_stream.on(notLocalHost ? 'finish' : 'close', () => {
|
||||
storage.forceDelete(id).then(err => {
|
||||
if (!err) {
|
||||
console.log('Deleted.');
|
||||
log.info('Deleted:', id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -100,7 +111,7 @@ app.post('/delete/:id', (req, res) => {
|
|||
.delete(id, delete_token)
|
||||
.then(err => {
|
||||
if (!err) {
|
||||
console.log('Deleted.');
|
||||
log.info('Deleted:', id);
|
||||
}
|
||||
})
|
||||
.catch(err => res.sendStatus(404));
|
||||
|
@ -114,7 +125,7 @@ app.post('/upload/:id', (req, res, next) => {
|
|||
|
||||
req.pipe(req.busboy);
|
||||
req.busboy.on('file', (fieldname, file, filename) => {
|
||||
console.log('Uploading: ' + filename);
|
||||
log.info('Uploading:', req.params.id);
|
||||
let url = `${req.protocol}://${req.get('host')}/download/${req.params.id}/`;
|
||||
|
||||
storage.set(req.params.id, file, filename, url).then(linkAndID => {
|
||||
|
@ -124,7 +135,7 @@ app.post('/upload/:id', (req, res, next) => {
|
|||
});
|
||||
|
||||
let server = app.listen(conf.listen_port, () => {
|
||||
console.log(`Portal app listening on port ${conf.listen_port}!`);
|
||||
log.info('startServer:', `Portal app listening on port ${conf.listen_port}!`);
|
||||
});
|
||||
|
||||
let validateID = route_id => {
|
||||
|
|
|
@ -7,26 +7,35 @@ const path = require('path');
|
|||
const fetch = require('node-fetch');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const redis = require('redis');
|
||||
const redis_client = redis.createClient();
|
||||
|
||||
redis_client.on('error', err => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
let notLocalhost =
|
||||
let notLocalHost =
|
||||
conf.env === 'production' &&
|
||||
conf.s3_bucket !== 'localhost' &&
|
||||
conf.bitly_key !== 'localhost';
|
||||
|
||||
if (notLocalhost) {
|
||||
const mozlog = require('./log.js');
|
||||
|
||||
let log = mozlog('portal.storage');
|
||||
|
||||
const redis = require('redis');
|
||||
const redis_client = redis.createClient();
|
||||
|
||||
|
||||
redis_client.on('error', err => {
|
||||
log.info('Redis: ', err);
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (notLocalHost) {
|
||||
module.exports = {
|
||||
filename: filename,
|
||||
length: awsLength,
|
||||
get: awsGet,
|
||||
set: awsSet,
|
||||
delete: awsDelete,
|
||||
forceDelete: awsForceDelete
|
||||
forceDelete: awsForceDelete,
|
||||
exists: awsExists
|
||||
};
|
||||
} else {
|
||||
module.exports = {
|
||||
|
@ -35,7 +44,8 @@ if (notLocalhost) {
|
|||
get: localGet,
|
||||
set: localSet,
|
||||
delete: localDelete,
|
||||
forceDelete: localForceDelete
|
||||
forceDelete: localForceDelete,
|
||||
exists: localExists
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -51,6 +61,14 @@ function filename(id) {
|
|||
});
|
||||
}
|
||||
|
||||
function localExists(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
redis_client.hget(id, 'filename', (rediserr, reply) => {
|
||||
resolve(fs.existsSync(__dirname + '/../static/' + id) && !rediserr)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function localLength(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
|
@ -74,7 +92,7 @@ function localSet(id, file, filename, url) {
|
|||
|
||||
redis_client.hmset([id, 'filename', filename, 'delete', uuid]);
|
||||
redis_client.expire(id, 86400000);
|
||||
console.log('Upload Finished of ' + filename);
|
||||
log.info('localSet:', 'Upload Finished of ' + id);
|
||||
resolve({
|
||||
uuid: uuid,
|
||||
url: url
|
||||
|
@ -105,6 +123,16 @@ function localForceDelete(id) {
|
|||
});
|
||||
}
|
||||
|
||||
function awsExists(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
s3.getObject(params, function(awserr, data) {
|
||||
redis_client.hget(id, 'filename', (rediserr, reply) => {
|
||||
resolve(!awserr && !rediserr);
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function awsLength(id) {
|
||||
let params = {
|
||||
Bucket: conf.s3_bucket,
|
||||
|
@ -140,7 +168,7 @@ function awsSet(id, file, filename, url) {
|
|||
return new Promise((resolve, reject) => {
|
||||
s3.upload(params, function(err, data) {
|
||||
if (err) {
|
||||
console.log(err, err.stack); // an error occurred
|
||||
log.info('awsUploadError:', err.stack); // an error occurred
|
||||
reject();
|
||||
} else {
|
||||
let uuid = crypto.randomBytes(10).toString('hex');
|
||||
|
@ -148,7 +176,7 @@ function awsSet(id, file, filename, url) {
|
|||
redis_client.hmset([id, 'filename', filename, 'delete', uuid]);
|
||||
|
||||
redis_client.expire(id, 86400000);
|
||||
console.log('Upload Finished of ' + filename);
|
||||
log('awsUploadFinish', 'Upload Finished of ' + filename);
|
||||
if (conf.bitly_key) {
|
||||
fetch(
|
||||
'https://api-ssl.bitly.com/v3/shorten?access_token=' +
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Download your file</title>
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="/bundle.js"></script>
|
||||
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css">
|
||||
<link rel="stylesheet" type="text/css" href="/main.css" />
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Firefox Fileshare</title>
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="./bundle.js"></script>
|
||||
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css">
|
||||
<link rel="stylesheet" type="text/css" href="./main.css" />
|
||||
|
|
Loading…
Reference in New Issue