diff --git a/app.js b/app.js
index d7307896..afb1d0ae 100644
--- a/app.js
+++ b/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);
diff --git a/public/download.html b/public/download.html
index 47ac3dbc..bf5686b0 100644
--- a/public/download.html
+++ b/public/download.html
@@ -7,7 +7,6 @@
-
diff --git a/public/download.js b/public/download.js
index f74ab52e..66e595a1 100644
--- a/public/download.js
+++ b/public/download.js
@@ -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();
})
diff --git a/public/index.html b/public/index.html
index f8d8a43c..c6b31826 100644
--- a/public/index.html
+++ b/public/index.html
@@ -11,8 +11,6 @@
-
-
diff --git a/public/upload.js b/public/upload.js
index 36629a79..9e3c8789 100644
--- a/public/upload.js
+++ b/public/upload.js
@@ -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);
})
}
};