Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const parseAmzImageUrl = (imgurl) => {
// let imageURL =
// 'https://m.media-amazon.com/images/I/A1EHx4FHFjL._CLa%7C2140%2C2000%7CB1hNfKQcFOS.png%7C0%2C0%2C2140%2C2000%2B0.0%2C0.0%2C2140.0%2C2000.0._UL1500_.png';
let imageURL = decodeURIComponent(imgurl);
let imgData = imageURL.split('/I/');
let startURL = imgData[0];
imgData = imgData[1];
let fileInfo = path.parse(imageURL);
let data = {
base_id: '',
base_url: '',
print_id: '',
print_url: '',
ext: fileInfo.ext,
url: imgurl
};
try {
imgData = imgData.split(/\|/g);
let bases = imgData[0].split(/\./g);
let print = imgData[2].split(/\./g);
data.base_id = bases[0];
data.print_id = print[0];
if (data.base_id) {
data.base_url = `https://m.media-amazon.com/images/I/${data.base_id}.png`;
}
if (data.print_id) {
data.print_url = `https://m.media-amazon.com/images/I/${data.print_id}.png`;
}
} catch (e) {}
return data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment