Fix direct saving of PDFs via connector
This commit is contained in:
parent
6a97de8911
commit
47b934f67e
|
@ -400,7 +400,10 @@ Zotero.Server.DataListener.prototype._processEndpoint = function(method, postDat
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass to endpoint
|
// pass to endpoint
|
||||||
if((endpoint.init.length ? endpoint.init.length : endpoint.init.arity) === 3) {
|
if (endpoint.init.length === 2) {
|
||||||
|
endpoint.init(decodedData, sendResponseCallback);
|
||||||
|
}
|
||||||
|
else {
|
||||||
const uaRe = /[\r\n]User-Agent: +([^\r\n]+)/i;
|
const uaRe = /[\r\n]User-Agent: +([^\r\n]+)/i;
|
||||||
var m = uaRe.exec(this.header);
|
var m = uaRe.exec(this.header);
|
||||||
var url = {
|
var url = {
|
||||||
|
@ -408,10 +411,7 @@ Zotero.Server.DataListener.prototype._processEndpoint = function(method, postDat
|
||||||
"query":this.query ? Zotero.Server.decodeQueryString(this.query.substr(1)) : {},
|
"query":this.query ? Zotero.Server.decodeQueryString(this.query.substr(1)) : {},
|
||||||
"userAgent":m && m[1]
|
"userAgent":m && m[1]
|
||||||
};
|
};
|
||||||
|
|
||||||
endpoint.init(url, decodedData, sendResponseCallback);
|
endpoint.init(url, decodedData, sendResponseCallback);
|
||||||
} else {
|
|
||||||
endpoint.init(decodedData, sendResponseCallback);
|
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
Zotero.debug(e);
|
Zotero.debug(e);
|
||||||
|
|
|
@ -409,7 +409,7 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
* @param {String} data POST data or GET query string
|
* @param {String} data POST data or GET query string
|
||||||
* @param {Function} sendResponseCallback function to send HTTP response
|
* @param {Function} sendResponseCallback function to send HTTP response
|
||||||
*/
|
*/
|
||||||
"init":function(url, data, sendResponseCallback) {
|
init: Zotero.Promise.coroutine(function* (url, data, sendResponseCallback) {
|
||||||
Zotero.Server.Connector.Data[data["url"]] = "<html>"+data["html"]+"</html>";
|
Zotero.Server.Connector.Data[data["url"]] = "<html>"+data["html"]+"</html>";
|
||||||
|
|
||||||
var zp = Zotero.getActiveZoteroPane();
|
var zp = Zotero.getActiveZoteroPane();
|
||||||
|
@ -439,20 +439,14 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
delete Zotero.Server.Connector.Data[data.url];
|
delete Zotero.Server.Connector.Data[data.url];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: Async
|
yield Zotero.Attachments.importFromURL({
|
||||||
Zotero.Attachments.importFromURL(
|
|
||||||
data.url,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
collection ? [collection.id] : null,
|
|
||||||
"application/pdf",
|
|
||||||
libraryID,
|
libraryID,
|
||||||
function () {
|
url: data.url,
|
||||||
sendResponseCallback(201);
|
collections: collection ? [collection.id] : undefined,
|
||||||
},
|
contentType: "application/pdf",
|
||||||
cookieSandbox
|
cookieSandbox
|
||||||
);
|
});
|
||||||
|
sendResponseCallback(201)
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
sendResponseCallback(500);
|
sendResponseCallback(500);
|
||||||
|
@ -496,7 +490,7 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
|
||||||
null, null, false, cookieSandbox
|
null, null, false, cookieSandbox
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -145,5 +145,38 @@ describe("Connector Server", function () {
|
||||||
assert.isTrue(item.isImportedAttachment());
|
assert.isTrue(item.isImportedAttachment());
|
||||||
assert.equal(item.getField('title'), 'Title');
|
assert.equal(item.getField('title'), 'Title');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should save a PDF to the current selected collection", function* () {
|
||||||
|
var collection = yield createDataObject('collection');
|
||||||
|
yield waitForItemsLoad(win);
|
||||||
|
|
||||||
|
var file = getTestDataDirectory();
|
||||||
|
file.append('test.pdf');
|
||||||
|
httpd.registerFile("/test.pdf", file);
|
||||||
|
|
||||||
|
var ids;
|
||||||
|
var promise = waitForItemEvent('add');
|
||||||
|
yield Zotero.HTTP.request(
|
||||||
|
'POST',
|
||||||
|
connectorServerPath + "/connector/saveSnapshot",
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
url: testServerPath + "/test.pdf",
|
||||||
|
pdf: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var ids = yield promise;
|
||||||
|
|
||||||
|
assert.lengthOf(ids, 1);
|
||||||
|
var item = Zotero.Items.get(ids[0]);
|
||||||
|
assert.isTrue(item.isImportedAttachment());
|
||||||
|
assert.equal(item.attachmentContentType, 'application/pdf');
|
||||||
|
assert.isTrue(collection.hasItem(item.id));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user