diff --git a/src/lib/backpack-api.js b/src/lib/backpack-api.js index e77b6d83200f40164c519ad23f4291cda44e9acc..0ec46260ac315d9592e7b7e0abfe432eb8e1a08e 100644 --- a/src/lib/backpack-api.js +++ b/src/lib/backpack-api.js @@ -1,18 +1,28 @@ +import xhr from 'xhr'; + const getBackpackContents = ({ host, username, token, limit, offset -}) => fetch(`${host}${username}?limit=${limit}&offset=${offset}`, { - headers: {'x-token': token} -}) - .then(d => d.json()) - .then(items => items.map(item => +}) => new Promise((resolve, reject) => { + xhr({ + method: 'GET', + uri: `${host}${username}?limit=${limit}&offset=${offset}`, + headers: {'x-token': token}, + json: true + }, (error, response) => { + if (error || response.statusCode !== 200) { + return reject(); + } // Add a new property for the full thumbnail url, which includes the host. // TODO retreiving the images through storage would allow us to remove this. - Object.assign(item, {thumbnailUrl: `${host}${item.thumbnail}`}) - )); + return resolve(response.body.map(item => ( + Object.assign({}, item, {thumbnailUrl: `${host}/${item.thumbnail}`}) + ))); + }); +}); export { getBackpackContents