diff --git a/scripts/patch-endpoint-files-upload-route.mjs b/scripts/patch-endpoint-files-upload-route.mjs index 86b4543d..68620d21 100644 --- a/scripts/patch-endpoint-files-upload-route.mjs +++ b/scripts/patch-endpoint-files-upload-route.mjs @@ -8,6 +8,34 @@ const candidates = [ const oldCode = "xhr.open('POST', endpoint);"; const newCode = "xhr.open('POST', window.location.pathname);"; +const textFallbackPatches = [ + { + from: '{{ __("files.upload.dropText") }}', + to: '{{ __("files.upload.dropText") == "files.upload.dropText" and "Drag files here or" or __("files.upload.dropText") }}', + }, + { + from: '{{ __("files.upload.browse") }}', + to: '{{ __("files.upload.browse") == "files.upload.browse" and "Browse files" or __("files.upload.browse") }}', + }, + { + from: '{{ __("files.upload.submitMultiple") }}', + to: '{{ __("files.upload.submitMultiple") == "files.upload.submitMultiple" and "Upload files" or __("files.upload.submitMultiple") }}', + }, +]; + +const fallbackSubmitBlock = ` {# Reliable fallback submit (works even when Alpine/XHR upload is unavailable) #} +
+ {{ button({ + text: __("files.form.submit"), + attributes: { + type: "submit", + formenctype: "multipart/form-data", + "x-show": "files.length === 0 || allDone" + } + }) }} +
+`; + async function exists(path) { try { await access(path); @@ -27,16 +55,33 @@ for (const filePath of candidates) { checked += 1; const source = await readFile(filePath, "utf8"); + let updated = source; + let changed = false; - if (source.includes(newCode)) { + if (updated.includes(oldCode)) { + updated = updated.replace(oldCode, newCode); + changed = true; + } + + for (const patch of textFallbackPatches) { + if (updated.includes(patch.from) && !updated.includes(patch.to)) { + updated = updated.replace(patch.from, patch.to); + changed = true; + } + } + + if (updated.includes("