added functionality to cancel uploads
This commit is contained in:
parent
b805c78a9a
commit
cc35206ee4
@ -8,6 +8,7 @@ class FileSender extends EventEmitter {
|
|||||||
super();
|
super();
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.iv = window.crypto.getRandomValues(new Uint8Array(12));
|
this.iv = window.crypto.getRandomValues(new Uint8Array(12));
|
||||||
|
this.uploadXHR = new XMLHttpRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
static delete(fileId, token) {
|
static delete(fileId, token) {
|
||||||
@ -35,6 +36,10 @@ class FileSender extends EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancel() {
|
||||||
|
this.uploadXHR.abort();
|
||||||
|
}
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
const self = this;
|
const self = this;
|
||||||
self.emit('loading', true);
|
self.emit('loading', true);
|
||||||
@ -103,7 +108,7 @@ class FileSender extends EventEmitter {
|
|||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('data', blob, file.name);
|
fd.append('data', blob, file.name);
|
||||||
|
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = self.uploadXHR;
|
||||||
|
|
||||||
xhr.upload.addEventListener('progress', e => {
|
xhr.upload.addEventListener('progress', e => {
|
||||||
if (e.lengthComputable) {
|
if (e.lengthComputable) {
|
||||||
|
@ -79,8 +79,7 @@ $(document).ready(function() {
|
|||||||
$('.upload-window').removeClass('ondrag');
|
$('.upload-window').removeClass('ondrag');
|
||||||
$('#page-one').show();
|
$('#page-one').show();
|
||||||
});
|
});
|
||||||
//cancel the upload
|
|
||||||
$('#cancel-upload').click(() => {});
|
|
||||||
// on file upload by browse or drag & drop
|
// on file upload by browse or drag & drop
|
||||||
function onUpload(event) {
|
function onUpload(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -93,6 +92,12 @@ $(document).ready(function() {
|
|||||||
const expiration = 24 * 60 * 60 * 1000; //will eventually come from a field
|
const expiration = 24 * 60 * 60 * 1000; //will eventually come from a field
|
||||||
|
|
||||||
const fileSender = new FileSender(file);
|
const fileSender = new FileSender(file);
|
||||||
|
$('#cancel-upload').click(() => {
|
||||||
|
fileSender.cancel();
|
||||||
|
location.reload();
|
||||||
|
notify('Your upload was cancelled.');
|
||||||
|
});
|
||||||
|
|
||||||
fileSender.on('progress', progress => {
|
fileSender.on('progress', progress => {
|
||||||
$('#page-one').hide();
|
$('#page-one').hide();
|
||||||
$('#upload-error').hide();
|
$('#upload-error').hide();
|
||||||
|
@ -219,6 +219,19 @@ app.post('/upload', (req, res, next) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
req.on('close', err => {
|
||||||
|
storage
|
||||||
|
.forceDelete(newId)
|
||||||
|
.then(err => {
|
||||||
|
if (!err) {
|
||||||
|
log.info('Deleted:', newId);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
log.info('DeleteError:', newId);
|
||||||
|
});
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/__lbheartbeat__', (req, res) => {
|
app.get('/__lbheartbeat__', (req, res) => {
|
||||||
|
@ -234,13 +234,13 @@ function awsDelete(id, delete_token) {
|
|||||||
if (!reply || delete_token !== reply) {
|
if (!reply || delete_token !== reply) {
|
||||||
reject();
|
reject();
|
||||||
} else {
|
} else {
|
||||||
redis_client.del(id);
|
|
||||||
const params = {
|
const params = {
|
||||||
Bucket: conf.s3_bucket,
|
Bucket: conf.s3_bucket,
|
||||||
Key: id
|
Key: id
|
||||||
};
|
};
|
||||||
|
|
||||||
s3.deleteObject(params, function(err, _data) {
|
s3.deleteObject(params, function(err, _data) {
|
||||||
|
redis_client.del(id);
|
||||||
err ? reject(err) : resolve(err);
|
err ? reject(err) : resolve(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -250,13 +250,13 @@ function awsDelete(id, delete_token) {
|
|||||||
|
|
||||||
function awsForceDelete(id) {
|
function awsForceDelete(id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
redis_client.del(id);
|
|
||||||
const params = {
|
const params = {
|
||||||
Bucket: conf.s3_bucket,
|
Bucket: conf.s3_bucket,
|
||||||
Key: id
|
Key: id
|
||||||
};
|
};
|
||||||
|
|
||||||
s3.deleteObject(params, function(err, _data) {
|
s3.deleteObject(params, function(err, _data) {
|
||||||
|
redis_client.del(id);
|
||||||
err ? reject(err) : resolve(err);
|
err ? reject(err) : resolve(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user