pp-planer/app/Http/Controllers/ExportProFileController.php
Thorsten Bus fdabaadb89 fix(export): preserve probundle extension and attach slide macros
- store() persisted uploads under Laravel's MIME-guessed extension,
  turning a .probundle (a ZIP) into .zip; embedExportProFile then
  branched on the stored path, missed the bundle branch and embedded
  the raw ZIP as a broken .pro (ProPresenter showed an empty slide).
  Store with the real client extension and derive the bundle type from
  the original filename, treating .zip as a bundle for legacy uploads.
- Skip export .pro/.probundle files that parse to zero content slides,
  recording a German warning instead of injecting an empty slide.
- Attach position macros (first_slide/last_slide/all_slides) per slide
  for information/moderation/sermon parts in the agenda and legacy paths.
- Cover both with ExportProFileProbundleEmbedTest and PlaylistSermonMacroTest.
2026-07-06 11:19:56 +02:00

89 lines
3.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\ExportProFile;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
class ExportProFileController extends Controller
{
public function store(Request $request): JsonResponse
{
$request->validate([
'type' => ['required', Rule::in(['prefix', 'postfix', 'keyword'])],
'keyword' => [Rule::requiredIf(fn () => $request->input('type') === 'keyword'), 'nullable', 'string', 'max:255'],
'files' => ['required', 'array'],
'files.*' => ['required', 'file', 'max:10240', 'extensions:pro,probundle'],
], [
'files.*.extensions' => 'Nur .pro- und .probundle-Dateien sind erlaubt.',
]);
$type = $request->input('type');
$keyword = $type === 'keyword' ? $request->input('keyword') : null;
$created = [];
foreach ($request->file('files') as $file) {
// Store under a random basename but keep the REAL client extension.
// Laravel's store() names files by the guessed MIME extension, which
// turns a .probundle (a ZIP) into a .zip and breaks extension-based
// routing at export time.
$extension = strtolower($file->getClientOriginalExtension());
$basename = Str::random(40).($extension !== '' ? '.'.$extension : '');
$storedPath = $file->storeAs('export-pro-files/'.$type, $basename, 'local');
$maxOrder = ExportProFile::where('type', $type)->max('order') ?? 0;
$record = ExportProFile::create([
'type' => $type,
'keyword' => $keyword,
'original_name' => $file->getClientOriginalName(),
'stored_path' => $storedPath,
'order' => $maxOrder + 1,
]);
$created[] = [
'id' => $record->id,
'original_name' => $record->original_name,
'order' => $record->order,
];
}
return response()->json([
'files' => $created,
'message' => count($created).' Datei(en) erfolgreich hochgeladen.',
], 201);
}
public function updateKeyword(Request $request, ExportProFile $exportProFile): JsonResponse
{
if ($exportProFile->type !== 'keyword') {
return response()->json([
'message' => 'Schlüsselwort kann nur für Schlüsselwort-Dateien geändert werden.',
], 422);
}
$validated = $request->validate([
'keyword' => ['required', 'string', 'max:255'],
]);
$exportProFile->update(['keyword' => $validated['keyword']]);
return response()->json([
'message' => 'Schlüsselwort erfolgreich aktualisiert.',
]);
}
public function destroy(ExportProFile $exportProFile): JsonResponse
{
Storage::disk('local')->delete($exportProFile->stored_path);
$exportProFile->delete();
return response()->json([
'message' => 'Datei erfolgreich gelöscht.',
]);
}
}