1// The Auth0 client, initialized in configureClient() 2let auth0Client = null; 3 4/** 5 * Starts the authentication flow 6 */ 7const login = async (dataUrl) => { 8 try { 9 const options = { 10 authorizationParams: { 11 redirect_uri: window.location.origin 12 } 13 }; 14 15 if (dataUrl) { 16 options.appState = { dataUrl }; 17 } 18 19 await auth0Client.loginWithRedirect(options); 20 } catch (err) { 21 console.log("Log in failed", err); 22 } 23}; 24 25/** 26 * Executes the logout flow 27 */ 28const logout = async () => { 29 try { 30 await auth0Client.logout({ 31 logoutParams: { 32 returnTo: window.location.origin 33 } 34 }); 35 } catch (err) { 36 console.log("Log out failed", err); 37 } 38}; 39 40/** 41 * Retrieves the auth configuration from the server 42 */ 43//const configURL = "https://shark-supreme-truly.ngrok-free.app/api/v1/get/config/auth_config.json"; 44const fetchAuthConfig = () => fetch("/auth_config.json"); 45 46/** 47 * Initializes the Auth0 client 48 */ 49const configureClient = async () => { 50 const response = await fetchAuthConfig(); 51 const config = await response.json(); 52 53 auth0Client = await auth0.createAuth0Client({ 54 domain: config.domain, 55 clientId: config.clientId, 56 authorizationParams: { 57 audience: config.audience 58 } 59 }); 60}; 61 62/** 63 * Checks to see if the user is authenticated. If so, `fn` is executed. Otherwise, the user 64 * is prompted to log in 65 * @param {*} fn The function to execute if the user is logged in 66 */ 67const requireAuth = async (fn, dataUrl) => { 68 const isAuthenticated = await auth0Client.isAuthenticated(); 69 70 if (isAuthenticated) { 71 return fn(); 72 } 73 74 return login(dataUrl); 75}; 76 77redirectURL = (url) => { 78 window.location.href = url; 79}; 80 81isValidURL = (url) => { 82 try { 83 new URL(url); 84 return true; 85 } catch (_) { 86 return false; 87 } 88} 89 90const callApiGetDataScrap = async (scrub_url, QueryValue) => { 91 try { 92 const token = await auth0Client.getTokenSilently(); 93 const apiUrl = 'https://shark-supreme-truly.ngrok-free.app/api/v1/get/datascrap/basic/scraping'; 94 95 const requestOptions = { 96 method: 'POST', 97 headers: { 98 'Content-Type': 'application/json', 99 'Authorization': `Bearer ${token}` 100 }, 101 body: JSON.stringify({ url: scrub_url, query: QueryValue }) 102 }; 103 104 const response = await fetch(apiUrl, requestOptions); 105 if (!response.ok) { 106 stopProgress(); 107 throw new Error('Network response was not ok ' + response.statusText); 108 } 109 110 const data = await response.json(); 111 stopProgress(); 112 113 114 // Check if current page is index.html 115 if (window.location.pathname.endsWith("index.html") || window.location.pathname === "/") { 116 // Store content in sessionStorage if called from index.html 117 sessionStorage.setItem('fetchedContent', JSON.stringify(data.data)); 118 // Redirect to datascrap.html 119 window.location.href = 'pages/datascrap.html'; 120 } else { 121 // Directly display data if called from datascrap.html 122 if (data.status === "success") { 123 displayData(data.data); 124 } else { 125 displayError(data.data); 126 } 127 } 128 129 } catch (error) { 130 console.error("Error:", error); 131 stopProgress(); 132 // Handle error display in current page 133 } 134}; 135 136const callApiCheckUser = async () => { 137 try { 138 const token = await auth0Client.getTokenSilently(); 139 const apiUrl = 'https://shark-supreme-truly.ngrok-free.app/api/v1/get/datascrap/basic/check-user'; 140 141 const requestOptions = { 142 method: 'POST', 143 headers: { 144 'Authorization': `Bearer ${token}` 145 }, 146 }; 147 148 const response = await fetch(apiUrl, requestOptions); 149 if (!response.ok) { 150 throw new Error('Network response was not ok ' + response.statusText); 151 } 152 153 const data = await response.json(); 154 return data; 155 } catch (error) { 156 console.error("Error:", error); 157 stopProgress(); 158 // Handle error display in current page 159 } 160}; 161 162const displayData = (data) => { 163 document.getElementById('content-display-window').style.display = 'block'; 164 document.getElementById('url-content-icon').style.display = 'block'; 165 document.getElementById('url-error-icon').style.display = 'none'; 166 document.getElementById('url-content-title').innerHTML = "DataScrap Result"; 167 document.getElementById('url-content-string').innerHTML = data 168 ? marked.parse(data.data) 169 : "No data found"; 170} 171 172const displayError = (data) => { 173 document.getElementById('content-display-window').style.display = 'block'; 174 document.getElementById('url-content-icon').style.display = 'none'; 175 document.getElementById('url-error-icon').style.display = 'block'; 176 document.getElementById('url-content-title').innerHTML = "Error"; 177 document.getElementById('url-content-string').innerHTML = data.data; 178} 179 180const callApiSubmitFeedback = async (url, feedback) => { 181 try { 182 const token = await auth0Client.getTokenSilently();
183 //const apiUrl = 'http://192.168.150.198:8096/api/v1/get/datascrap/basic/scrapping'; // Replace with your API URL 184 const apiUrl = 'https://shark-supreme-truly.ngrok-free.app/api/v1/get/datascrap/feedback'; // Replace with your API URL 185 186 const isAuthenticated = await auth0Client.isAuthenticated(); 187 var email = ""; 188 if (isAuthenticated) { 189 const user = await auth0Client.getUser(); 190 email = user.email; 191 } 192 193 // Set up request options (method, headers, etc.) 194 const requestOptions = { 195 method: 'POST', // or 'POST', 'PUT', etc. 196 headers: { 197 'Content-Type': 'application/json', 198 'Authorization': `Bearer ${token}` // Replace with your API token if needed 199 }, 200 body: JSON.stringify({ 201 email: email, 202 url: url, 203 feedback: feedback 204 // Add any key-value pairs you need to send in the POST body 205 }) 206 }; 207 208 // Make the API request 209 const response = await fetch(apiUrl, requestOptions); 210 211 if (!response.ok) { 212 throw new Error('Network response was not ok ' + response.statusText); 213 } 214 } catch (error) { 215 console.error("Error:", error); 216 } 217}; 218 219
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.