some code cleanup, fixed bug with regex in app.js
This commit is contained in:
parent
065f3c2014
commit
76c337836d
3
app.js
3
app.js
|
@ -23,12 +23,13 @@ app.get("/download/:id", function(req, res) {
|
|||
|
||||
app.get("/assets/download/:id", function(req, res) {
|
||||
|
||||
let id = req.params.id;
|
||||
if (!validateID(id)){
|
||||
res.send(404);
|
||||
return;
|
||||
}
|
||||
|
||||
let id = req.params.id;
|
||||
|
||||
client.hget(id, "filename", function(err, reply) { // maybe some expiration logic too
|
||||
if (!reply) {
|
||||
res.sendStatus(404);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
<body>
|
||||
|
||||
<button onclick="download()">DOWNLOAD</button>
|
||||
<p id="downloadProgress"></p>
|
||||
|
||||
<ul id="downloaded_files">
|
||||
</ul>
|
||||
|
|
|
@ -7,10 +7,22 @@ function download() {
|
|||
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) {
|
||||
|
||||
// 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];
|
||||
li.insertBefore(name, li.firstChild);
|
||||
|
||||
if (this.status == 200) {
|
||||
let self = this;
|
||||
var blob = new Blob([this.response]);
|
||||
|
@ -43,20 +55,12 @@ function download() {
|
|||
key,
|
||||
array)
|
||||
.then(function(decrypted){
|
||||
var filename = xhr.getResponseHeader("Content-Disposition").match(/filename="(.+)"/)[1];
|
||||
|
||||
var name = document.createElement("p");
|
||||
name.innerHTML = filename;
|
||||
li.insertBefore(name, li.firstChild);
|
||||
document.getElementById("downloaded_files").appendChild(li);
|
||||
|
||||
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 = filename
|
||||
console.log(xhr.getResponseHeader("Content-Disposition"));
|
||||
a.download = xhr.getResponseHeader("Content-Disposition").match(/filename="(.+)"/)[1];
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
})
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
<input type="file" onchange="onChange(event)" name="fileUploaded" />
|
||||
</form>
|
||||
|
||||
<p id="downloadProgress"></p>
|
||||
|
||||
<ul id="uploaded_files">
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -57,16 +57,7 @@ function onChange(event) {
|
|||
link.innerHTML = "http://localhost:3000/download/" + hex + "/#" + keydata.k;
|
||||
link.setAttribute("href", "http://localhost:3000/download/" + hex + "/#" + keydata.k);
|
||||
|
||||
// if (curr_name) {
|
||||
// localStorage.setItem(file.name, curr_name + "," + hex);
|
||||
// } else {
|
||||
// localStorage.setItem(file.name, hex)
|
||||
// }
|
||||
|
||||
|
||||
|
||||
console.log("Share this link with a friend: http://localhost:3000/download/" + hex + "/#" + keydata.k);
|
||||
alert("Share this link with a friend: http://localhost:3000/download/" + hex + "/#" + keydata.k);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue