Skip to content
Snippets Groups Projects
Commit 9ce75e80 authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Update backpack api to use `xhr` module

parent 82290540
No related branches found
No related tags found
No related merge requests found
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment