mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-08-11 07:41:17 +02:00
filepond: implement async server-ID upload architecture with nested queue support + PeerTube integration
Replace `storeAsFile:true` with a full async FilePond round-trip pipeline using opaque server-side file IDs.
* Added 4 new PHP endpoints under `/admin/actions/filepond/`:
* `process.php` — upload/process single file and return opaque `file_id`
* `revert.php` — delete pending tmp uploads before form submit
* `load.php` — stream existing files by DB ID for FilePond preload
* `remove.php` — soft-delete `thesis_files` rows
* `process.php` improvements:
* accept arbitrary FilePond field names instead of hardcoded `file`
* support PHP-nested multi-file queue inputs (`queue_file[tfe][]`)
* explicit unwrapping of nested `$_FILES` structures
* add `audio/mp3` to audio + `peertube_audio` MIME whitelists
* immediate upload of `peertube_*` files to PeerTube, returning `peertube:{uuid}` IDs
* extensive `error_log()` instrumentation for request, CSRF, MIME, upload, and save stages
* `revert.php` now accepts `peertube:` IDs without local cleanup
* `ThesisFileHandler`:
* add `handleFilePondQueueFiles()` + `handleFilePondSingleFile()`
* process async uploads from `storage/tmp/filepond/` via opaque `file_id`
* inline handling of `peertube:{uuid}` IDs with direct `thesis_files` insertion
* remove obsolete deferred PeerTube queue-processing flow
* `ThesisCreateController` + `ThesisEditController`:
* gate async path behind `filepond_mode=1`
* preserve legacy multipart flow as fallback
* `file-upload-filepond.js`:
* remove `storeAsFile:true`
* add `buildServerConfig()` for async endpoint wiring
* fix `syncOrderInput()` to use `serverId`
* add `onprocessfile` hook
* add `fileValidateSizeFilterItem` for per-extension size caps
* preload existing uploads via `data-existing-files` + `server.load`
* replace static `INPUT_ID_TO_TYPE` map with `data-queue-type`
* add extensive `console.log()` debugging across upload pipeline stages
* `upload-progress.js`:
* block form submission while uploads are pending
* update `collectFileNames()` to read processed FilePond items
* Templates/layout:
* add `data-queue-type`
* add `data-existing-files`
* add global CSRF meta tag outside admin-only context
* add `filepond_mode` hidden input
* add CSRF token/meta support for partage pages
* move website URL field below file upload block
* `.gitignore`: exclude `storage/tmp/` from version control
This commit is contained in:
@@ -340,7 +340,24 @@ class ThesisEditController
|
||||
}
|
||||
|
||||
// ── Cover image (outside transaction — filesystem op) ─────────────────
|
||||
if (!empty($post['remove_cover'])) {
|
||||
if (!empty($post['filepond_mode'])) {
|
||||
// Async path: cover file_id arrives in post, not $_FILES
|
||||
if (!empty($post['remove_cover'])) {
|
||||
foreach ($existingFiles as $f) {
|
||||
if ($f['file_type'] === 'cover') {
|
||||
$this->db->deleteThesisFile((int)$f['id'], $thesisId);
|
||||
if (!empty($f['file_path']) && defined('STORAGE_ROOT')) {
|
||||
$abs = STORAGE_ROOT . '/' . $f['file_path'];
|
||||
if (file_exists($abs)) {
|
||||
@unlink($abs);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->handleFilePondSingleFile($thesisId, $post, 'cover', $folderPath, $filePrefix);
|
||||
} elseif (!empty($post['remove_cover'])) {
|
||||
foreach ($existingFiles as $f) {
|
||||
if ($f['file_type'] === 'cover') {
|
||||
$this->db->deleteThesisFile((int)$f['id'], $thesisId);
|
||||
@@ -358,22 +375,43 @@ class ThesisEditController
|
||||
}
|
||||
|
||||
// ── Note d'intention (replace if uploaded) ────────────────────────────
|
||||
// Remove old note_intention row+file if new one is uploaded
|
||||
if (!empty($files['note_intention']['tmp_name'] ?? null) && ($files['note_intention']['error'] ?? -1) === UPLOAD_ERR_OK) {
|
||||
foreach ($existingFiles as $f) {
|
||||
if ($f['file_type'] === 'note_intention') {
|
||||
$this->db->deleteThesisFile((int)$f['id'], $thesisId);
|
||||
if (!empty($f['file_path']) && defined('STORAGE_ROOT')) {
|
||||
$abs = STORAGE_ROOT . '/' . $f['file_path'];
|
||||
if (file_exists($abs)) {
|
||||
@unlink($abs);
|
||||
if (!empty($post['filepond_mode'])) {
|
||||
// Remove old note_intention if new one is uploaded via async path
|
||||
$newNoteId = ($post['queue_file']['note_intention'] ?? null);
|
||||
$hasNewNote = $newNoteId !== null && (is_array($newNoteId) ? !empty($newNoteId) : $newNoteId !== '');
|
||||
if ($hasNewNote) {
|
||||
foreach ($existingFiles as $f) {
|
||||
if ($f['file_type'] === 'note_intention') {
|
||||
$this->db->deleteThesisFile((int)$f['id'], $thesisId);
|
||||
if (!empty($f['file_path']) && defined('STORAGE_ROOT')) {
|
||||
$abs = STORAGE_ROOT . '/' . $f['file_path'];
|
||||
if (file_exists($abs)) {
|
||||
@unlink($abs);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->handleFilePondSingleFile($thesisId, $post, 'note_intention', $folderPath, $filePrefix);
|
||||
} else {
|
||||
// Legacy path
|
||||
if (!empty($files['note_intention']['tmp_name'] ?? null) && ($files['note_intention']['error'] ?? -1) === UPLOAD_ERR_OK) {
|
||||
foreach ($existingFiles as $f) {
|
||||
if ($f['file_type'] === 'note_intention') {
|
||||
$this->db->deleteThesisFile((int)$f['id'], $thesisId);
|
||||
if (!empty($f['file_path']) && defined('STORAGE_ROOT')) {
|
||||
$abs = STORAGE_ROOT . '/' . $f['file_path'];
|
||||
if (file_exists($abs)) {
|
||||
@unlink($abs);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->handleNoteIntentionUpload($thesisId, $files['note_intention'] ?? null, $folderPath, $filePrefix);
|
||||
}
|
||||
$this->handleNoteIntentionUpload($thesisId, $files['note_intention'] ?? null, $folderPath, $filePrefix);
|
||||
|
||||
// ── Delete individual thesis files ────────────────────────────────────
|
||||
$deleteIds = isset($post['delete_files']) && is_array($post['delete_files'])
|
||||
@@ -411,38 +449,52 @@ class ThesisEditController
|
||||
}
|
||||
}
|
||||
|
||||
// ── New TFE/video/audio files upload (from client-side JS queue) ──
|
||||
$queueFiles = $files['queue_file'] ?? [];
|
||||
$qTfe = $this->extractFilesSubArray($queueFiles, 'tfe');
|
||||
$qVideo = $this->extractFilesSubArray($queueFiles, 'video');
|
||||
$qAudio = $this->extractFilesSubArray($queueFiles, 'audio');
|
||||
$qAnnexe = $this->extractFilesSubArray($queueFiles, 'annexe');
|
||||
|
||||
// ── New TFE/video/audio files upload (choose path based on filepond_mode)
|
||||
// Count existing TFE files (not cover, note_intention, website, annex, caption, PeerTube)
|
||||
$tfeCount = 0;
|
||||
foreach ($existingFiles as $f) {
|
||||
if (!in_array($f['file_type'] ?? '', ['cover', 'note_intention', 'website', 'annex', 'caption'], true)
|
||||
&& !str_starts_with($f['file_path'] ?? '', 'http')) {
|
||||
&& !str_starts_with($f['file_path'] ?? '', 'http')
|
||||
&& !str_starts_with($f['file_path'] ?? '', 'peertube_ids:')) {
|
||||
$tfeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$startNum = $tfeCount + 1;
|
||||
$startNum = $this->handleTfeQueueFiles($thesisId, $qTfe, $folderPath, $filePrefix, $startNum);
|
||||
$startNum = $this->handleTfeQueueFiles($thesisId, $qVideo, $folderPath, $filePrefix, $startNum);
|
||||
$this->handleTfeQueueFiles($thesisId, $qAudio, $folderPath, $filePrefix, $startNum);
|
||||
$this->handleAnnexeQueueFiles($thesisId, $qAnnexe, $folderPath, $filePrefix);
|
||||
if (!empty($post['filepond_mode'])) {
|
||||
// New path: files already on server via async FilePond uploads
|
||||
$nextNum = $tfeCount + 1;
|
||||
$nextNum = $this->handleFilePondQueueFiles($thesisId, $post, 'tfe', $folderPath, $filePrefix, $nextNum);
|
||||
$nextNum = $this->handleFilePondQueueFiles($thesisId, $post, 'video', $folderPath, $filePrefix, $nextNum);
|
||||
$this->handleFilePondQueueFiles($thesisId, $post, 'audio', $folderPath, $filePrefix, $nextNum);
|
||||
$this->handleFilePondQueueFiles($thesisId, $post, 'annexe', $folderPath, $filePrefix, 0);
|
||||
$this->handleFilePondQueueFiles($thesisId, $post, 'peertube_video', $folderPath, $filePrefix, 0, $progressToken);
|
||||
$this->handleFilePondQueueFiles($thesisId, $post, 'peertube_audio', $folderPath, $filePrefix, 0, $progressToken);
|
||||
} else {
|
||||
// Legacy path: files arrive via multipart $_FILES
|
||||
$queueFiles = $files['queue_file'] ?? [];
|
||||
$qTfe = $this->extractFilesSubArray($queueFiles, 'tfe');
|
||||
$qVideo = $this->extractFilesSubArray($queueFiles, 'video');
|
||||
$qAudio = $this->extractFilesSubArray($queueFiles, 'audio');
|
||||
$qAnnexe = $this->extractFilesSubArray($queueFiles, 'annexe');
|
||||
|
||||
// Legacy annexe files (direct upload, non-queue path — kept for backwards compat)
|
||||
if (isset($files['annexes']) && is_array($files['annexes']['name'] ?? null)) {
|
||||
$this->handleAnnexeFiles($thesisId, $files['annexes'], $folderPath, $filePrefix, $post);
|
||||
$startNum = $tfeCount + 1;
|
||||
$startNum = $this->handleTfeQueueFiles($thesisId, $qTfe, $folderPath, $filePrefix, $startNum);
|
||||
$startNum = $this->handleTfeQueueFiles($thesisId, $qVideo, $folderPath, $filePrefix, $startNum);
|
||||
$this->handleTfeQueueFiles($thesisId, $qAudio, $folderPath, $filePrefix, $startNum);
|
||||
$this->handleAnnexeQueueFiles($thesisId, $qAnnexe, $folderPath, $filePrefix);
|
||||
|
||||
// Legacy annexe files (direct upload, non-queue path — kept for backwards compat)
|
||||
if (isset($files['annexes']) && is_array($files['annexes']['name'] ?? null)) {
|
||||
$this->handleAnnexeFiles($thesisId, $files['annexes'], $folderPath, $filePrefix, $post);
|
||||
}
|
||||
|
||||
// ── PeerTube video / audio uploads (from FilePond queue) ──────────────
|
||||
$qPTVideo = $this->extractFilesSubArray($queueFiles, 'peertube_video');
|
||||
$qPTAudio = $this->extractFilesSubArray($queueFiles, 'peertube_audio');
|
||||
$this->handlePeerTubeQueueFiles($thesisId, trim($post['titre'] ?? ''), $qPTVideo, 'video', $progressToken);
|
||||
$this->handlePeerTubeQueueFiles($thesisId, trim($post['titre'] ?? ''), $qPTAudio, 'audio', $progressToken);
|
||||
}
|
||||
|
||||
// ── PeerTube video / audio uploads (from FilePond queue) ──────────────
|
||||
$qPTVideo = $this->extractFilesSubArray($queueFiles, 'peertube_video');
|
||||
$qPTAudio = $this->extractFilesSubArray($queueFiles, 'peertube_audio');
|
||||
$this->handlePeerTubeQueueFiles($thesisId, trim($post['titre'] ?? ''), $qPTVideo, 'video', $progressToken);
|
||||
$this->handlePeerTubeQueueFiles($thesisId, trim($post['titre'] ?? ''), $qPTAudio, 'audio', $progressToken);
|
||||
|
||||
// ── Website URL — add or update ──────────────────────────────────────
|
||||
$this->handleWebsiteUrl($thesisId, $post);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user