Replace Backbone saveFile
with Attachment.save
This commit is contained in:
parent
9a76d4bcf8
commit
41fe50553f
4 changed files with 45 additions and 80 deletions
|
@ -2,7 +2,6 @@
|
|||
/* global _: false */
|
||||
/* global Backbone: false */
|
||||
/* global filesize: false */
|
||||
/* global moment: false */
|
||||
|
||||
/* global i18n: false */
|
||||
/* global Signal: false */
|
||||
|
@ -103,12 +102,6 @@
|
|||
|
||||
this.remove();
|
||||
},
|
||||
getFileType() {
|
||||
switch (this.model.contentType) {
|
||||
case 'video/quicktime': return 'mov';
|
||||
default: return this.model.contentType.split('/')[1];
|
||||
}
|
||||
},
|
||||
onClick() {
|
||||
if (!this.isImage()) {
|
||||
this.saveFile();
|
||||
|
@ -182,26 +175,11 @@
|
|||
|
||||
return i18n('unnamedFile');
|
||||
},
|
||||
suggestedName() {
|
||||
if (this.model.fileName) {
|
||||
return this.model.fileName;
|
||||
}
|
||||
|
||||
let suggestion = 'signal';
|
||||
if (this.timestamp) {
|
||||
suggestion += moment(this.timestamp).format('-YYYY-MM-DD-HHmmss');
|
||||
}
|
||||
const fileType = this.getFileType();
|
||||
if (fileType) {
|
||||
suggestion += `.${fileType}`;
|
||||
}
|
||||
return suggestion;
|
||||
},
|
||||
saveFile() {
|
||||
const url = window.URL.createObjectURL(this.blob, { type: 'octet/stream' });
|
||||
const a = $('<a>').attr({ href: url, download: this.suggestedName() });
|
||||
a[0].click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
Signal.Types.AttachmentTS.save({
|
||||
attachment: this.model,
|
||||
timestamp: this.timestamp,
|
||||
});
|
||||
},
|
||||
render() {
|
||||
if (!this.isImage()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue