PageSourceSearch

https://ezspeech.ai/static/main/js/logErrors.js?v=1

js ezspeech.ai collected 2026-10-05 13:56:24 UTC 4,561 bytes, 132 lines download raw bytes

1document.addEventListener("DOMContentLoaded", function () {
2  const fileInput = document.getElementById("fileInput");
3  const errorLog = []; // Массив для хранения ошибок
4  const imagePreview = document.getElementById("imagePreview");
5  let messageFromUser = document.getElementById("message-description");
6  document
7    .getElementById("sendMessageFromUser")
8    .addEventListener("click", function () {
9      if (messageFromUser.value === "") {
10        document.querySelector(".error-description").classList.remove("d-none");
11        return;
12      }
13      document.querySelector(".error-description").classList.add("d-none");
14      logUserBugreport();
15    });
16
17  fileInput.addEventListener("change", function () {
18    imagePreview.innerHTML = ""; // Очищаем предыдущий просмотр изображений
19
20    for (const file of fileInput.files) {
21      if (file.type.startsWith("image/")) {
22        const image = document.createElement("img");
23        image.src = URL.createObjectURL(file);
24        image.className = "preview-image";
25        imagePreview.appendChild(image);
26      }
27    }
28  });
29
30  // Перехватываем ошибки и вызываем функцию logError
31  window.addEventListener("error", function (event) {
32    logError(event.error);
33    captureConsoleErrors(event.error);
34  });
35
36  function getDateFormatted() {
37    const now = new Date();
38    const year = now.getUTCFullYear();
39    const month = (now.getUTCMonth() + 1).toString().padStart(2, "0"); // +1, так как месяцы начинаются с 0
40    const day = now.getUTCDate().toString().padStart(2, "0");
41    const hours = now.getUTCHours().toString().padStart(2, "0");
42    const minutes = now.getUTCMinutes().toString().padStart(2, "0");
43
44    const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}`;
45
46    return formattedDate;
47  }
48
49  function logError(error) {
50    // Отправить ошибку на сервер
51    fetch("/api/log_frontend_error", {
52      method: "POST",
53      headers: {
54        "Content-Type": "application/json",
55        "X-CSRFToken": $.cookie("csrftoken"),
56      },
57      body: JSON.stringify({
58        error: error.message,
59        stack: error.stack,
60        date: getDateFormatted(),
61        user: USER_ID,
62      }),
63    });
64  }
65
66  function logUserBugreport() {
67    const selectedFiles = Array.from(fileInput.files);
68    generateBase64Images(selectedFiles)
69      .then((base64Images) => {
70        const requestData = {
71          images: base64Images,
72          errors: errorLog,
73          date: getDateFormatted(),
74          user: USER_ID,
75          message_from_user: messageFromUser.value,
76        };
77        fetch("/api/log_user_bugreport", {
78          method: "POST",
79          headers: {
80            "Content-Type": "application/json",
81            "X-CSRFToken": $.cookie("csrftoken"),
82          },
83          body: JSON.stringify(requestData),
84        })
85          .then((response) => {
86            if (!response.ok) {
87              throw new Error(`HTTP error! Status: ${response.status}`);
88            }
89            return response.json();
90          })
91          .then((data) => {
92            const feedbackMessageElement =
93              document.getElementById("number-message");
94            feedbackMessageElement.textContent = data.id;
95            let popup = document.getElementById("popup-end-send-messaage");
96            popupOpen(popup);
97          })
98          .catch((error) => {
99            console.error("Error:", error);
100          });
101      })
102      .catch((error) => {
103        console.error("Error:", error);
104      });
105  }
106
107  function generateBase64Images(selectedFiles) {
108    const base64Images = [];
109    if (selectedFiles.length === 0) return Promise.resolve(base64Images);
110    const promises = selectedFiles.map((file) => {
111      return new Promise((resolve) => {
112        const reader = new FileReader();
113        reader.readAsDataURL(file);
114        reader.onload = function () {
115          resolve({ image: reader.result });
116        };
117      });
118    });
119
120    return Promise.all(promises);
121  }
122
123  // Функция для перехвата ошибок и добавления их в массив
124  function captureConsoleErrors(error) {
125    // Добавляем ошибку в массив
126    errorLog.push({
127      date: getDateFormatted(),
128      stack: error.stack,
129      error: error.message,
130    });
131  }
132});

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.