Merge pull request #262 from aurimasv/snapshot-mimetype
Don't attach snapshots when option is unchecked and no mimeType is supplied
This commit is contained in:
commit
01c7c7f9e1
2 changed files with 27 additions and 5 deletions
|
@ -30,6 +30,8 @@ Zotero.Attachments = new function(){
|
||||||
this.LINK_MODE_LINKED_URL = 3;
|
this.LINK_MODE_LINKED_URL = 3;
|
||||||
this.BASE_PATH_PLACEHOLDER = 'attachments:';
|
this.BASE_PATH_PLACEHOLDER = 'attachments:';
|
||||||
|
|
||||||
|
this.SNAPSHOT_MIMETYPES = ["text/html", "application/xhtml+xml"];
|
||||||
|
|
||||||
this.importFromFile = importFromFile;
|
this.importFromFile = importFromFile;
|
||||||
this.linkFromFile = linkFromFile;
|
this.linkFromFile = linkFromFile;
|
||||||
this.importSnapshotFromFile = importSnapshotFromFile;
|
this.importSnapshotFromFile = importSnapshotFromFile;
|
||||||
|
@ -574,7 +576,7 @@ Zotero.Attachments = new function(){
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mimeType === 'text/html' || mimeType === 'application/xhtml+xml') {
|
if (this.SNAPSHOT_MIMETYPES.indexOf(mimeType) != -1) {
|
||||||
var sync = true;
|
var sync = true;
|
||||||
|
|
||||||
// Load WebPageDump code
|
// Load WebPageDump code
|
||||||
|
|
|
@ -336,10 +336,16 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
// Determine whether to save an attachment
|
// Determine whether to save an attachment
|
||||||
if(attachment.snapshot !== false) {
|
if(attachment.snapshot !== false) {
|
||||||
if(attachment.document
|
if(attachment.document
|
||||||
|| (attachment.mimeType && attachment.mimeType == "text/html")) {
|
|| (attachment.mimeType && Zotero.Attachments.SNAPSHOT_MIMETYPES.indexOf(attachment.mimeType) != -1)) {
|
||||||
if(!Zotero.Prefs.get("automaticSnapshots")) return;
|
if(!Zotero.Prefs.get("automaticSnapshots")) {
|
||||||
|
Zotero.debug("Translate: Automatic snapshots are disabled. Skipping.", 4);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if(!Zotero.Prefs.get("downloadAssociatedFiles")) return;
|
if(!Zotero.Prefs.get("downloadAssociatedFiles")) {
|
||||||
|
Zotero.debug("Translate: File attachments are disabled. Skipping.", 4);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,12 +405,26 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
// Save attachment if snapshot pref enabled or not HTML
|
// Save attachment if snapshot pref enabled or not HTML
|
||||||
// (in which case downloadAssociatedFiles applies)
|
// (in which case downloadAssociatedFiles applies)
|
||||||
} else {
|
} else {
|
||||||
|
if(!attachment.mimeType && attachment.mimeType !== '') {
|
||||||
|
Zotero.debug("Translate: No mimeType specified for a possible snapshot. Trying to determine mimeType.", 4);
|
||||||
|
var me = this;
|
||||||
|
try {
|
||||||
|
Zotero.MIME.getMIMETypeFromURL(attachment.url, function (mimeType, hasNativeHandler) {
|
||||||
|
attachment.mimeType = mimeType || '';
|
||||||
|
me._saveAttachmentDownload(attachment, parentID, attachmentCallback);
|
||||||
|
}, this._cookieSandbox);
|
||||||
|
} catch(e) {
|
||||||
|
Zotero.debug("Translate: Error adding attachment "+attachment.url, 2);
|
||||||
|
attachmentCallback(attachment, false, e);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
var mimeType = (attachment.mimeType ? attachment.mimeType : null);
|
var mimeType = (attachment.mimeType ? attachment.mimeType : null);
|
||||||
var title = (attachment.title ? attachment.title : null);
|
var title = (attachment.title ? attachment.title : null);
|
||||||
|
|
||||||
var fileBaseName = Zotero.Attachments.getFileBaseNameFromItem(parentID);
|
var fileBaseName = Zotero.Attachments.getFileBaseNameFromItem(parentID);
|
||||||
try {
|
try {
|
||||||
Zotero.debug('Importing attachment from URL');
|
Zotero.debug('Translate: Importing attachment from URL', 4);
|
||||||
attachment.linkMode = "imported_url";
|
attachment.linkMode = "imported_url";
|
||||||
Zotero.Attachments.importFromURL(attachment.url, parentID, title,
|
Zotero.Attachments.importFromURL(attachment.url, parentID, title,
|
||||||
fileBaseName, null, mimeType, this._libraryID, function(status, err) {
|
fileBaseName, null, mimeType, this._libraryID, function(status, err) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue