This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/main by this push:
new 0cf4e74 Fix linting errors in the script for announcement previews
0cf4e74 is described below
commit 0cf4e74eac7778a217d9712c17800bd2ce076052
Author: Sean B. Palmer <[email protected]>
AuthorDate: Thu Dec 11 16:53:54 2025 +0000
Fix linting errors in the script for announcement previews
---
atr/static/js/src/announce-preview.js | 153 +++++++++++++++++++---------------
1 file changed, 87 insertions(+), 66 deletions(-)
diff --git a/atr/static/js/src/announce-preview.js
b/atr/static/js/src/announce-preview.js
index ea387cb..96ea4c4 100644
--- a/atr/static/js/src/announce-preview.js
+++ b/atr/static/js/src/announce-preview.js
@@ -1,4 +1,40 @@
-document.addEventListener("DOMContentLoaded", () => {
+function fetchAnnouncePreview(
+ previewUrl,
+ csrfToken,
+ bodyTextarea,
+ textPreviewContent,
+) {
+ const bodyContent = bodyTextarea.value;
+
+ fetch(previewUrl, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ "X-CSRFToken": csrfToken,
+ },
+ body: new URLSearchParams({
+ body: bodyContent,
+ csrf_token: csrfToken,
+ }),
+ })
+ .then((response) => {
+ if (!response.ok) {
+ return response.text().then((text) => {
+ throw new Error(`HTTP error
${response.status}: ${text}`);
+ });
+ }
+ return response.text();
+ })
+ .then((previewText) => {
+ textPreviewContent.textContent = previewText;
+ })
+ .catch((error) => {
+ console.error("Error fetching email preview:", error);
+ textPreviewContent.textContent = `Error loading
preview:\n${error.message}`;
+ });
+}
+
+function initAnnouncePreview() {
let debounceTimeout;
const debounceDelay = 500;
@@ -25,83 +61,68 @@ document.addEventListener("DOMContentLoaded", () => {
}
const csrfToken = csrfTokenInput.value;
- function fetchAndUpdateAnnouncePreview() {
- const bodyContent = bodyTextarea.value;
-
- fetch(previewUrl, {
- method: "POST",
- headers: {
- "Content-Type":
"application/x-www-form-urlencoded",
- "X-CSRFToken": csrfToken,
- },
- body: new URLSearchParams({
- body: bodyContent,
- csrf_token: csrfToken,
- }),
- })
- .then((response) => {
- if (!response.ok) {
- return response.text().then((text) => {
- throw new Error(`HTTP error
${response.status}: ${text}`);
- });
- }
- return response.text();
- })
- .then((previewText) => {
- textPreviewContent.textContent = previewText;
- })
- .catch((error) => {
- console.error("Error fetching email preview:",
error);
- textPreviewContent.textContent = `Error loading
preview:\n${error.message}`;
- });
- }
+ const doFetch = () =>
+ fetchAnnouncePreview(
+ previewUrl,
+ csrfToken,
+ bodyTextarea,
+ textPreviewContent,
+ );
bodyTextarea.addEventListener("input", () => {
clearTimeout(debounceTimeout);
- debounceTimeout = setTimeout(fetchAndUpdateAnnouncePreview,
debounceDelay);
+ debounceTimeout = setTimeout(doFetch, debounceDelay);
});
- fetchAndUpdateAnnouncePreview();
+ doFetch();
+}
- // Download path suffix validation
+function initDownloadPathValidation() {
const pathInput = document.getElementById("download_path_suffix");
const pathHelpText = pathInput
? pathInput.parentElement.querySelector(".form-text")
: null;
- if (pathInput && pathHelpText) {
- const baseText = pathHelpText.dataset.baseText || "";
- let pathDebounce;
+ if (!pathInput || !pathHelpText) {
+ return;
+ }
- function updatePathHelpText() {
- let suffix = pathInput.value;
- if (suffix.includes("..") || suffix.includes("//")) {
- pathHelpText.textContent =
- "Download path suffix must not contain
.. or //";
- return;
- }
- if (suffix.startsWith("./")) {
- suffix = suffix.substring(1);
- } else if (suffix === ".") {
- suffix = "/";
- }
- if (!suffix.startsWith("/")) {
- suffix = "/" + suffix;
- }
- if (!suffix.endsWith("/")) {
- suffix = suffix + "/";
- }
- if (suffix.includes("/.")) {
- pathHelpText.textContent = "Download path
suffix must not contain /.";
- return;
- }
- pathHelpText.textContent = baseText + suffix;
+ const baseText = pathHelpText.dataset.baseText || "";
+ let pathDebounce;
+
+ const updatePathHelpText = () => {
+ let suffix = pathInput.value;
+ if (suffix.includes("..") || suffix.includes("//")) {
+ pathHelpText.textContent =
+ "Download path suffix must not contain .. or
//";
+ return;
+ }
+ if (suffix.startsWith("./")) {
+ suffix = suffix.slice(1);
+ } else if (suffix === ".") {
+ suffix = "/";
+ }
+ if (!suffix.startsWith("/")) {
+ suffix = `/${suffix}`;
}
+ if (!suffix.endsWith("/")) {
+ suffix = `${suffix}/`;
+ }
+ if (suffix.includes("/.")) {
+ pathHelpText.textContent = "Download path suffix must
not contain /.";
+ return;
+ }
+ pathHelpText.textContent = baseText + suffix;
+ };
- pathInput.addEventListener("input", () => {
- clearTimeout(pathDebounce);
- pathDebounce = setTimeout(updatePathHelpText, 10);
- });
- updatePathHelpText();
- }
+ pathInput.addEventListener("input", () => {
+ clearTimeout(pathDebounce);
+ pathDebounce = setTimeout(updatePathHelpText, 10);
+ });
+ updatePathHelpText();
+}
+
+document.addEventListener("DOMContentLoaded", () => {
+ initAnnouncePreview();
+ initDownloadPathValidation();
});
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]