feat(js): harden global HTTP and module import contracts

This commit is contained in:
2026-04-20 22:41:07 +02:00
parent f189ef9df6
commit 7c47e818f2
12 changed files with 181 additions and 266 deletions

View File

@@ -3,6 +3,7 @@
* Supports slide-out animation and hover-pause.
*/
import { resolveHost } from '../core/app-dom.js';
import { postForm as postFormRequest } from '../core/app-http.js';
export function initFlashAutoDismiss(root = document, options = {}) {
const {
@@ -32,17 +33,14 @@ export function initFlashAutoDismiss(root = document, options = {}) {
const postForm = async (form) => {
const action = form.getAttribute('action');
if (!action) {
return null;
return false;
}
try {
await postFormRequest(action, new FormData(form));
return true;
} catch {
return false;
}
const body = new URLSearchParams(new FormData(form));
return fetch(action, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'fetch',
},
body,
});
};
notices.forEach((notice) => {
@@ -62,8 +60,8 @@ export function initFlashAutoDismiss(root = document, options = {}) {
}
const form = notice.querySelector('form');
if (form) {
const response = await postForm(form);
if (!response || !response.ok) {
const ok = await postForm(form);
if (!ok) {
return;
}
}
@@ -80,8 +78,8 @@ export function initFlashAutoDismiss(root = document, options = {}) {
if (destroyed) return;
const form = notice.querySelector('form');
if (form) {
const response = await postForm(form);
if (!response || !response.ok) return;
const ok = await postForm(form);
if (!ok) return;
}
dismissNotice(notice);
}, 1000);