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,9 +405,6 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
*/
|
*/
|
||||||
"init":function(url, data, sendResponseCallback) {
|
"init":function(url, data, sendResponseCallback) {
|
||||||
Zotero.Server.Connector.Data[data["url"]] = "<html>"+data["html"]+"</html>";
|
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
|
// figure out where to save
|
||||||
var libraryID = null;
|
var libraryID = null;
|
||||||
|
@ -418,6 +415,46 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
var collection = zp.getSelectedCollection();
|
var collection = zp.getSelectedCollection();
|
||||||
} catch(e) {}
|
} 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"]];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// create new webpage item
|
// create new webpage item
|
||||||
var item = new Zotero.Item("webpage");
|
var item = new Zotero.Item("webpage");
|
||||||
|
@ -428,15 +465,6 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
var itemID = item.save();
|
var itemID = item.save();
|
||||||
if(collection) collection.addItem(itemID);
|
if(collection) collection.addItem(itemID);
|
||||||
|
|
||||||
// determine whether snapshot can be saved
|
|
||||||
var filesEditable;
|
|
||||||
if (libraryID) {
|
|
||||||
var group = Zotero.Groups.getByLibraryID(libraryID);
|
|
||||||
filesEditable = group.filesEditable;
|
|
||||||
} else {
|
|
||||||
filesEditable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// save snapshot
|
// save snapshot
|
||||||
if (filesEditable && !data.skipSnapshot) {
|
if (filesEditable && !data.skipSnapshot) {
|
||||||
Zotero.Attachments.importFromDocument(doc, itemID);
|
Zotero.Attachments.importFromDocument(doc, itemID);
|
||||||
|
@ -448,8 +476,8 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
null, null, false,
|
null, null, false, cookieSandbox);
|
||||||
new Zotero.CookieSandbox(null, data["url"], data["cookie"], url.userAgent));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
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