From d1b2567663ef4a6d2d6ab207f9e4e67065901386 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 3 Apr 2007 06:59:33 +0000 Subject: [PATCH] - Fix missing file extension when using importFromDocument() on a non-HTML file - Fix PDF indexing for importFromDocument() files (Reverted to using saveURI() rather than WebPageDump for non-HTML files in Attachments.importFromDocument(), since custom filename logic was being lost and it was just calling saveURI() itself anyway) --- chrome/content/zotero/xpcom/attachments.js | 57 +++++++++++++++++----- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index af8c38a041..2c3181369a 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -451,20 +451,35 @@ Zotero.Attachments = new function(){ file.initWithFile(destDir); var fileName = _getFileNameFromURL(url, mimeType); - file.append(fileName); - // Load WebPageDump code - Components.classes["@mozilla.org/moz/jssubscript-loader;1"] - .getService(Components.interfaces.mozIJSSubScriptLoader) - .loadSubScript("chrome://zotero/content/webpagedump/common.js"); + if (mimeType == 'text/html') { + // Load WebPageDump code + Components.classes["@mozilla.org/moz/jssubscript-loader;1"] + .getService(Components.interfaces.mozIJSSubScriptLoader) + .loadSubScript("chrome://zotero/content/webpagedump/common.js"); + + Components.classes["@mozilla.org/moz/jssubscript-loader;1"] + .getService(Components.interfaces.mozIJSSubScriptLoader) + .loadSubScript("chrome://zotero/content/webpagedump/domsaver.js"); + + wpdDOMSaver.init(file.path, document) + wpdDOMSaver.saveHTMLDocument() + } + else { + Zotero.debug('Saving with saveURI()'); + const nsIWBP = Components.interfaces.nsIWebBrowserPersist; + var wbp = Components + .classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] + .createInstance(nsIWBP); + wbp.persistFlags = nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION + | nsIWBP.PERSIST_FLAGS_FROM_CACHE; + var ioService = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var nsIURL = ioService.newURI(url, null, null); + wbp.saveURI(nsIURL, null, null, null, null, file); + } - Components.classes["@mozilla.org/moz/jssubscript-loader;1"] - .getService(Components.interfaces.mozIJSSubScriptLoader) - .loadSubScript("chrome://zotero/content/webpagedump/domsaver.js"); - - wpdDOMSaver.init(file.path, document) - wpdDOMSaver.saveHTMLDocument() _addToDB(file, url, title, Zotero.Attachments.LINK_MODE_IMPORTED_URL, mimeType, charsetID, sourceItemID, itemID); @@ -482,7 +497,25 @@ Zotero.Attachments = new function(){ Zotero.DB.commitTransaction(); - Zotero.Fulltext.indexDocument(document, itemID); + if (mimeType == 'application/pdf') { + var f = function() { + Zotero.Fulltext.indexPDF(file, itemID);; + }; + } + else { + var f = function() { + Zotero.Fulltext.indexDocument(document, itemID); + }; + } + + // We don't have any way of knowing that the file is flushed to + // disk, so we just wait a second and hope for the best -- + // we'll index it later if it fails + var timer = Components.classes["@mozilla.org/timer;1"]. + createInstance(Components.interfaces.nsITimer); + timer.initWithCallback({notify: f}, 1000, + Components.interfaces.nsITimer.TYPE_ONE_SHOT); + } catch (e) { Zotero.DB.rollbackTransaction();