From 07464d5c84561ae7bde185d6ab1b9b3b324bfd07 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Fri, 3 Aug 2018 10:49:15 +0200 Subject: [PATCH] Make File.getResource expect full URLs This change makes is easier to support different URL schemes when overriding on other platforms. --- chrome/content/zotero/xpcom/date.js | 2 +- chrome/content/zotero/xpcom/file.js | 22 ++++++++++++++++------ chrome/content/zotero/xpcom/schema.js | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index c622f5cb3f..eb800c97c8 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -47,7 +47,7 @@ Zotero.Date = new function(){ throw new Error("Unimplemented"); } - var json = JSON.parse(Zotero.File.getResource('schema/dateFormats.json')); + var json = JSON.parse(Zotero.File.getResource('resource://zotero/schema/dateFormats.json')); var locale = Zotero.locale; var english = locale.startsWith('en'); // If no exact match, try first two characters ('de') diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 38c1c13723..e91ce07e00 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -339,15 +339,25 @@ Zotero.File = new function(){ return xmlhttp.responseText; } - /* - * Returns the contents of the given local resource. + /** + * Return the contents of resource. Use this for loading + * resource/chrome URLs. + * + * @param {String} url - the resource url + * @return {String} the resource contents as a string */ - this.getResource = function (res) { - return getContentsFromURL(`resource://zotero/${res}`); + this.getResource = function (url) { + return getContentsFromURL(url); } - this.getResourceAsync = function (res) { - return getContentsFromURLAsync(`resource://zotero/${res}`); + /** + * Return a promise for the contents of resource. + * + * @param {String} url - the resource url + * @return {Promise} the resource contents as a string + */ + this.getResourceAsync = function (url) { + return getContentsFromURLAsync(url); } diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 61ae216f12..5d598f7eea 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -574,7 +574,7 @@ Zotero.Schema = new function(){ var ModeType = Zotero.Utilities.capitalize(modeType); var Mode = Zotero.Utilities.capitalize(mode); - var repotime = yield Zotero.File.getResourceAsync("schema/repotime.txt"); + var repotime = yield Zotero.File.getResourceAsync("resource://zotero/schema/repotime.txt"); var date = Zotero.Date.sqlToDate(repotime.trim(), true); repotime = Zotero.Date.toUnixTimestamp(date); @@ -1446,7 +1446,7 @@ Zotero.Schema = new function(){ throw ('Schema type not provided to _getSchemaSQL()'); } - return Zotero.File.getResourceAsync(`schema/${schema}.sql`); + return Zotero.File.getResourceAsync(`resource://zotero/schema/${schema}.sql`); }