revert register for sessions. photos with different settings, settings configurable
This commit is contained in:
DigitalInfinity committed 2026-06-07 21:30:34 +02:00
1 parent 5596437995
commit 858a451396
14 files changed
+71 -515

No files matched your search

+1 -4
View File
@@ -20,12 +20,9 @@ class ConvertToComic implements ShouldQueue
{
$absolutePath = Storage::disk('public')->path($this->photoJob->image_path);
$gmicOps = $this->photoJob->setting?->gmic_command
?? 'cl_comic 4,1,0,0,1,15,15,1,10,20,6,2,0,0,0,0,0,0,50,50';
$result = Process::timeout(0)->run(
'gmic ' . escapeshellarg($absolutePath) .
' ' . $gmicOps .
' cl_comic 4,1,0,0,1,15,15,1,10,20,6,2,0,0,0,0,0,0,50,50' .
' -o ' . escapeshellarg($absolutePath)
);
+26 -52
View File
@@ -4,8 +4,6 @@ namespace App\Livewire;
use App\Jobs\ConvertToComic;
use App\Models\PhotoJob;
use App\Models\PhotoSession;
use App\Models\PhotoSetting;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Livewire\Component;
@@ -14,6 +12,17 @@ class CameraCapture extends Component
{
public string $status = '';
public function delete(int $jobId): void
{
$job = PhotoJob::find($jobId);
if (!$job) return;
Storage::disk('public')->delete($job->image_path);
$job->delete();
$this->status = "Job #{$jobId} deleted";
}
public function capture(string $imageData): void
{
if (!preg_match('/^data:image\/(\w+);base64,/', $imageData, $type)) {
@@ -22,66 +31,31 @@ class CameraCapture extends Component
}
$extension = strtolower($type[1]);
$filename = 'photos/' . Str::uuid() . '.' . $extension;
$raw = base64_decode(substr($imageData, strpos($imageData, ',') + 1));
$originalPath = 'photos/' . Str::uuid() . '.' . $extension;
Storage::disk('public')->put($originalPath, $raw);
Storage::disk('public')->put($filename, $raw);
$session = PhotoSession::create(['original_image_path' => $originalPath]);
$job = PhotoJob::create([
'image_path' => $filename,
'status' => 'processing',
]);
$settings = PhotoSetting::active()->get();
ConvertToComic::dispatch($job);
foreach ($settings as $setting) {
$variantPath = 'photos/' . Str::uuid() . '.' . $extension;
Storage::disk('public')->put($variantPath, $raw);
$job = PhotoJob::create([
'image_path' => $variantPath,
'status' => 'processing',
'photo_session_id' => $session->id,
'photo_setting_id' => $setting->id,
]);
ConvertToComic::dispatch($job);
}
$this->status = count($settings) . ' Varianten werden erstellt…';
}
public function selectVariant(int $sessionId, int $jobId): void
{
PhotoSession::where('id', $sessionId)->update(['selected_job_id' => $jobId]);
}
public function deleteSession(int $sessionId): void
{
$session = PhotoSession::with('jobs')->find($sessionId);
if (!$session) return;
foreach ($session->jobs as $job) {
Storage::disk('public')->delete($job->image_path);
$job->delete();
}
Storage::disk('public')->delete($session->original_image_path);
$session->delete();
$this->status = "Session #{$sessionId} gelöscht";
$this->status = "Processing photo…";
}
public function render()
{
$sessions = PhotoSession::latest()->take(10)->get();
$recentPhotos = PhotoJob::latest()->take(10)->get()->map(fn($job) => [
'id' => $job->id,
'url' => Storage::disk('public')->url($job->image_path) . '?v=' . $job->updated_at->timestamp,
'status' => $job->status,
]);
foreach ($sessions as $session) {
$session->setRelation('jobs', $session->jobs()->with('setting')->orderBy('photo_setting_id')->get());
}
$hasProcessing = $recentPhotos->contains('status', 'processing');
$currentSession = $sessions->first();
$previousSessions = $sessions->skip(1);
$hasProcessing = $currentSession && $currentSession->jobs->contains('status', 'processing');
return view('livewire.camera-capture', compact('currentSession', 'previousSessions', 'hasProcessing'));
return view('livewire.camera-capture', compact('recentPhotos', 'hasProcessing'));
}
}
-75
View File
@@ -1,75 +0,0 @@
<?php
namespace App\Livewire;
use App\Models\PhotoSetting;
use Livewire\Component;
class PhotoSettings extends Component
{
public array $editingId = [];
public array $editName = [];
public array $editCommand = [];
public bool $showForm = false;
public string $newName = '';
public string $newCommand = '';
public function toggleActive(int $id): void
{
$setting = PhotoSetting::findOrFail($id);
$setting->update(['is_active' => !$setting->is_active]);
}
public function startEdit(int $id, string $name, string $command): void
{
$this->editingId = [$id => true];
$this->editName[$id] = $name;
$this->editCommand[$id] = $command;
}
public function saveEdit(int $id): void
{
PhotoSetting::findOrFail($id)->update([
'name' => trim($this->editName[$id] ?? ''),
'gmic_command' => trim($this->editCommand[$id] ?? ''),
]);
unset($this->editingId[$id]);
}
public function cancelEdit(int $id): void
{
unset($this->editingId[$id]);
}
public function addSetting(): void
{
$name = trim($this->newName);
$command = trim($this->newCommand);
if (!$name || !$command) return;
$max = PhotoSetting::max('sort_order') ?? 0;
PhotoSetting::create([
'name' => $name,
'gmic_command' => $command,
'sort_order' => $max + 1,
'is_active' => true,
]);
$this->newName = '';
$this->newCommand = '';
$this->showForm = false;
}
public function delete(int $id): void
{
PhotoSetting::findOrFail($id)->delete();
}
public function render()
{
return view('livewire.photo-settings', [
'settings' => PhotoSetting::orderBy('sort_order')->get(),
]);
}
}
+1 -12
View File
@@ -3,19 +3,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PhotoJob extends Model
{
protected $fillable = ['image_path', 'status', 'photo_session_id', 'photo_setting_id'];
public function session(): BelongsTo
{
return $this->belongsTo(PhotoSession::class, 'photo_session_id');
}
public function setting(): BelongsTo
{
return $this->belongsTo(PhotoSetting::class, 'photo_setting_id');
}
protected $fillable = ['image_path', 'status'];
}
-22
View File
@@ -1,22 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PhotoSession extends Model
{
protected $fillable = ['original_image_path', 'selected_job_id'];
public function jobs(): HasMany
{
return $this->hasMany(PhotoJob::class)->with('setting')->orderBy('photo_setting_id');
}
public function selectedJob(): BelongsTo
{
return $this->belongsTo(PhotoJob::class, 'selected_job_id');
}
}
-23
View File
@@ -1,23 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PhotoSetting extends Model
{
protected $fillable = ['name', 'gmic_command', 'sort_order', 'is_active'];
protected $casts = ['is_active' => 'boolean'];
public function jobs(): HasMany
{
return $this->hasMany(PhotoJob::class);
}
public function scopeActive($query)
{
return $query->where('is_active', true)->orderBy('sort_order');
}
}