mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-19 11:02:58 +00:00
Merge branch 'master' into develop
This commit is contained in:
commit
5caef507ce
@ -27,6 +27,7 @@ export default class FileHandler {
|
|||||||
confirmTransfer(event) {
|
confirmTransfer(event) {
|
||||||
const validFileTypes = ['png','jpg','jpeg','gif','zip','rar','gzip','pdf','txt','json','doc','docx','csv','js','html','css'];
|
const validFileTypes = ['png','jpg','jpeg','gif','zip','rar','gzip','pdf','txt','json','doc','docx','csv','js','html','css'];
|
||||||
const file = event.target.files && event.target.files[0];
|
const file = event.target.files && event.target.files[0];
|
||||||
|
const fileName = this.sanitizeFileName(file.name);
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
const fileExt = file.name.split('.').pop().toLowerCase();
|
const fileExt = file.name.split('.').pop().toLowerCase();
|
||||||
@ -38,16 +39,16 @@ export default class FileHandler {
|
|||||||
|
|
||||||
// Support for only 1MB
|
// Support for only 1MB
|
||||||
if (file.size > 1000000) {
|
if (file.size > 1000000) {
|
||||||
console.log(file);
|
|
||||||
alert('Max filesize is 1MB.');
|
alert('Max filesize is 1MB.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let fileId = uuid.v4();
|
let fileId = uuid.v4();
|
||||||
|
|
||||||
let confirmMessage = '<span id="transfer-' + fileId + '" class="file-presend-prompt">You are about to send <strong>' + file.name + '</strong> to all participants in this chat. <a class="file-trigger-confirm" onclick="triggerFileTransfer(this);" data-file="' + fileId + '">Confirm</a> | <a class="file-trigger-cancel" onclick="triggerFileDestroy(this)" data-file="' + fileId + '">Cancel</a></span>';
|
let confirmMessage = '<span id="transfer-' + fileId + '" class="file-presend-prompt">You are about to send <strong>' + fileName + '</strong> to all participants in this chat. <a class="file-trigger-confirm" onclick="triggerFileTransfer(this);" data-file="' + fileId + '">Confirm</a> | <a class="file-trigger-cancel" onclick="triggerFileDestroy(this)" data-file="' + fileId + '">Cancel</a></span>';
|
||||||
let fileData = {
|
let fileData = {
|
||||||
id: fileId,
|
id: fileId,
|
||||||
file: file
|
file: file,
|
||||||
|
fileName: fileName
|
||||||
};
|
};
|
||||||
this.localFileQueue.push(fileData);
|
this.localFileQueue.push(fileData);
|
||||||
this.chat.addChatMessage({
|
this.chat.addChatMessage({
|
||||||
@ -78,10 +79,10 @@ export default class FileHandler {
|
|||||||
const base64 = window.btoa(readerEvent.target.result);
|
const base64 = window.btoa(readerEvent.target.result);
|
||||||
const additionalData = {
|
const additionalData = {
|
||||||
fileId: fileId,
|
fileId: fileId,
|
||||||
fileName: file.name
|
fileName: this.sanitizeFileName(file.name)
|
||||||
};
|
};
|
||||||
this.darkwire.encodeMessage(base64, fileType, additionalData).then((socketData) => {
|
this.darkwire.encodeMessage(base64, fileType, additionalData).then((socketData) => {
|
||||||
this.chat.replaceMessage('#transfer-' + fileId, 'Sent <strong>' + file.name + '</strong>');
|
this.chat.replaceMessage('#transfer-' + fileId, 'Sent <strong>' + additionalData.fileName + '</strong>');
|
||||||
this.socket.emit('new message', socketData);
|
this.socket.emit('new message', socketData);
|
||||||
});
|
});
|
||||||
this.resetInput();
|
this.resetInput();
|
||||||
@ -94,7 +95,7 @@ export default class FileHandler {
|
|||||||
const file = _.findWhere(this.localFileQueue, {id: fileId});
|
const file = _.findWhere(this.localFileQueue, {id: fileId});
|
||||||
this.localFileQueue = _.without(this.localFileQueue, file);
|
this.localFileQueue = _.without(this.localFileQueue, file);
|
||||||
this.resetInput();
|
this.resetInput();
|
||||||
return this.chat.replaceMessage('#transfer-' + fileId, 'The file transfer for <strong>' + file.file.name + '</strong> has been canceled.');
|
return this.chat.replaceMessage('#transfer-' + fileId, 'The file transfer for <strong>' + file.fileName + '</strong> has been canceled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
createBlob(base64, fileType) {
|
createBlob(base64, fileType) {
|
||||||
@ -125,6 +126,10 @@ export default class FileHandler {
|
|||||||
return window.URL.createObjectURL(blob);
|
return window.URL.createObjectURL(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sanitizeFileName(str) {
|
||||||
|
return str.replace(/[<>]/ig, '');
|
||||||
|
}
|
||||||
|
|
||||||
listen() {
|
listen() {
|
||||||
// browser API
|
// browser API
|
||||||
document.getElementById('fileInput').addEventListener('change', this.confirmTransfer.bind(this), false);
|
document.getElementById('fileInput').addEventListener('change', this.confirmTransfer.bind(this), false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user