updated table structure for photobooth/sparkbooth settings. now there's a separate table for it. update all references and tests. also fixed the notification panel and the lightbox in the guest app.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Services\Photobooth;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPhotoboothSetting;
|
||||
use App\Models\Photo;
|
||||
use App\Services\Photobooth\Exceptions\SparkboothUploadException;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
@@ -21,47 +22,52 @@ class SparkboothUploadService
|
||||
*/
|
||||
public function handleUpload(UploadedFile $media, ?string $username, ?string $password): array
|
||||
{
|
||||
$event = $this->authenticate($username, $password);
|
||||
$setting = $this->authenticate($username, $password);
|
||||
$event = $setting->event;
|
||||
|
||||
$this->enforceExpiry($event);
|
||||
if (! $event) {
|
||||
throw new SparkboothUploadException('invalid_credentials', 'Invalid credentials', 401);
|
||||
}
|
||||
|
||||
$this->enforceExpiry($setting);
|
||||
$this->enforceRateLimit($event);
|
||||
$this->assertValidFile($media);
|
||||
|
||||
$importDisk = config('photobooth.import.disk', 'photobooth');
|
||||
$basePath = ltrim((string) ($event->photobooth_path ?: $this->buildPath($event)), '/');
|
||||
$basePath = ltrim((string) ($setting->path ?: $this->buildPath($event)), '/');
|
||||
$extension = strtolower($media->getClientOriginalExtension() ?: $media->extension() ?: 'jpg');
|
||||
$filename = Str::uuid().'.'.$extension;
|
||||
$relativePath = "{$basePath}/{$filename}";
|
||||
|
||||
if (! $event->photobooth_path) {
|
||||
$event->forceFill([
|
||||
'photobooth_path' => $basePath,
|
||||
if (! $setting->path) {
|
||||
$setting->forceFill([
|
||||
'path' => $basePath,
|
||||
])->save();
|
||||
}
|
||||
|
||||
Storage::disk($importDisk)->makeDirectory($basePath);
|
||||
Storage::disk($importDisk)->putFileAs($basePath, $media, $filename);
|
||||
|
||||
$summary = $this->ingestService->ingest($event->fresh(), 1, Photo::SOURCE_SPARKBOOTH);
|
||||
$summary = $this->ingestService->ingest($event->fresh('photoboothSetting'), 1, Photo::SOURCE_SPARKBOOTH);
|
||||
|
||||
if (($summary['processed'] ?? 0) < 1) {
|
||||
throw new SparkboothUploadException('ingest_failed', 'Upload failed, please retry.', 500);
|
||||
}
|
||||
|
||||
$event->forceFill([
|
||||
'sparkbooth_last_upload_at' => now(),
|
||||
'sparkbooth_uploads_last_24h' => ($event->sparkbooth_uploads_last_24h ?? 0) + 1,
|
||||
'sparkbooth_uploads_total' => ($event->sparkbooth_uploads_total ?? 0) + 1,
|
||||
$setting->forceFill([
|
||||
'last_upload_at' => now(),
|
||||
'uploads_last_24h' => ($setting->uploads_last_24h ?? 0) + 1,
|
||||
'uploads_total' => ($setting->uploads_total ?? 0) + 1,
|
||||
])->save();
|
||||
|
||||
return [
|
||||
'event' => $event->fresh(),
|
||||
'event' => $event->fresh('photoboothSetting'),
|
||||
'processed' => $summary['processed'] ?? 0,
|
||||
'skipped' => $summary['skipped'] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
protected function authenticate(?string $username, ?string $password): Event
|
||||
protected function authenticate(?string $username, ?string $password): EventPhotoboothSetting
|
||||
{
|
||||
if (! $username || ! $password) {
|
||||
throw new SparkboothUploadException('missing_credentials', 'Invalid credentials', 401);
|
||||
@@ -69,29 +75,34 @@ class SparkboothUploadService
|
||||
|
||||
$normalizedUsername = strtolower(trim($username));
|
||||
|
||||
/** @var Event|null $event */
|
||||
$event = Event::query()
|
||||
->whereRaw('LOWER(sparkbooth_username) = ?', [$normalizedUsername])
|
||||
/** @var EventPhotoboothSetting|null $setting */
|
||||
$setting = EventPhotoboothSetting::query()
|
||||
->where('username', $normalizedUsername)
|
||||
->with('event')
|
||||
->first();
|
||||
|
||||
if (! $event) {
|
||||
if (! $setting) {
|
||||
throw new SparkboothUploadException('invalid_credentials', 'Invalid credentials', 401);
|
||||
}
|
||||
|
||||
if ($event->photobooth_mode !== 'sparkbooth' || ! $event->photobooth_enabled) {
|
||||
if (! $setting->event) {
|
||||
throw new SparkboothUploadException('invalid_credentials', 'Invalid credentials', 401);
|
||||
}
|
||||
|
||||
if ($setting->mode !== 'sparkbooth' || ! $setting->enabled) {
|
||||
throw new SparkboothUploadException('disabled', 'Upload not active for this event', 403);
|
||||
}
|
||||
|
||||
if (! hash_equals($event->sparkbooth_password ?? '', $password ?? '')) {
|
||||
if (! hash_equals($setting->password ?? '', $password ?? '')) {
|
||||
throw new SparkboothUploadException('invalid_credentials', 'Invalid credentials', 401);
|
||||
}
|
||||
|
||||
return $event;
|
||||
return $setting;
|
||||
}
|
||||
|
||||
protected function enforceExpiry(Event $event): void
|
||||
protected function enforceExpiry(EventPhotoboothSetting $setting): void
|
||||
{
|
||||
if ($event->sparkbooth_expires_at && $event->sparkbooth_expires_at->isPast()) {
|
||||
if ($setting->expires_at && $setting->expires_at->isPast()) {
|
||||
throw new SparkboothUploadException('expired', 'Upload access has expired', 403);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user