bookData = Promise.all(
combinedRaw.map((d, i) => {
let id_we_use = null;
if (!d.work.cover_edition_key) {
id_we_use = d.logged_edition.substring(7, 18);
} else id_we_use = d.work.cover_edition_key;
const coverUrl =
"http://covers.openlibrary.org/b/olid/" + id_we_use + "-L.jpg";
const editionUrl = "https://openlibrary.org/books/" + id_we_use + ".json";
d = d.work;
return d3.json(editionUrl).then((editionJson) => {
return getColors(coverUrl)
.then((colors) => {
colors = colors.map((d) => {
return {
red: d._rgb[0],
green: d._rgb[1],
blue: d._rgb[2]
};
});
if (colors.length == 0) return null;
return {
Title: d.title,
NumPages: editionJson.number_of_pages,
CoverColor: colors[COVERCOLOR],
AccentColor: colors[ACCENTCOLOR],
CoverUrl: coverUrl
};
})
.catch(function (err) {
return null;
});
});
})
)