$(function() { // Make add music on page load makeAddMusicMenus(); }); $('#submit-music').submit(async function(event) { event.preventDefault(); // Get boost amount from selector const boostAmount = $("#boost-blux option:selected").val(); let txid = ""; try { // Only handle BLUX boost if amount is selected and greater than 0 if(boostAmount && parseInt(boostAmount) > 0) { txid = await sendBluxBoostTransaction(boostAmount); } else { // Set txid to empty string or some indicator that no transaction was needed txid = ""; } // Proceed with original form submission logic await handleAddMusicSubmission(txid); } catch (error) { $('#add-music-success').removeClass('alert-success').addClass('alert-danger') .html(`Boost failed: ${error.message}`).fadeIn().delay(3000).fadeOut(); } }); async function handleAddMusicSubmission(txid) { // Take submit form and make it yo bish. // Call getGeopol first and await its result try { // GetGeopol Called await getGeopol( $("#submit-music-btn").attr("valueLng"), $("#submit-music-btn").attr("valueLat") ); } catch (error) { console.error("Geolocation failed:", error); valid = false; errors.push("Could not determine location. Please try again."); } //--- We gon need some facts in this erria ---\\ let yt = $("#yt").val(); let sc = $("#sc").val(); let spot = $("#spot").val(); let atomict = $("#atomict").val(); var atomicc = "";// = $("#atomict").attr("collection"); let mood = $("#mood option:selected").val(); let genre = $("#genre option:selected").val(); let format = $("#format option:selected").val(); let songLat = $("#submit-music-btn").attr("valuelat"); let songLng = $("#submit-music-btn").attr("valuelng"); let songIso3 = $("#submit-music-btn").attr("songiso3"); let boost_blux_val = $("#boost-blux option:selected").val() || 0; // Default to 0 if undefined or null var songstateid = $("#submit-music-btn").attr("songstateid"); var songcityascii = $("#submit-music-btn").attr("songcityascii"); // YouTube URL:, sc, spot, Atomic Token:, mood, Genre:, Format:, Latitude:, Longitude:, ISO3 Country Code:, Boost BLUX Value:, State ID:, City ASCII:, errors = []; spotSlug = ""; scSlug = ""; ytSlug = ""; ytChannel = ""; valid = true; if (yt) { await validateYouTubeUrl(yt); } if (sc) { validateSoundcloudUrl(sc); } if (spot) { validateSpotifyUrl(spot); } //--- Check if content is blank ---\\ if ((!spot && !sc && !yt)) { errors.push("The Sound of Silence. Good choice."); valid = false; } //--- Require YT Videos also have another Player ---\\ if ((!spot && !sc) && yt) { errors.push("πŸŽ₯ For YouTube, we require at least 1 other player of the same song/album. If you aren't yet distributing your music to all platforms you may use Soundcloud; playlists work."); valid = false; } /*/--- Limit posting to 1 per minute ---\\ if(Cookies.get('lastPost') !== undefined) { /// CHECK THIS valid = false; errors.push("To combat spam, please wait 30 seconds between posts. ⏱️"); } /*/ //--- Make sure they marked Genre/Mood/Format ---\\ if(genre == "" || mood == "" || format == "") { valid = false; errors.push("Don't forget about the genre, mood, and format"); } if(typeof songIso3 == 'undefined') { valid = false; errors.push("Please post on land and try again."); } // --- Make sure user is logged in --- \\ if($("#boost-title").text() == 'Log in to post') { valid = false; errors.push("You must be logged in to post."); } // --- Make NFT use NFT type --- \\ if((atomict == '') && format == "nft") { valid = false; errors.push("To use NFT format, you must include Template ID"); } // --- Force NFT type to only be for NFTs--- \\ if((atomict != '') && format != "nft") { valid = false; errors.push("To use Template ID, you must choose NFT format "); } // --- Get Collection + Verify Audio or Video field --- \\ console.log("atomict",atomict); if (atomict != ''){ await getAtomicCollection(atomict) } var justSendIt = { "yt":ytSlug, "yt_channel":window.ytChannelf ? window.ytChannelf: "", "sc":scSlug, "spot":spotSlug, "mood":mood, "genre":genre, "lat":songLat, "lng":songLng, "format":format, "iso3":songIso3, "atomict":atomict, "atomicc": atomicc || '', "city_ascii":(typeof songcityascii !== 'undefined') ? songcityascii: "", "state_code":(typeof songstateid !== 'undefined') ? songstateid: "", "boost_blux": boost_blux_val, "boost_tx": txid, // Will be populated if boost succeeds "posted_by": window.session?.actor.toString() || "" }; console.log("//justSendIt", justSendIt); if (Cookies.get('username') !== undefined){ justSendIt.username = Cookies.get('username'); } if( valid ){ // Send that shit $.ajax({ method:"post", url:'php/add_music.php', data:justSendIt, dataType:"json" }) // END .ajax() .done(function(data) { // console.log("Response data:", data); if (data.success == true) { // Hide any previous errors $("#add-music-error").hide(); // Show Success Message $("#add-music-success").html('Your music has been posted to the map. πŸ‘
Upvote this track and it will grow bigger 🌱🌳').fadeIn(222); // --- Send event to Google Analytics --- \\ ADD THIS WHEN WE GO LIVE Cookies.set('lastPost', 'true', { expires: 150 }); console.log("no duplicate error"); $("#yt, #sc, #spot").val(''); //--- Remove +Music Marker ---\\ if (typeof addMusicMarker !== 'undefined') { addMusicMarker.remove(); } // -- Post Song to Map -- \\ //Cookies.set('getItSteemy', data.songid); // Adds cookie that will make user post to Steemit var marker = L.circleMarker( [songLat,songLng], { radius: 20, "title": data.songid, color: genreColors[genre], fillColor: moodColors[mood] } ) .on("click", function (e) { //--- Force refresh with ID GET param that makes content display ---\\ urlGet.id = data.songid; //window.location = location.protocol+'//'+location.host+location.pathname + "?" + $.param(urlGet); window.location = window.location.protocol + "//" + window.location.host + ( !areWeLive ? "/cxc/" : "/")+ "?id=" + urlGet.id; } ).addTo(mymap); } else //END/CTN if (typeof addMusicMarker !== 'undefined') { $("#music-geopol-info, #add-music-error, #add-music-success").hide(); //--- either There was a duplicate ---\\ if (data.success == false) { // console.log("Error Message Should Appear"); if(typeof data.duplicate != undefined){ $("#add-music-error").html('It looks like we already have that song on the map. Try another!').show(); } else { $("#add-music-error").html('A wild Error appeared. We aren\'t sure why πŸ€” Try again later.').show(); } } else { // --- or Show Exact Error --- \\ htmlErrors = []; if (data.scInvalid){ htmlErrors.push("The Soundcloud link is in the right format, but showing nothing 🧐 Make sure it's public and try again."); } if (data.ytInvalid){ htmlErrors.push("The YouTube link seems legit, but we can't embedd it. Make sure it's public and try again 🧐"); } if (data.spotInvalid){ htmlErrors.push("The Spotify link seems cool, but isn't working. Make sure it's a song not an album 🧐 Click the three dots and then \"copy song link\"."); } if (data.duplicate){ htmlErrors.push("It looks like that song is already on the map. Try another +🎡"); } console.log(errors); htmlErrorsExpanded = htmlErrors.join("

"); $("#add-music-error").html(htmlErrorsExpanded).show(); } } //END if (typeof addMusicMarker !== 'undefined') // console.log(data); }) .fail(function(jqXHR, textStatus, errorThrown) { // console.log("AJAX Error Details:"); // console.log("Status:", jqXHR.status); // console.log("Response Text:", jqXHR.responseText); // console.log("Text Status:", textStatus); // console.log("Error Thrown:", errorThrown); // If we got a 200 status but empty response, try to handle it as success if (jqXHR.status === 200) { // console.log("Server returned 200 but response couldn't be parsed as JSON. Treating as success."); // Show a more specific message to the user $("#alert-holder") .prepend(''); $("#unknown-add-error-alert").fadeIn(222).delay(6000).fadeOut(222); } else { // console.log({ // "yt": ytSlug, // "sc": scSlug, // "spot": spotSlug, // "mood": mood, // "genre": genre, // "lat": songLat, // "lng": songLng, // "format": format // }); $("#alert-holder") .prepend(''); $("#unknown-add-error-alert").fadeIn(222).delay(6000).fadeOut(222); } }); // END .fail() } else { // END Validation if() console.log(errors); errorsExpanded = errors.join("

"); $("#add-music-error").html(errorsExpanded).show(); } };// END $('#submit-music') TODO // --- Put information abouf Country, city, state when user puts in their info --- \\ async function getGeopol(songLng, songLat) { // Send request to the Geoapify API to get location information // console.log(songLat); // console.log(songLng); if(isNaN(songLat)) { return Promise.reject("Invalid latitude"); } // Return a promise that resolves when the geolocation data is ready return new Promise((resolve, reject) => { $.ajax({ method: "get", url: `https://api.geoapify.com/v1/geocode/reverse?lat=${songLat}&lon=${songLng}&limit=1&apiKey=994ff9746f3348fb91d3659ffda66692`, dataType: "json" }) .done(function(geodata) { if (geodata.features && geodata.features.length > 0) { const props = geodata.features[0].properties; // console.log("props", props); // Get ISO3 from country code const country = props.country_code.toUpperCase(); // console.log("props country", props); let iso3 = ""; // Convert 2-letter country code to 3-letter code const countryCodes = { 'AF': 'AFG', 'AX': 'ALA', 'AL': 'ALB', 'DZ': 'DZA', 'AS': 'ASM', 'AD': 'AND', 'AO': 'AGO', 'AI': 'AIA', 'AQ': 'ATA', 'AG': 'ATG', 'AR': 'ARG', 'AM': 'ARM', 'AW': 'ABW', 'AU': 'AUS', 'AT': 'AUT', 'AZ': 'AZE', 'BS': 'BHS', 'BH': 'BHR', 'BD': 'BGD', 'BB': 'BRB', 'BY': 'BLR', 'BE': 'BEL', 'BZ': 'BLZ', 'BJ': 'BEN', 'BM': 'BMU', 'BT': 'BTN', 'BO': 'BOL', 'BQ': 'BES', 'BA': 'BIH', 'BW': 'BWA', 'BV': 'BVT', 'BR': 'BRA', 'IO': 'IOT', 'BN': 'BRN', 'BG': 'BGR', 'BF': 'BFA', 'BI': 'BDI', 'CV': 'CPV', 'KH': 'KHM', 'CM': 'CMR', 'CA': 'CAN', 'KY': 'CYM', 'CF': 'CAF', 'TD': 'TCD', 'CL': 'CHL', 'CN': 'CHN', 'CX': 'CXR', 'CC': 'CCK', 'CO': 'COL', 'KM': 'COM', 'CG': 'COG', 'CD': 'COD', 'CK': 'COK', 'CR': 'CRI', 'CI': 'CIV', 'HR': 'HRV', 'CU': 'CUB', 'CW': 'CUW', 'CY': 'CYP', 'CZ': 'CZE', 'DK': 'DNK', 'DJ': 'DJI', 'DM': 'DMA', 'DO': 'DOM', 'EC': 'ECU', 'EG': 'EGY', 'SV': 'SLV', 'GQ': 'GNQ', 'ER': 'ERI', 'EE': 'EST', 'SZ': 'SWZ', 'ET': 'ETH', 'FK': 'FLK', 'FO': 'FRO', 'FJ': 'FJI', 'FI': 'FIN', 'FR': 'FRA', 'GF': 'GUF', 'PF': 'PYF', 'TF': 'ATF', 'GA': 'GAB', 'GM': 'GMB', 'GE': 'GEO', 'DE': 'DEU', 'GH': 'GHA', 'GI': 'GIB', 'GR': 'GRC', 'GL': 'GRL', 'GD': 'GRD', 'GP': 'GLP', 'GU': 'GUM', 'GT': 'GTM', 'GG': 'GGY', 'GN': 'GIN', 'GW': 'GNB', 'GY': 'GUY', 'HT': 'HTI', 'HM': 'HMD', 'VA': 'VAT', 'HN': 'HND', 'HK': 'HKG', 'HU': 'HUN', 'IS': 'ISL', 'IN': 'IND', 'ID': 'IDN', 'IR': 'IRN', 'IQ': 'IRQ', 'IE': 'IRL', 'IM': 'IMN', 'IL': 'ISR', 'IT': 'ITA', 'JM': 'JAM', 'JP': 'JPN', 'JE': 'JEY', 'JO': 'JOR', 'KZ': 'KAZ', 'KE': 'KEN', 'KI': 'KIR', 'KP': 'PRK', 'KR': 'KOR', 'KW': 'KWT', 'KG': 'KGZ', 'LA': 'LAO', 'LV': 'LVA', 'LB': 'LBN', 'LS': 'LSO', 'LR': 'LBR', 'LY': 'LBY', 'LI': 'LIE', 'LT': 'LTU', 'LU': 'LUX', 'MO': 'MAC', 'MG': 'MDG', 'MW': 'MWI', 'MY': 'MYS', 'MV': 'MDV', 'ML': 'MLI', 'MT': 'MLT', 'MH': 'MHL', 'MQ': 'MTQ', 'MR': 'MRT', 'MU': 'MUS', 'YT': 'MYT', 'MX': 'MEX', 'FM': 'FSM', 'MD': 'MDA', 'MC': 'MCO', 'MN': 'MNG', 'ME': 'MNE', 'MS': 'MSR', 'MA': 'MAR', 'MZ': 'MOZ', 'MM': 'MMR', 'NA': 'NAM', 'NR': 'NRU', 'NP': 'NPL', 'NL': 'NLD', 'NC': 'NCL', 'NZ': 'NZL', 'NI': 'NIC', 'NE': 'NER', 'NG': 'NGA', 'NU': 'NIU', 'NF': 'NFK', 'MK': 'MKD', 'MP': 'MNP', 'NO': 'NOR', 'OM': 'OMN', 'PK': 'PAK', 'PW': 'PLW', 'PS': 'PSE', 'PA': 'PAN', 'PG': 'PNG', 'PY': 'PRY', 'PE': 'PER', 'PH': 'PHL', 'PN': 'PCN', 'PL': 'POL', 'PT': 'PRT', 'PR': 'PRI', 'QA': 'QAT', 'RE': 'REU', 'RO': 'ROU', 'RU': 'RUS', 'RW': 'RWA', 'BL': 'BLM', 'SH': 'SHN', 'KN': 'KNA', 'LC': 'LCA', 'MF': 'MAF', 'PM': 'SPM', 'VC': 'VCT', 'WS': 'WSM', 'SM': 'SMR', 'ST': 'STP', 'SA': 'SAU', 'SN': 'SEN', 'RS': 'SRB', 'SC': 'SYC', 'SL': 'SLE', 'SG': 'SGP', 'SX': 'SXM', 'SK': 'SVK', 'SI': 'SVN', 'SB': 'SLB', 'SO': 'SOM', 'ZA': 'ZAF', 'GS': 'SGS', 'SS': 'SSD', 'ES': 'ESP', 'LK': 'LKA', 'SD': 'SDN', 'SR': 'SUR', 'SJ': 'SJM', 'SE': 'SWE', 'CH': 'CHE', 'SY': 'SYR', 'TW': 'TWN', 'TJ': 'TJK', 'TZ': 'TZA', 'TH': 'THA', 'TL': 'TLS', 'TG': 'TGO', 'TK': 'TKL', 'TO': 'TON', 'TT': 'TTO', 'TN': 'TUN', 'TR': 'TUR', 'TM': 'TKM', 'TC': 'TCA', 'TV': 'TUV', 'UG': 'UGA', 'UA': 'UKR', 'AE': 'ARE', 'GB': 'GBR', 'US': 'USA', 'UM': 'UMI', 'UY': 'URY', 'UZ': 'UZB', 'VU': 'VUT', 'VE': 'VEN', 'VN': 'VNM', 'VG': 'VGB', 'VI': 'VIR', 'WF': 'WLF', 'EH': 'ESH', 'YE': 'YEM', 'ZM': 'ZMB', 'ZW': 'ZWE' }; // Assuming you have a code2 variable with the 2-letter country code if (country) { const upperCode = country.toUpperCase(); iso3 = countryCodes[upperCode] || ""; } // console.log("iso3 from API", iso3); const city = props.city || props.town || props.village || props.municipality || props.commune || props.settlement || props.borough || props.hamlet || props.locality || props.urban_area || props.place || props.suburb || props.ward || props.neighborhood || ""; const state = props.state || props.province || props.region || props.county || props.territory || props.district || props.prefecture || props.governorate || props.parish || props.department || props.division || props.canton || props.oblast || props.krai || props.republic || props.shire || props.zone || props.municipality || props.area || props.autonomous_region || props.union_territory || props.bundesland || props.administrative_division || props.subdivision || props.admin2 || ""; // console.log("city from API", city); // console.log("state from API", state); // Verify state exists in file structure or find a matching region if (iso3) { // Function to check if the coordinate falls within any region's shapefile function findMatchingRegion(iso3, lat, lng) { return new Promise((resolve) => { $.ajax({ url: `geo/regions/${iso3}/regions.txt`, dataType: 'text', success: async function(data) { // Make this callback async const regions = data.split('\n').filter(line => line.trim() !== ''); const point = L.latLng(lat, lng); let matchedRegion = state; // Default to API's state if no match // Check each region's shapefile sequentially for (const region of regions) { const filename = region.replace(/\s+/g, '_').toLowerCase() + '.json'; try { const geojson = await $.ajax({ url: `geo/regions/${iso3}/${filename}`, dataType: 'json' }); const layer = L.geoJSON(geojson); let matchFound = false; layer.eachLayer(function(l) { if (l.getBounds().contains(point)) { matchFound = true; matchedRegion = region; // Use shapefile-matched region } }); if (matchFound) break; // Exit loop early if we found a match } catch (error) { // console.log(`Error loading ${filename}`, error); } } resolve(matchedRegion); // Resolve with either shapefile match or API state }, error: function() { resolve(state); // Fallback to API state if regions.txt fails } }); }); } // Make this callback async so it can use await (async function() { // Use the spatial check function const matchedRegion = await findMatchingRegion(iso3, songLat, songLng); const formattedRegion = matchedRegion.replace(/\s+/g, '_'); let geopolMessage = ""; if (city && matchedRegion) { geopolMessage = `Posting to ${city}, ${matchedRegion}.`; $("#submit-music-btn").attr({ "songiso3": iso3, "songstateid": formattedRegion, "songcityascii": city }); } else if (matchedRegion) { geopolMessage = `Posting to ${matchedRegion}, ${props.country}.`; $("#submit-music-btn").attr({ "songiso3": iso3, "songstateid": formattedRegion }); } else { geopolMessage = `Posting to ${props.country}.`; $("#submit-music-btn").attr({ "songiso3": iso3 }); } $("#music-geopol-info").html(geopolMessage).show(); // Make sure we resolve the promise with the data we need resolve({ iso3: iso3, state_code: formattedRegion || "", city_ascii: city || "" }); })(); // Immediately invoke the async function } else { // No state information available, just use country let geopolMessage = ""; if (city) { geopolMessage = `Posting to ${city}, ${props.country}.`; $("#submit-music-btn").attr({ "songiso3": iso3, "songcityascii": city }); } else { geopolMessage = `Posting to ${props.country}.`; $("#submit-music-btn").attr({ "songiso3": iso3 }); } $("#music-geopol-info").html(geopolMessage).show(); // Make sure we resolve the promise with the data we need resolve({ iso3: iso3, state_code: state.replace(/\s+/g, '_') || "", city_ascii: city || "" }); } } else { geopolMessage = "Our charts only work on land 🏝️ Please double click/tap to choose the location this music was recorded πŸŽ™οΈ"; $("#submit-music-btn").attr("missingGeoloc", "true"); reject("Location not on land"); // Reject with a reason } }) .fail(function(jqXHR, textStatus, errorThrown) { // console.error("Geoapify API error:", textStatus, errorThrown); $("#music-geopol-info").html("Location service temporarily unavailable. We are rate-limited. Please try again in 15+ seconds, and if it fails again, try tomorrow EARLY.").show(); reject(errorThrown || "Geolocation API error"); // Reject with error }); }); } // --- Gets location information --- \\ // --- Set Label of Hive Opt-in/out --- \\ if(Cookies.get('steemOptOut')=='1'){ $("#add-music-steem-opt").html('Post To Hive: Off'); } else { $("#add-music-steem-opt").html('Post To Hive: On'); } $("#add-music-steem-opt").on('click', function() { //--- Set Cookie ---\\ if(Cookies.get('steemOptOut')=='1'){ $("#add-music-steem-opt").html('Post To Hive: On'); Cookies.set('steemOptOut', "0"); } else { $("#add-music-steem-opt").html('Post To Hive: Off'); Cookies.set('steemOptOut', "1"); } }); // === FUNCTIONS === \\ // --- Youtube Validation --- \\ async function validateYouTubeUrl(passed) { var url = passed; if (url != undefined || url != '') { var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/; var match = url.match(regExp); if (match && match[2].length == 11) { // Valid ytSlug = match[2]; // console.log('yt validation passed'); // console.log(match[2]); // Use oEmbed to get video information return new Promise((resolve, reject) => { $.ajax({ method: "get", url: `https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${ytSlug}&format=json`, dataType: "json" }) .done(function(data) { // console.log("YouTube oEmbed data:", data); // oEmbed doesn't directly provide channel ID, but we can store author name // and other available metadata // Try to get channel URL from author_url if available if (data.author_url) { const channelUrlMatch = data.author_url.match(/\/(channel\/[^\/]+|@[^\/]+)/); if (channelUrlMatch && channelUrlMatch[1]) { window.ytChannelf = channelUrlMatch[1].startsWith('@') ? channelUrlMatch[1] : `channel/${channelUrlMatch[1]}`; // console.log("Extracted channel ID/handle:", window.ytChannelf); } else { window.ytChannelf = data.author_url.match(/youtube\.com\/([^\/]+)/)?.[1] || data.author_name || ""; // console.log("Using author URL fallback:", window.ytChannelf); } } else { window.ytChannelf = data.author_name || ""; } resolve(true); }) .fail(function(jqXHR, textStatus, errorThrown) { // console.warn("YouTube oEmbed request failed:", textStatus, errorThrown); // Fall back to YouTube API if oEmbed fails and we haven't hit quota limits $.ajax({ method: "get", url: 'https://www.googleapis.com/youtube/v3/videos', data: { part: "snippet", id: ytSlug, key: "AIzaSyAYhHZlFQ2zEaOFvO7J6xaS7yOAnR45uF4" }, dataType: "json" }) .done(function(resultGoogle) { if (resultGoogle.items && resultGoogle.items.length > 0) { window.ytChannelf = resultGoogle.items[0].snippet.channelId; // console.log("Got channel ID from API:", window.ytChannelf); resolve(true); } else { window.ytChannelf = ""; resolve(true); } }) .fail(function(apiError) { // If both oEmbed and API fail, continue without channel ID // console.warn("Both oEmbed and API failed, continuing without channel ID"); window.ytChannelf = ""; resolve(true); }); }); }); } else { valid = false; // console.log('youtube validation failed'); errors.push("Youtube link is invalid 🧐 You can use youtu.be or youtube.com links."); return Promise.resolve(false); } } else { return Promise.resolve(true); // No YouTube URL provided } } // --- Spotify Validation --- \\ function validateSpotifyUrl(passed) { var url = passed; var regExp = /^.*(spotify:|spotify\.com\/track\/)([^#\&\?]*).*/; var match = url.match(regExp); if (match && match[2].length == 22 ) {// Valid spotSlug = match[2]; // console.log('spotify validation passed'); return true; } else { // Invalid valid = false; // console.log('spotify validation failed'); errors.push("The Spotify link isn't working 😲 Right now, we can only embedd a single track from Spotfy, not an album (even a \"single\" album) πŸš«πŸ’Ώ To add one track, go to the album and click the three dots beside the track name and then click \"copy song link\" 😌 If you're posting an album, you can use the first track, or your favorite single 🎼"); } };// END validateSpotifyUrl, Outputs 'true' // --- SoundCloud Validation --- \\ function validateSoundcloudUrl(passed) { var url = passed; var regExp = /^.*(soundcloud\.com\/)([\w\-\.]+(\/)+[^#\&\?]*).*/; var match = url.match(regExp); if (match && match[2] ) { // Valid scSlug = match[2]; // console.log('SoundCloud validation passed'); return true; } else { // Invalid valid = false; // console.log('Soundcloud validation failed'); errors.push("Something is off with the Soundcloud link"); } } function makeAddMusicMenus() { // --- Add Genre Options --- \\ if ($("#genre option").length == 0) { $("#genre, #correct-genre").append(''); $.each(genreOptions, function(name, description) { if(name != "null"){ $("#genre, #correct-genre").append(''); } else { $("#genre, #correct-genre").append('') } }); } // END if ($("#genre option").length == 0) // --- Add Mood Options --- \\ if ($("#mood option").length == 0) { $("#mood, #correct-mood").append(''); $.each(moodOptions, function(name, description) { if(name != "null"){ $("#mood, #correct-mood").append(''); } else { $("#mood, #correct-mood").append('') } }); } // END if ($("#genre option").length == 0) // --- Add Format Options --- \\ if ($("#format option").length == 0) { $("#format, #correct-format").append(''); $.each(formatOptions, function(name, description) { if(name != "null"){ $("#format, #correct-format").append(''); } else { $("#format, #correct-format").append('') } }); } // END if ($("#genre option").length == 0) } // END function makeAddMusicMenus() /*/ async function getAtomicCollection(atomict){ if (atomict != ''){ $.ajax({ method:"get", url:'https://wax.api.atomicassets.io/atomicassets/v1/templates?', data:{ ids: atomict, page:"1", limit:"100" }, dataType:"json" //async: false }) .done( function (result){ // console.log("check collection", result); // console.log(result.data); if (result.success && result.data.length > 0) { // --- Prepare the Atomic Assets Data --- \\ let col_data = result.data[0]; valid = false; // --- Ensure this is a Music NFT --- \\ col_data.schema.format.forEach(function(field){ if(field.name == "video" || field.name == "audio" ){ valid = true; resolve(col_data.collection.collection_name); } })//END foreach(field) if (!valid){ errors.push("Music NFTs require an audio or video field"); resolve(false); } }else{//API gave back blank resule valid = false; errors.push("Error getting NFT data. Check template id, and try again"); resolve(false); } }).fail(function (){ valid = false; errors.push("We couldn't find your Atomic template"); resolve(false); }) } }//END getAtomicCollection /*/ function getAtomicCollection(atomict) { return new Promise(function(resolve, reject) { if (atomict != '') { $.ajax({ method: "get", url: 'https://wax.api.atomicassets.io/atomicassets/v1/templates?', data: { ids: atomict, page: "1", limit: "100" }, dataType: "json" }) .done(function(result) { // console.log("check collection", result); // console.log(result.data); if (result.success && result.data.length > 0) { let col_data = result.data[0]; let valid = false; col_data.schema.format.forEach(function(field) { if (field.name == "video" || field.name == "audio") { valid = true; resolve(col_data.collection.collection_name); } }); if (!valid) { reject("Music NFTs require an audio or video field"); } } else { reject("Error getting NFT data. Check template id, and try again"); } }) .fail(function() { reject("We couldn't find your Atomic template"); }); } else { reject("Empty atomict provided"); } }); } /*/ atomict = $("#atomict").val(); // --- Match th --- \\ if ($("#format option").length == 0) { $("#format").append(''); $.each(formatOptions, function(name, description) { if(name != "null"){ $("#format").append(''); } else { $("#format").append('') } }); } // END if ($("#genre option").length == 0) /*/ async function sendBluxBoostTransaction(amount) { let mood = $("#mood option:selected").val(); let genre = $("#genre option:selected").val(); let format = $("#format option:selected").val(); const data = { from: window.session.actor?.toString(), to: "creatorsfund", memo: `BOOST πŸ”Ί New ${mood} ${genre} ${format}`, // Special boost memo format quantity: Number(amount) + " BLUX" }; try { const txid = await window.callContractAction('bluxbluxblux', 'transfer', data); return txid; } catch (error) { throw new Error("Boost transaction failed"); } }