Allow PDF saving via connectors
If 'pdf' flag is included in object POSTed to saveSnapshot, import the PDF directly and save as top-level item. Currently the PDF is redownloaded -- there might be a better way to get the PDF data over without redownloading. (It uses passed cookies, though, so gated PDFs should still work.)
This commit is contained in:
parent
ee1e8578ce
commit
4190412ee4
2 changed files with 71 additions and 43 deletions
|
@ -405,51 +405,79 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
|||
*/
|
||||
"init":function(url, data, sendResponseCallback) {
|
||||
Zotero.Server.Connector.Data[data["url"]] = "<html>"+data["html"]+"</html>";
|
||||
Zotero.HTTP.processDocuments(["zotero://connector/"+encodeURIComponent(data["url"])],
|
||||
function(doc) {
|
||||
delete Zotero.Server.Connector.Data[data["url"]];
|
||||
|
||||
// figure out where to save
|
||||
var libraryID = null;
|
||||
var collectionID = null;
|
||||
var zp = Zotero.getActiveZoteroPane();
|
||||
try {
|
||||
var libraryID = zp.getSelectedLibraryID();
|
||||
var collection = zp.getSelectedCollection();
|
||||
} catch(e) {}
|
||||
|
||||
try {
|
||||
// create new webpage item
|
||||
var item = new Zotero.Item("webpage");
|
||||
item.libraryID = libraryID;
|
||||
item.setField("title", doc.title);
|
||||
item.setField("url", data.url);
|
||||
item.setField("accessDate", "CURRENT_TIMESTAMP");
|
||||
var itemID = item.save();
|
||||
if(collection) collection.addItem(itemID);
|
||||
|
||||
// figure out where to save
|
||||
var libraryID = null;
|
||||
var collectionID = null;
|
||||
var zp = Zotero.getActiveZoteroPane();
|
||||
try {
|
||||
var libraryID = zp.getSelectedLibraryID();
|
||||
var collection = zp.getSelectedCollection();
|
||||
} catch(e) {}
|
||||
|
||||
// determine whether snapshot can be saved
|
||||
var filesEditable;
|
||||
if (libraryID) {
|
||||
let group = Zotero.Groups.getByLibraryID(libraryID);
|
||||
filesEditable = group.filesEditable;
|
||||
}
|
||||
else {
|
||||
filesEditable = true;
|
||||
}
|
||||
|
||||
var cookieSandbox = new Zotero.CookieSandbox(null, data["url"], data["cookie"], url.userAgent);
|
||||
|
||||
if (data.pdf && filesEditable) {
|
||||
delete Zotero.Server.Connector.Data[data.url];
|
||||
|
||||
try {
|
||||
Zotero.Attachments.importFromURL(
|
||||
data.url,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
collection ? [collection.id] : null,
|
||||
"application/pdf",
|
||||
libraryID,
|
||||
function () {
|
||||
sendResponseCallback(201);
|
||||
},
|
||||
cookieSandbox
|
||||
);
|
||||
}
|
||||
catch (e) {
|
||||
sendResponseCallback(500);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Zotero.HTTP.processDocuments(["zotero://connector/"+encodeURIComponent(data["url"])],
|
||||
function(doc) {
|
||||
delete Zotero.Server.Connector.Data[data["url"]];
|
||||
|
||||
// determine whether snapshot can be saved
|
||||
var filesEditable;
|
||||
if (libraryID) {
|
||||
var group = Zotero.Groups.getByLibraryID(libraryID);
|
||||
filesEditable = group.filesEditable;
|
||||
} else {
|
||||
filesEditable = true;
|
||||
try {
|
||||
// create new webpage item
|
||||
var item = new Zotero.Item("webpage");
|
||||
item.libraryID = libraryID;
|
||||
item.setField("title", doc.title);
|
||||
item.setField("url", data.url);
|
||||
item.setField("accessDate", "CURRENT_TIMESTAMP");
|
||||
var itemID = item.save();
|
||||
if(collection) collection.addItem(itemID);
|
||||
|
||||
// save snapshot
|
||||
if (filesEditable && !data.skipSnapshot) {
|
||||
Zotero.Attachments.importFromDocument(doc, itemID);
|
||||
}
|
||||
|
||||
sendResponseCallback(201);
|
||||
} catch(e) {
|
||||
sendResponseCallback(500);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// save snapshot
|
||||
if (filesEditable && !data.skipSnapshot) {
|
||||
Zotero.Attachments.importFromDocument(doc, itemID);
|
||||
}
|
||||
|
||||
sendResponseCallback(201);
|
||||
} catch(e) {
|
||||
sendResponseCallback(500);
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
null, null, false,
|
||||
new Zotero.CookieSandbox(null, data["url"], data["cookie"], url.userAgent));
|
||||
},
|
||||
null, null, false, cookieSandbox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
BIN
chrome/skin/default/zotero/treeitem-attachment-pdf@2x.png
Normal file
BIN
chrome/skin/default/zotero/treeitem-attachment-pdf@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
Loading…
Reference in a new issue