Fix webpage/snapshot saving from connector
This commit is contained in:
parent
157b8deda9
commit
0be2796500
|
@ -458,9 +458,10 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Zotero.HTTP.processDocuments(["zotero://connector/"+encodeURIComponent(data["url"])],
|
Zotero.HTTP.processDocuments(
|
||||||
function(doc) {
|
["zotero://connector/" + encodeURIComponent(data.url)],
|
||||||
delete Zotero.Server.Connector.Data[data["url"]];
|
Zotero.Promise.coroutine(function* (doc) {
|
||||||
|
delete Zotero.Server.Connector.Data[data.url];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// create new webpage item
|
// create new webpage item
|
||||||
|
@ -469,13 +470,14 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
item.setField("title", doc.title);
|
item.setField("title", doc.title);
|
||||||
item.setField("url", data.url);
|
item.setField("url", data.url);
|
||||||
item.setField("accessDate", "CURRENT_TIMESTAMP");
|
item.setField("accessDate", "CURRENT_TIMESTAMP");
|
||||||
var itemID = item.save();
|
if (collection) {
|
||||||
if(collection) collection.addItem(itemID);
|
item.setCollections([collection.id]);
|
||||||
|
}
|
||||||
|
var itemID = yield item.saveTx();
|
||||||
|
|
||||||
// save snapshot
|
// save snapshot
|
||||||
if (filesEditable && !data.skipSnapshot) {
|
if (filesEditable && !data.skipSnapshot) {
|
||||||
// TODO: async
|
yield Zotero.Attachments.importFromDocument({
|
||||||
Zotero.Attachments.importFromDocument({
|
|
||||||
document: doc,
|
document: doc,
|
||||||
parentItemID: itemID
|
parentItemID: itemID
|
||||||
});
|
});
|
||||||
|
@ -483,11 +485,14 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
|
|
||||||
sendResponseCallback(201);
|
sendResponseCallback(201);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
Zotero.debug("ERROR");
|
||||||
|
Zotero.debug(e);
|
||||||
sendResponseCallback(500);
|
sendResponseCallback(500);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
null, null, false, cookieSandbox);
|
null, null, false, cookieSandbox
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ describe("Connector Server", function () {
|
||||||
|
|
||||||
describe("/connector/saveItems", function () {
|
describe("/connector/saveItems", function () {
|
||||||
// TODO: Test cookies
|
// TODO: Test cookies
|
||||||
it("should save an item to the current selected collection", function* () {
|
it("should save a translated item to the current selected collection", function* () {
|
||||||
var collection = yield createDataObject('collection');
|
var collection = yield createDataObject('collection');
|
||||||
yield waitForItemsLoad(win);
|
yield waitForItemsLoad(win);
|
||||||
|
|
||||||
|
@ -98,4 +98,48 @@ describe("Connector Server", function () {
|
||||||
yield waitForItemEvent('refresh');
|
yield waitForItemEvent('refresh');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("/connector/saveSnapshot", function () {
|
||||||
|
it("should save a webpage item and snapshot to the current selected collection", function* () {
|
||||||
|
var collection = yield createDataObject('collection');
|
||||||
|
yield waitForItemsLoad(win);
|
||||||
|
|
||||||
|
// saveSnapshot saves parent and child before returning
|
||||||
|
var ids1, ids2;
|
||||||
|
var promise = waitForItemEvent('add').then(function (ids) {
|
||||||
|
ids1 = ids;
|
||||||
|
return waitForItemEvent('add').then(function (ids) {
|
||||||
|
ids2 = ids;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
yield Zotero.HTTP.request(
|
||||||
|
'POST',
|
||||||
|
connectorServerPath + "/connector/saveSnapshot",
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
url: "http://example.com",
|
||||||
|
html: "<html><head><title>Title</title><body>Body</body></html>"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.isTrue(promise.isFulfilled());
|
||||||
|
|
||||||
|
// Check parent item
|
||||||
|
assert.lengthOf(ids1, 1);
|
||||||
|
var item = Zotero.Items.get(ids1[0]);
|
||||||
|
assert.equal(Zotero.ItemTypes.getName(item.itemTypeID), 'webpage');
|
||||||
|
assert.isTrue(collection.hasItem(item.id));
|
||||||
|
assert.equal(item.getField('title'), 'Title');
|
||||||
|
|
||||||
|
// Check attachment
|
||||||
|
assert.lengthOf(ids2, 1);
|
||||||
|
item = Zotero.Items.get(ids2[0]);
|
||||||
|
assert.isTrue(item.isImportedAttachment());
|
||||||
|
assert.equal(item.getField('title'), 'Title');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user