www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

server_connectorIntegration.js (3109B)


      1 /*
      2 	***** BEGIN LICENSE BLOCK *****
      3 	
      4 	Copyright © 2017 Center for History and New Media
      5 					George Mason University, Fairfax, Virginia, USA
      6 					http://zotero.org
      7 	
      8 	This file is part of Zotero.
      9 	
     10 	Zotero is free software: you can redistribute it and/or modify
     11 	it under the terms of the GNU Affero General Public License as published by
     12 	the Free Software Foundation, either version 3 of the License, or
     13 	(at your option) any later version.
     14 	
     15 	Zotero is distributed in the hope that it will be useful,
     16 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     17 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18 	GNU Affero General Public License for more details.
     19 
     20 	You should have received a copy of the GNU Affero General Public License
     21 	along with Zotero.  If not, see <http://www.gnu.org/licenses/>.
     22 	
     23 	***** END LICENSE BLOCK *****
     24 */
     25 
     26 /**
     27  * Adds integration endpoints related to doc integration via HTTP/connector.
     28  * 
     29  * document/execCommand initiates an integration command and responds with the
     30  * next request for the http client (e.g. 'Application.getDocument').
     31  * The client should respond to document/respond with the payload and expect
     32  * another response with the next request, until it receives 'Document.complete'
     33  * at which point the integration transaction is considered complete.
     34  */
     35 Zotero.Server.Endpoints['/connector/document/execCommand'] = function() {};
     36 Zotero.Server.Endpoints['/connector/document/execCommand'].prototype = {
     37 	supportedMethods: ["POST"],
     38 	supportedDataTypes: ["application/json"],
     39 	permitBookmarklet: true,
     40 	init: function(data, sendResponse) {
     41 		if (Zotero.HTTPIntegrationClient.inProgress) {
     42 			// This will focus the last integration window if present
     43 			Zotero.Integration.execCommand('http', data.command, data.docId);
     44 			sendResponse(503, 'text/plain', 'Integration transaction is already in progress')
     45 			return;
     46 		}
     47 		Zotero.HTTPIntegrationClient.inProgress = true;
     48 		Zotero.HTTPIntegrationClient.sendResponse = sendResponse;
     49 		Zotero.Integration.execCommand('http', data.command, data.docId);
     50 	},
     51 };
     52 
     53 Zotero.Server.Endpoints['/connector/document/respond'] = function() {};
     54 Zotero.Server.Endpoints['/connector/document/respond'].prototype = {
     55 	supportedMethods: ["POST"],
     56 	supportedDataTypes: ["application/json"],
     57 	permitBookmarklet: true,
     58 	
     59 	init: function(data, sendResponse) {
     60 		data = JSON.parse(data);
     61 		if (data && data.error) {
     62 			// Apps Script stack is a JSON object
     63 			if (typeof data.stack != "string") {
     64 				data.stack = JSON.stringify(data.stack);
     65 			}
     66 			Zotero.HTTPIntegrationClient.deferredResponse.reject(data);
     67 		} else {
     68 			Zotero.HTTPIntegrationClient.deferredResponse.resolve(data);
     69 		}
     70 		Zotero.HTTPIntegrationClient.sendResponse = sendResponse;
     71 	}
     72 };
     73 
     74 // For managing macOS integration and progress window focus
     75 Zotero.Server.Endpoints['/connector/sendToBack'] = function() {};
     76 Zotero.Server.Endpoints['/connector/sendToBack'].prototype = {
     77 	supportedMethods: ["POST"],
     78 	supportedDataTypes: ["application/json"],
     79 	permitBookmarklet: true,
     80 	init: function() {
     81 		Zotero.Utilities.Internal.sendToBack();
     82 	},
     83 };