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,WAAW,CAAC;QAClD,iEAAiE;QACjE,IAAI,GAAG,GACP,4CAA4C,CAAC;QAC7C,2BAA2B;QAC3B,IAAI,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;QAC5B,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,WAAW,EAAE,CAAC,CAAC;QACzD,IAAI,OAAO,GAAG;YACZ,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,OAAO;SACjB,CAAC;QACF,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC;aAChB,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,EAAE;YAC7D,gCAAgC;YAChC,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAClC,OAAO,CAAC,KAAK,CACX,yCAAyC,CAC1C,CAAC;gBACF,OAAO,IAAI,CAAC;YACd,CAAC;YACD,iCAAiC;YACjC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;YACpD,YAAY,CAAC,OAAO,CAAC,qBAAqB,EAAE,UAAU,CAAC,CAAC;QAC1D,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC;SACD,KAAK,CAAC,UAAU,KAAK;QACpB,oCAAoC;QACpC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;AACP,CAAC","file":"authRedirect.js","sourcesContent":["const dayToolMSALObj = new msal.PublicClientApplication(msalConfig);\nconst calendarApiURL = 'https://graph.microsoft.com/v1.0/me/calendar/events';\n\nfunction microsoftUploadDayToolBackUp() {\n // Setup payload\n // Get the current date\n var currentDate = new Date();\n var formattedDate = currentDate.toISOString().split(\"T\")[0]; // Format as YYYY-MM-DD\n // Set the file name\n var fileName = `${formattedDate}.${currentDate.getTime()}.daytool.json`;\n\n var url = `https://graph.microsoft.com/v1.0/me/drive/root:/${fileName}:/content`;\n\n var localStorageData = localStorage.getItem(\"DAYTOOL\");\n if (!localStorageData) {\n console.error(\"No data found in localStorage DAYTOOL.\");\n return;\n }\n\n var jsonData = JSON.parse(localStorageData);\n var jsonString = JSON.stringify(jsonData);\n\n var account = dayToolMSALObj.getAllAccounts()[0];\n\n /**\n * Add here the scopes to request when obtaining an access token for MS Graph API. For more information, see:\n * https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/resources-and-scopes.md\n */\n var tokenRequest = {\n scopes: [\n \"openid\",\n \"profile\",\n \"User.Read\",\n \"Files.ReadWrite\",\n \"Files.ReadWrite.AppFolder\",\n ],\n account: account,\n forceRefresh: true, // Set this to \"true\" to skip a cached token and go to the server to get a new token\n };\n\n dayToolMSALObj\n .acquireTokenPopup(tokenRequest)\n .then(function (accessTokenResponse) {\n // Acquire token interactive success\n let accessToken = accessTokenResponse.accessToken;\n // Call your API with token\n // Call your API with token\n var headers = new Headers();\n headers.append(\"Authorization\", `Bearer ${accessToken}`);\n headers.append(\"Content-Type\", \"application/json\");\n fetch(url, {\n method: \"PUT\",\n headers,\n body: jsonString,\n })\n .then((response) => response.json())\n .then(function (result) {\n // Complete last upload record\n console.log(result);\n var upload_record = DAYTOOL.metadata.history.uploads.at(-1);\n upload_record.id = result.id;\n upload_record.name = result.name;\n upload_record.storage_provider_id = 1;\n upload_record.uploaded = true;\n DAYTOOL.metadata.history.upload_timestamps.push(new Date().getTime());\n\n var new_upload_record = new daytool_upload();\n DAYTOOL.metadata.history.uploads.push(new_upload_record);\n DAYTOOL.saveToLocalStorage();\n })\n .catch(function (error) {\n // Acquire token interactive failure\n console.log(error);\n });\n })\n .catch(function (error) {\n // Acquire token interactive failure\n console.log(error);\n });\n}\n\n// Function to get the latest file from Microsoft OneDrive and store it in localStorage\nfunction microsoftReturnLatest() {\n var account = dayToolMSALObj.getAllAccounts()[0];\n /**\n * Add here the scopes to request when obtaining an access token for MS Graph API. For more information, see:\n * https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/resources-and-scopes.md\n */\n var tokenRequest = {\n scopes: [\n \"openid\",\n \"profile\",\n \"User.Read\",\n \"Files.ReadWrite\",\n \"Files.ReadWrite.AppFolder\",\n ],\n account: account,\n forceRefresh: true, // Set this to \"true\" to skip a cached token and go to the server to get a new token\n };\n\n dayToolMSALObj\n .acquireTokenPopup(tokenRequest)\n .then(function (accessTokenResponse) {\n // Acquire token interactive success\n let accessToken = accessTokenResponse.accessToken;\n // Make a request to Microsoft Graph API to get the list of files\n var url =\n \"https://graph.microsoft.com/v1.0/me/drive/root/search(q='.daytool.json')\";\n // Call your API with token\n var headers = new Headers();\n headers.append(\"Authorization\", `Bearer ${accessToken}`);\n var options = {\n method: \"GET\",\n headers: headers,\n };\n fetch(url, options)\n .then((response) => response.json()).then((downloadResponse) => {\n // Check if any files were found\n if (downloadResponse.value.length === 0) {\n console.error(\n 'No \"daytool_.json\" files found in Microsoft OneDrive.'\n );\n return null;\n }\n // Get the latest file's metadata\n var latestFileMetadata = downloadResponse.value[0];\n fetch(\n `${latestFileMetadata[\"@microsoft.graph.downloadUrl\"]}`,\n options\n ).then((response) => response.json()).then((downloaded_file) => {\n console.log(downloaded_file);\n // Store the content in the localStorage DAYTOOL\n localStorage.setItem(\"DAYTOOL\", JSON.stringify(downloaded_file));\n }).catch((error) => console.log(error));\n\n })\n .catch((error) => console.log(error));\n })\n .catch(function (error) {\n // Acquire token interactive failure\n console.log(error);\n });\n}\n\n// Function to get the latest file from Microsoft OneDrive and store it in localStorage\nasync function microsoftReturnCalendars() {\n var account = dayToolMSALObj.getAllAccounts()[0];\n\n /**\n * Add here the scopes to request when obtaining an access token for MS Graph API. For more information, see:\n * https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/resources-and-scopes.md\n */\n var tokenRequest = {\n scopes: [\n \"openid\",\n \"profile\",\n \"User.Read\",\n \"Calendars.ReadWrite\",\n ],\n account: account,\n forceRefresh: true, // Set this to \"true\" to skip a cached token and go to the server to get a new token\n };\n\n dayToolMSALObj\n .acquireTokenPopup(tokenRequest)\n .then(function (accessTokenResponse) {\n // Acquire token interactive success\n let accessToken = accessTokenResponse.accessToken;\n // Make a request to Microsoft Graph API to get the list of files\n var url =\n 'https://graph.microsoft.com/v1.0/me/events';\n // Call your API with token\n var headers = new Headers();\n headers.append(\"Authorization\", `Bearer ${accessToken}`);\n var options = {\n method: \"GET\",\n headers: headers,\n };\n fetch(url, options)\n .then((response) => response.json()).then((downloadResponse) => {\n // Check if any files were found\n if (downloadResponse.length === 0) {\n console.error(\n 'No Events found in Microsoft Calendars.'\n );\n return null;\n }\n // Get the latest file's metadata\n const dataString = JSON.stringify(downloadResponse);\n localStorage.setItem('MICROSOFT_CALENDARS', dataString);\n })\n .catch((error) => console.log(error));\n })\n .catch(function (error) {\n // Acquire token interactive failure\n console.log(error);\n });\n}\n"]}