PK7ZUXD7ELS4V6SNYYFWP45JKWKJOVWBGFDRSFY3LP47IU2M55BAC if [[ $status = "404" ]]; then
if [[ $status = "200" ]]; thentype="$(identify -format %[magick] ${filename})";if [[ $type = PNG ]]; thenconvert -strip "$filename" -fuzz 10% -trim +repage "$filename";elif [[ $type = JPEG ]]; thenjpegtran -perfect -copy none -trim -optimize -crop $(convert "$filename" -fuzz 10% -trim -format "%wx%h%X%Y" info:-) -outfile "$filename" "$filename";fiif [ -z "$2" ]; thenecho "/tmp/$filename";elsestring2="$(curl -O -J -s -w "%{filename_effective}, %{http_code}" $2)";readarray -c1 -C 'mfcb val_trim a' -td, <<<"$string2,"; unset 'a[-1]'; declare -p a > /dev/null;filename2="${a[0]}"status2="${a[1]}"if [[ $status2 = "200" ]]; then#nice! cloudinary filename duplicate file extension, so no chance of overwrite due to collisionif cmp -s "$filename" "filename2"; thenecho "same";elseecho "/tmp/$filename";fielseecho "$status2";fifielse
exit 0;fitype="$(identify -format %[magick] ${filename})";if [[ $type = PNG ]]; thenconvert -strip "$filename" -fuzz 10% -trim +repage "$filename";elif [[ $type = JPEG ]]; thenjpegtran -perfect -copy none -trim -optimize -crop $(convert "$filename" -fuzz 10% -trim -format "%wx%h%X%Y" info:-) -outfile "$filename" "$filename";fiecho "/tmp/$filename";
fi
if(e[i][0].type === 'chocolate' || e[i][0].type === 'gummy' || e[i][0].type === 'mint') {let n = new Big(e[i][0].meta.variant.retail_pack_number_of_items);
if(e[i][0].type === 'chocolate' || e[i][0].type === 'gummy' || e[i][0].type === 'mint' || e[i][0].type === 'spray' || e[i][0].type === 'tea') {let n = e[i][0].meta.variant;if(e[i][0].type === 'spray') {n = new Big(n.retail_pack_net_content);} else {n = new Big(n.retail_pack_number_of_items);}
let terpene = e[i][0].tags[j].split('terpenes--')[1];if(terpene) {terpenes.push(terpene);
if(e[i][0].tags[j].startsWith('terpenes--')) {let terpene = e[i][0].tags[j].substring(10).toLowerCase();if(terpene) {if(terpene.includes('remove')) {if(terpenes.length) {console.log(terpenes);console.log(e[i][0].tags);console.log(`${url}/products/${e[i][0].handle}`);}terpenes = null;break;} else {terpenes.push(terpene);}}
let pics = new Set((await request({url: `${url}/products/${e[i][0].handle}.json`,headers: {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36"}}).then(JSON.parse)).product.images.map(a => a.src.split('?')[0]));for(let pic of pics) {let product_images = await return_key('select ID from product_image where product = $1 and source = $2', [productID, pic]);if(product_images.length === 0) {let response = (await exec('./image.sh ' + pic)).stdout.trim();if(response !== '404') {let ar = await cloudinary.uploader.upload(response, {public_id: response.slice(5), unique_filename: false});
if(process.env.CLOUDINARY_URL) {let pics = new Set((await request({url: `${url}/products/${e[i][0].handle}.json`,headers: {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36"}}).then(JSON.parse)).product.images.map(({src}) => {let questionIndex = src.indexOf('?');if(questionIndex === -1) {return src;} else {return src.substring(0, questionIndex);}}));for(let pic of pics) {let product_images = (await postgres.query(`select id, case when now() - system_time_start > '30 days' then destination else null end as destination from product_image where product = $1 and source = $2`, [productID, pic])).rows;if(product_images.length === 0) {let destination;if(process.env.CLOUDINARY_URL === 'fake') {//https://stackoverflow.com/a/13108449/let name = pic.split('/');name = name.pop() || name.pop();name += name.substring(name.lastIndexOf('.'));destination = "https://res.cloudinary.com/the-eternal-tao/image/upload/" + name;} else {let response = (await exec('./image.sh ' + pic)).stdout.trim();if(response.startsWith('/tmp/')) {destination = (await cloudinary.uploader.upload(response, {public_id: response.substring(5), unique_filename: false})).secure_url;} else {continue;}}
} else if(product_images.length === 1) {if(product_images[0].destination !== null && process.env.CLOUDINARY_URL !== 'fake') {let response = (await exec(`./image.sh ${pic} ${product_images[0].destination}`)).stdout.trim();if(response.startsWith('/tmp/')) {await postgres.query('update product_image set destination = $1 where id = $2', [(await cloudinary.uploader.upload(response, {public_id: response.substring(5), unique_filename: false})).secure_url,product_images[0].id]);}}} else {console.error('data integrity issue', product_images);//product match, source match, but destinations are different, which should be unpossible
} else if(product_images.length === 1) {//console.log('already persisted :)');//have a flag that once a month, we fetch images anyways just to see if there's a diff? thanks cloudinary :)} else {console.error('data integrity issue', product_images);//product match, source match, but destinations are different, which should be unpossible
switch(e[i][j].type) {case 'capsule':quantity = e[i][j].meta.variant.retail_pack_number_of_items;break;case 'disposable':case 'cartridge':case 'flower':case 'spray':case 'oil':if(e[i][j].meta.variant && e[i][j].meta.variant.retail_pack_net_content) {quantity = e[i][j].meta.variant.retail_pack_net_content;} else {quantity = e[i][j].variant_title.match(qty)[3];}break;case 'tea':case 'gummy':case 'mint':case 'preroll':case 'cookie':case 'chocolate':
if(e[i][j].variant_title === 'Default Title') {portions = e[i][j].meta.variant.retail_pack_number_of_itemsquantity = e[i][j].meta.variant.retail_pack_net_content;} else {[, , portions, quantity] = e[i][j].variant_title.match(qty);if(portions === undefined && e[i][0/*since we only modify the first index*/].type === 'preroll' && e[i][j].meta.variant.retail_pack_number_of_items > 1) {