mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-08-11 07:41:17 +02:00
Guard no-JS file uploads: disabled filepond_mode by default, server-side fallback
The partage/admin form had a hardcoded filepond_mode=1 hidden input, so without JavaScript the server always entered the FilePond async path — which found no hex IDs and silently dropped all files. Three-layer fix: 1. HTML: filepond_mode input starts disabled with value=0; JS enables it and sets value=1 on DOMContentLoaded (and after HTMX swaps). Disabled inputs aren't submitted → server gets no filepond_mode → naturally falls to legacy path. 2. JS: enableFilepondMode() called on page load and hx:afterSwap so FilePond-enhanced forms always send filepond_mode=1. 3. Server (defense-in-depth): ThesisFileHandler::hasFilePondQueueData() scans POST['queue_file'] for 32-char hex IDs; ThesisCreateController and ThesisEditController use it alongside filepond_mode, so even if the flag somehow arrives without async upload IDs, the path takes over.
This commit is contained in:
@@ -359,8 +359,12 @@ class ThesisEditController
|
||||
mkdir($dirAbs, 0755, true);
|
||||
}
|
||||
|
||||
// Determine upload path: FilePond async (JS enabled, hex IDs present)
|
||||
// vs. legacy multipart. Defense-in-depth fallback for no-JS scenarios.
|
||||
$useFilePond = !empty($post['filepond_mode']) && $this->hasFilePondQueueData($post);
|
||||
|
||||
// ── Cover image (outside transaction — filesystem op) ─────────────────
|
||||
if (!empty($post['filepond_mode'])) {
|
||||
if ($useFilePond) {
|
||||
// Delete old cover only if a genuinely new cover was uploaded (hex file_id).
|
||||
// Existing cover preserved in FilePond sends its DB integer ID — skip.
|
||||
$coverIdRaw = ($post['queue_file']['cover'] ?? null);
|
||||
@@ -387,7 +391,7 @@ class ThesisEditController
|
||||
}
|
||||
|
||||
// ── Note d'intention (replace if uploaded) ────────────────────────────
|
||||
if (!empty($post['filepond_mode'])) {
|
||||
if ($useFilePond) {
|
||||
// Only delete + replace if a genuinely new file was uploaded (hex file_id).
|
||||
// Existing files preserved in the FilePond pool send their DB integer ID;
|
||||
// we must NOT delete them — they're already stored.
|
||||
@@ -454,7 +458,7 @@ class ThesisEditController
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($post['filepond_mode'])) {
|
||||
if ($useFilePond) {
|
||||
// New path: files already on server via async FilePond uploads
|
||||
$nextNum = $tfeCount + 1;
|
||||
$nextNum = $this->handleFilePondQueueFiles($thesisId, $post, 'tfe', $folderPath, $filePrefix, $nextNum);
|
||||
|
||||
Reference in New Issue
Block a user