fediverse-export-analyzer/public/js/modules/handleUpload.min.js.map

1 wiersz
12 KiB
Plaintext
Czysty Zwykły widok Historia

2023-08-29 23:43:22 +00:00
{"version":3,"file":"handleUpload.min.js","sources":["modules/handleUpload.js"],"sourcesContent":["import sortArrayOfObjects from \"/js/modules/sortArrayOfObjects.min.js\";\r\nimport loadEmbedScript from \"/js/modules/loadEmbedScript.min.js\";\r\nimport Cookie from \"/js/cookies/main.min.js\";\r\n\r\nconst cookieManager = new Cookie();\r\nconst fileInput = document.getElementById(\"file-input\");\r\nconst introElement = document.getElementById(\"intro\");\r\nconst loadingAnimation = document.getElementById(\"loading-animation\");\r\nconst loadingText = document.getElementById(\"loading-text\");\r\nconst resultsElement = document.getElementById(\"results\");\r\nconst userInfo = document.getElementById(\"user-info\");\r\nconst userAvatar = document.getElementById(\"user-avatar\");\r\nconst userDescription = document.getElementById(\"user-description\");\r\nconst userDataBreakdown = document.getElementById(\"user-data-breakdown\");\r\nconst chartElement = document.getElementById(\"chart\");\r\n\r\nconst handleUpload = () => {\r\n if (fileInput) {\r\n fileInput.addEventListener(\"change\", async (ev) => {\r\n loadingAnimation.classList.remove('d-none');\r\n loadingText.classList.remove('d-none');\r\n fileInput.disabled = true;\r\n const formData = new FormData();\r\n formData.set(\"archive\", fileInput.files[0]);\r\n\r\n const resp = await fetch(\"/extract-data\", {\r\n method: \"POST\",\r\n body: formData,\r\n });\r\n\r\n const response = await resp.json();\r\n console.log(response);\r\n\r\n if (response && response.data) {\r\n introElement.classList.add(\"d-none\");\r\n resultsElement.classList.remove(\"d-none\");\r\n const userData = response.data;\r\n\r\n let userDescriptionHTML = '';\r\n let userDataBreakdownHTML = '';\r\n\r\n if (userData.actor){\r\n userDescriptionHTML += `\r\n <p class=\"mb-0\">\r\n <strong>${\r\n userData.actor.name || userData.actor.preferredUsername\r\n }</strong>\r\n </p>\r\n ${userData.actor.summary.replaceAll('class=\"invisible\"', \"\")}\r\n `;\r\n \r\n if (userData.actor.attachment) {\r\n userDescriptionHTML += `\r\n <ul class=\"list-group\">\r\n ${userData.actor.attachment\r\n .map(\r\n (attachment) => `\r\n <li class=\"list-group-item\">${\r\n attachment.name\r\n }: ${attachment.value.replace('class=\"invisible\"', \"\")}</li>\r\n `\r\n )\r\n .join(\"\")}\r\n </ul>\r\n `;\r\n }\r\n \r\n userDescription.innerHTML = `<div>${userDescriptionHTML}</div>`;\r\n userAvatar.innerHTML = `\r\n <img class=\"img-thumbnail\" width=\"64\" height=\"64\" src=\"data:image/jpg;base64,${userData.avatar}\">\r\n `;\r\n } else {\r\n userInfo.remove();\r\n userDescription.remove();\r\n }\r\n\r\n let posts = [],\r\n firstPost,\r\n postCount = 0;\r\n\r\n if (userData?.outbox?.orderedItems) {\r\n posts = userData.outbox.orderedItems;\r\n } else if (userData?.outbox){\r\n posts = userData.outbox; \r\n }\r\n \r\n postCount = posts.length;\r\n if (postCount) {\r\n // posts = sortArrayOfObjects(posts, key, desc)\r\n firstPost = posts[0];\r\n }\r\n const options = {\r\n weekday: \"long\",\r\n year: \"numeric\",\r\n month: \"long\",\r\n day: \"numeric\",\r\n };\r\n\r\n if (userData.actor){\r\n const accountCreationDate = moment(userData.actor.published);\r\n const today = moment();\r\n const timeAgo = today.diff(accountCreationDate, 'days');\r\n \r\n \r\n userDataBreakdownHTML += `\r\n <p>\r\n You created your account on <strong>${new