1/** 2 * Vola API pro zalogovani pouziti Google API. 3 * Vraci true, pokud nebyl prekrocen limit na poctu volani Google API pro dany klic. 4 * @param {"frontend"|"backend"} kind udava, zda jde o frontend nebo backend 5 * @param {"map"|"geocoder"|"street_view"|"addr_suggest"|"addr_detail"} endpoint udava typ Google API sluzby 6 * @param {string|null} googleApiKey klic pro Google API, pokud neni zadan, bude vyhledavat se v DOMu. 7 * @returns {Promise<boolean>} 8 */ 9async function logGoogleApiUsage(kind, endpoint, googleApiKey = null) 10{ 11 function lookupGoogleApiKey() 12 { 13 const domScripts = document.getElementsByTagName("script"); 14 for (const domScript of domScripts) { 15 if (domScript.src.indexOf("maps.google.com/maps/api/js") !== -1) { 16 return domScript.src.match(/key=([^&]+)/)[1]; 17 } 18 } 19 return null; 20 } 21 22 const GOOGLE_API_KEY = googleApiKey === null ? lookupGoogleApiKey() : googleApiKey; 23 if (GOOGLE_API_KEY === null) { 24 console.error("logGoogleApiUsage: Nebyl nalezen Google API klic."); 25 return false; 26 } 27 28 try { 29 const response = await window.fetch('/api/v2/usage/googleapi', { 30 method: "POST", 31 headers: { 32 "Content-Type": "application/json" 33 }, 34 body: JSON.stringify({ 35 api_key: GOOGLE_API_KEY, 36 domain: window.location.hostname, 37 kind: kind, 38 endpoint: endpoint 39 }) 40 }); 41 42 return response.status === 200; 43 } catch (reason) { 44 console.error("logGoogleApiUsage: NepodaÅilo se zalogovat použità Google API.", reason); 45 return false; 46 } 47} 48 49/** 50 * VP: PROVIZORNI RESENI 51 * Notifikuje uzivatele o preteceni limitu na poctu volani Google API. 52 * @param mapSelector {string|HTMLElement} CSS Selecktor pro mapu 53 * @param {"frontend"|"backend"} kind udava, zda jde o frontend nebo backend 54 */ 55function notifyGoogleApiOutOfLimit(mapSelector, kind) 56{ 57 const domMap = typeof mapSelector === "string" ? document.querySelector(mapSelector) 58 : mapSelector; 59 60 if (domMap === null) { 61 console.error(`notifyGoogleApiOutOfLimit: Mapa s CSS selektorem ${mapSelector} nebyla nalezena.`); 62 } else if (domMap instanceof HTMLElement) { 63 domMap.style.background = "#333"; 64 domMap.style.display = "flex"; 65 domMap.style.alignItems = "center"; 66 domMap.style.justifyContent = "center"; 67 domMap.style.color = "white"; 68 domMap.style.fontSize = "24px"; 69 domMap.style.fontWeight = "bold"; 70 domMap.style.minHeight = "120px"; 71 domMap.style.textAlign = "center"; 72 73 const message = kind === "frontend" ? "Nastala technická porucha pÅi naÄÃtánà mapy." 74 : "Byl pÅekroÄen limit služeb Google API."; 75 domMap.innerHTML = `<span>${message}</span>`; 76 } else { 77 console.error(`notifyGoogleApiOutOfLimit: Mapa s CSS selektorem ${mapSelector} neni HTML element.`); 78 } 79}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.