format
This commit is contained in:
parent
a71161bf20
commit
6c29e33946
|
@ -23,7 +23,7 @@ $(document).ready(function(){
|
|||
if (percentComplete === 100) {
|
||||
fileReceiver.removeAllListeners('progress');
|
||||
btn.text('Download complete!');
|
||||
btn.attr("disabled", "true");
|
||||
btn.attr('disabled', 'true');
|
||||
// let finished = document.createElement('p');
|
||||
// finished.innerText = 'Your download has finished.';
|
||||
// li.appendChild(finished);
|
||||
|
@ -37,9 +37,12 @@ $(document).ready(function(){
|
|||
}
|
||||
});
|
||||
|
||||
fileReceiver.download()
|
||||
.catch((err) => {
|
||||
$('.title').text('This link has expired or never existed in the first place.');
|
||||
fileReceiver
|
||||
.download()
|
||||
.catch(err => {
|
||||
$('.title').text(
|
||||
'This link has expired or never existed in the first place.'
|
||||
);
|
||||
$('#download-btn').hide();
|
||||
$('#expired-img').show();
|
||||
console.log('The file has expired, or has already been deleted.');
|
||||
|
|
|
@ -20,9 +20,10 @@ class FileReceiver extends EventEmitter {
|
|||
};
|
||||
|
||||
xhr.onload = function(e) {
|
||||
|
||||
if (xhr.status === 404) {
|
||||
reject(new Error('The file has expired, or has already been deleted.'));
|
||||
reject(
|
||||
new Error('The file has expired, or has already been deleted.')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -58,8 +59,7 @@ class FileReceiver extends EventEmitter {
|
|||
true,
|
||||
['encrypt', 'decrypt']
|
||||
)
|
||||
])
|
||||
.then(([fdata, key]) => {
|
||||
]).then(([fdata, key]) => {
|
||||
let salt = this.salt;
|
||||
return Promise.all([
|
||||
window.crypto.subtle.decrypt(
|
||||
|
|
|
@ -2,31 +2,31 @@ const FileSender = require('./fileSender');
|
|||
|
||||
$(document).ready(function() {
|
||||
let copyBtn = $('#copy-btn');
|
||||
copyBtn.attr("disabled", false);
|
||||
copyBtn.html("Copy");
|
||||
copyBtn.attr('disabled', false);
|
||||
copyBtn.html('Copy');
|
||||
$('#page-one').show();
|
||||
$('#file-list').hide();
|
||||
$('#upload-progress').hide();
|
||||
$('#share-link').hide();
|
||||
|
||||
copyBtn.click(() => {
|
||||
console.log("copied");
|
||||
var aux = document.createElement("input");
|
||||
aux.setAttribute("value", $('#link').attr("value"));
|
||||
console.log('copied');
|
||||
var aux = document.createElement('input');
|
||||
aux.setAttribute('value', $('#link').attr('value'));
|
||||
document.body.appendChild(aux);
|
||||
aux.select();
|
||||
document.execCommand("copy");
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(aux);
|
||||
copyBtn.attr("disabled", true);
|
||||
copyBtn.html("Copied!");
|
||||
copyBtn.attr('disabled', true);
|
||||
copyBtn.html('Copied!');
|
||||
});
|
||||
$('.send-new').click(() => {
|
||||
$('#page-one').show();
|
||||
$('#file-list').show();
|
||||
$('#upload-progress').hide();
|
||||
$('#share-link').hide();
|
||||
copyBtn.attr("disabled", false);
|
||||
copyBtn.html("Copy");
|
||||
copyBtn.attr('disabled', false);
|
||||
copyBtn.html('Copy');
|
||||
});
|
||||
|
||||
let onChange = event => {
|
||||
|
@ -60,14 +60,14 @@ $(document).ready(function(){
|
|||
fileSender.upload().then(info => {
|
||||
const url = `${window.location
|
||||
.origin}/download/${info.fileId}/#${info.secretKey}`;
|
||||
$('#link').attr("value", url);
|
||||
$('#link').attr('value', url);
|
||||
link.innerHTML = url;
|
||||
localStorage.setItem(info.fileId, info.deleteToken);
|
||||
let del = document.createElement('td');
|
||||
let btn = document.createElement('button');
|
||||
btn.innerHTML = 'x';
|
||||
btn.classList.add('delete-btn');
|
||||
btn.addEventListener('click', (e) => {
|
||||
btn.addEventListener('click', e => {
|
||||
FileSender.delete(
|
||||
info.fileId,
|
||||
localStorage.getItem(info.fileId)
|
||||
|
|
|
@ -1,54 +1,52 @@
|
|||
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"),
|
||||
const app = express();
|
||||
const redis = require('redis'),
|
||||
client = redis.createClient();
|
||||
|
||||
client.on("error", (err) => {
|
||||
client.on('error', 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", (req, res) => {
|
||||
res.sendFile(path.join(__dirname + "/../public/download.html"));
|
||||
app.get('/download/:id', (req, res) => {
|
||||
res.sendFile(path.join(__dirname + '/../public/download.html'));
|
||||
});
|
||||
|
||||
app.get("/assets/download/:id", (req, res) => {
|
||||
|
||||
app.get('/assets/download/:id', (req, res) => {
|
||||
let id = req.params.id;
|
||||
if (!validateID(id)) {
|
||||
res.send(404);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
client.hget(id, "filename", (err, reply) => { // maybe some expiration logic too
|
||||
client.hget(id, 'filename', (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.setHeader('Content-Disposition', 'attachment; filename=' + reply);
|
||||
res.setHeader('Content-Type', 'application/octet-stream');
|
||||
|
||||
res.download(__dirname + "/../static/" + id, reply, (err) => {
|
||||
res.download(__dirname + '/../static/' + id, reply, err => {
|
||||
if (!err) {
|
||||
client.del(id);
|
||||
fs.unlinkSync(__dirname + "/../static/" + id);
|
||||
fs.unlinkSync(__dirname + '/../static/' + id);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
app.post("/delete/:id", (req, res) => {
|
||||
app.post('/delete/:id', (req, res) => {
|
||||
let id = req.params.id;
|
||||
|
||||
if (!validateID(id)) {
|
||||
|
@ -62,19 +60,18 @@ app.post("/delete/:id", (req, res) => {
|
|||
res.sendStatus(404);
|
||||
}
|
||||
|
||||
client.hget(id, "delete", (err, reply) => {
|
||||
client.hget(id, 'delete', (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", (req, res, next) => {
|
||||
|
||||
app.post('/upload/:id', (req, res, next) => {
|
||||
if (!validateID(req.params.id)) {
|
||||
res.send(404);
|
||||
return;
|
||||
|
@ -82,17 +79,17 @@ app.post("/upload/:id", (req, res, next) => {
|
|||
|
||||
let fstream;
|
||||
req.pipe(req.busboy);
|
||||
req.busboy.on("file", (fieldname, file, filename) => {
|
||||
console.log("Uploading: " + filename);
|
||||
req.busboy.on('file', (fieldname, file, filename) => {
|
||||
console.log('Uploading: ' + filename);
|
||||
|
||||
//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);
|
||||
fstream.on("close", () => {
|
||||
fstream.on('close', () => {
|
||||
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(() => {
|
||||
|
@ -100,16 +97,16 @@ app.post("/upload/:id", (req, res, next) => {
|
|||
// }, 86400000);
|
||||
|
||||
client.expire(id, 86400000);
|
||||
console.log("Upload Finished of " + filename);
|
||||
console.log('Upload Finished of ' + filename);
|
||||
res.send(uuid);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log("Portal app listening on port 3000!")
|
||||
})
|
||||
console.log('Portal app listening on port 3000!');
|
||||
});
|
||||
|
||||
let validateID = (route_id) => {
|
||||
let validateID = route_id => {
|
||||
return route_id.match(/^[0-9a-fA-F]{32}$/) !== null;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue