Add Zotero.File.getResourceAsync

This commit is contained in:
Sylvester Keil 2018-07-27 15:56:00 +02:00
parent c3bdf72f35
commit aa1adc8817
No known key found for this signature in database
GPG key ID: 878933BCEAB25A10

View file

@ -33,6 +33,7 @@ Zotero.File = new function(){
this.getExtension = getExtension;
this.getContentsFromURL = getContentsFromURL;
this.getContentsFromURLAsync = getContentsFromURLAsync;
this.putContents = putContents;
this.getValidFileName = getValidFileName;
this.truncateFileName = truncateFileName;
@ -346,12 +347,16 @@ Zotero.File = new function(){
this.getResource = function (res) {
return getContentsFromURL(`resource://zotero/${res}`);
}
this.getResourceAsync = function (res) {
return getContentsFromURLAsync(`resource://zotero/${res}`);
}
/*
* Return a promise for the contents of a URL as a string
*/
this.getContentsFromURLAsync = function (url, options={}) {
function getContentsFromURLAsync (url, options={}) {
return Zotero.HTTP.request("GET", url, Object.assign(options, { responseType: "text" }))
.then(function (xmlhttp) {
return xmlhttp.response;