Add Docker stack, Reverb live progress, and duplicate upload detection.
Ship FrankenPHP Compose services with Reverb WebSockets for real-time transcription status, skip re-uploading identical audio via content hash, and format disk usage without requiring intl.
This commit is contained in:
@@ -49,7 +49,19 @@ class RecordingController extends Controller
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('recordings.create');
|
||||
$existingFingerprints = Recording::query()
|
||||
->get(['original_filename', 'file_size_bytes'])
|
||||
->map(fn (Recording $recording) => $this->uploadFingerprint(
|
||||
$recording->original_filename,
|
||||
(int) $recording->file_size_bytes,
|
||||
))
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return view('recordings.create', [
|
||||
'existingFingerprints' => $existingFingerprints,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,24 +77,71 @@ class RecordingController extends Controller
|
||||
|
||||
$titleOverride = $request->string('title')->trim()->toString();
|
||||
$recordings = [];
|
||||
$skippedDuplicates = 0;
|
||||
$seenHashes = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$hash = hash_file('sha256', $file->getRealPath());
|
||||
|
||||
if ($hash === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($seenHashes[$hash])
|
||||
|| Recording::query()->where('content_hash', $hash)->exists()
|
||||
|| Recording::query()
|
||||
->where('original_filename', $file->getClientOriginalName())
|
||||
->where('file_size_bytes', $file->getSize() ?: 0)
|
||||
->exists()
|
||||
) {
|
||||
$skippedDuplicates++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$seenHashes[$hash] = true;
|
||||
|
||||
$title = count($files) === 1 && $titleOverride !== ''
|
||||
? $titleOverride
|
||||
: null;
|
||||
|
||||
$recordings[] = $this->storeUploadedRecording($file, $metadata, $title);
|
||||
$recordings[] = $this->storeUploadedRecording($file, $metadata, $hash, $title);
|
||||
}
|
||||
|
||||
if ($recordings === [] && $skippedDuplicates > 0) {
|
||||
return redirect()
|
||||
->route('recordings.create')
|
||||
->with('error', $skippedDuplicates === 1
|
||||
? 'That file is already uploaded — nothing new was saved.'
|
||||
: "All {$skippedDuplicates} files were duplicates — nothing new was saved.");
|
||||
}
|
||||
|
||||
if ($recordings === []) {
|
||||
return redirect()
|
||||
->route('recordings.create')
|
||||
->with('error', 'No valid audio files were uploaded.');
|
||||
}
|
||||
|
||||
$message = count($recordings) === 1
|
||||
? 'Recording uploaded — transcription queued.'
|
||||
: count($recordings).' recordings uploaded — transcription queued.';
|
||||
|
||||
if ($skippedDuplicates > 0) {
|
||||
$message .= $skippedDuplicates === 1
|
||||
? ' Skipped 1 duplicate.'
|
||||
: " Skipped {$skippedDuplicates} duplicates.";
|
||||
}
|
||||
|
||||
if (count($recordings) === 1) {
|
||||
return redirect()
|
||||
->route('recordings.show', $recordings[0])
|
||||
->with('success', 'Recording uploaded — transcription queued.');
|
||||
->with('success', $message);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('recordings.index')
|
||||
->with('success', count($recordings).' recordings uploaded — transcription queued.');
|
||||
->with('success', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,6 +174,7 @@ class RecordingController extends Controller
|
||||
private function storeUploadedRecording(
|
||||
UploadedFile $file,
|
||||
Mp3MetadataService $metadata,
|
||||
string $contentHash,
|
||||
?string $titleOverride = null,
|
||||
): Recording {
|
||||
$path = $file->store('recordings', 'local');
|
||||
@@ -133,6 +193,7 @@ class RecordingController extends Controller
|
||||
'artist' => $tags['artist'],
|
||||
'album' => $tags['album'],
|
||||
'file_size_bytes' => $file->getSize() ?: 0,
|
||||
'content_hash' => $contentHash,
|
||||
'transcription_status' => 'pending',
|
||||
'transcription_driver' => 'local',
|
||||
]);
|
||||
@@ -141,4 +202,12 @@ class RecordingController extends Controller
|
||||
|
||||
return $recording->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-side fingerprint for name + size duplicate checks before upload.
|
||||
*/
|
||||
private function uploadFingerprint(string $filename, int $sizeBytes): string
|
||||
{
|
||||
return strtolower($filename).':'.$sizeBytes;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user