-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
26 lines (26 loc) · 1 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fetch('https://api.spotify.com/v1/search?q=michael+jackson&type=album')
.then(response => response.json())
.then(data => {
return Promise.all(data.albums.items
.map(item => item.id).slice(0, 5)
.map(id => fetch('https://api.spotify.com/v1/albums/' + id)));
})
.then(responses => Promise.all(responses.map(r => r.json())))
.then(albums => Promise.all(albums.map(album => fetch(album.images[0].url))))
.then(responses => Promise.all(responses.map(r => r.blob())))
.then(blobs => blobs.map(blob => URL.createObjectURL(blob)))
.then(urls => {
return Promise.all(urls.map(url => {
return new Promise(resolve => {
const image = new Image();
image.addEventListener('load', () => {
resolve(image);
});
image.src = url;
})}));
})
.then(images => {
images.forEach(image => {
document.body.appendChild(image);
});
});