Skip to content

Commit 30a80b2

Browse files
committed
Make BaseClient#getItemURL async
1 parent 1456df0 commit 30a80b2

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/baseclient.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,18 @@ BaseClient.prototype = {
289289
* URL of an item in the ``/public`` folder.
290290
*
291291
* @param {string} path - Path relative to the module root.
292-
* @returns {string} The full URL of the item, including the storage origin
292+
* @returns {Promise} Resolves to t he full URL of the item, including the storage origin.
293293
*/
294294
getItemURL: function (path) {
295295
if (typeof(path) !== 'string') {
296-
throw 'Argument \'path\' of baseClient.getItemURL must be a string';
296+
return Promise.reject('Argument \'path\' of baseClient.getItemURL must be a string');
297297
}
298+
let url;
298299
if (this.storage.connected) {
299300
path = this._cleanPath( this.makePath(path) );
300-
return this.storage.remote.href + path;
301-
} else {
302-
return undefined;
301+
url = this.storage.remote.href + path;
303302
}
303+
return Promise.resolve(url);
304304
},
305305

306306
/**

test/unit/baseclient-suite.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ define(['./src/config', './src/baseclient', 'test/helpers/mocks', 'tv4'],
403403
env.storage.connected = true;
404404
env.storage.remote = {href: 'http://example.com/test'};
405405

406-
var itemURL = env.client.getItemURL('A%2FB /C/%bla//D');
407-
test.assert(itemURL, 'http://example.com/test/foo/A%252FB%20/C/%25bla/D');
406+
env.client.getItemURL('A%2FB /C/%bla//D').then((itemURL) => {
407+
test.assert(itemURL, 'http://example.com/test/foo/A%252FB%20/C/%25bla/D');
408+
});
408409
}
409410
},
410411

@@ -414,11 +415,13 @@ define(['./src/config', './src/baseclient', 'test/helpers/mocks', 'tv4'],
414415
env.storage.connected = true;
415416
env.storage.remote = {href: 'http://example.com/test'};
416417

417-
test.assert(env.client.getItemURL("Capture d'écran"),
418-
'http://example.com/test/foo/Capture%20d%27%C3%A9cran');
418+
env.client.getItemURL("Capture d'écran").then((itemURL) => {
419+
test.assertAnd(itemURL, 'http://example.com/test/foo/Capture%20d%27%C3%A9cran');
419420

420-
test.assert(env.client.getItemURL('So they said "hey"'),
421-
'http://example.com/test/foo/So%20they%20said%20%22hey%22');
421+
env.client.getItemURL('So they said "hey"').then((itemURL) => {
422+
test.assert(itemURL, 'http://example.com/test/foo/So%20they%20said%20%22hey%22');
423+
});
424+
});
422425
}
423426
},
424427

0 commit comments

Comments
 (0)