Support target selector sessions for /connector/import

This commit is contained in:
Dan Stillman 2018-03-28 08:45:46 -04:00
parent bff7cee374
commit 38330e4c13

View file

@ -850,29 +850,41 @@ Zotero.Server.Connector.Import.prototype = {
supportedDataTypes: '*',
permitBookmarklet: false,
init: Zotero.Promise.coroutine(function* (options) {
init: async function (options) {
let translate = new Zotero.Translate.Import();
translate.setString(options.data);
let translators = yield translate.getTranslators();
let translators = await translate.getTranslators();
if (!translators || !translators.length) {
return 400;
}
translate.setTranslator(translators[0]);
var { library, collection, editable } = Zotero.Server.Connector.getSaveTarget();
var libraryID = library.libraryID;
if (!library.editable) {
Zotero.logError("Can't import into read-only library " + library.name);
return [500, "application/json", JSON.stringify({ libraryEditable: false })];
}
let items = yield translate.translate({
libraryID: library.libraryID,
try {
var session = Zotero.Server.Connector.SessionManager.create(options.query.session);
}
catch (e) {
return [409, "application/json", JSON.stringify({ error: "SESSION_EXISTS" })];
}
await session.update(libraryID, collection ? collection.id : false);
let items = await translate.translate({
libraryID,
collections: collection ? [collection.id] : null,
// Import translation skips selection by default, so force it to occur
saveOptions: {
skipSelect: false
}
});
session.addItems(items);
return [201, "application/json", JSON.stringify(items)];
})
}
}
/**