added a help system, replaced the words "tenant" and "Pwa" with better alternatives. corrected and implemented cron jobs. prepared going live on a coolify-powered system.
This commit is contained in:
76
app/Http/Resources/Tenant/PhotoboothStatusResource.php
Normal file
76
app/Http/Resources/Tenant/PhotoboothStatusResource.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Tenant;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\PhotoboothSetting;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PhotoboothStatusResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$payload = $this->resolvePayload();
|
||||
/** @var Event $event */
|
||||
$event = $payload['event'];
|
||||
/** @var PhotoboothSetting $settings */
|
||||
$settings = $payload['settings'];
|
||||
|
||||
$password = $event->getAttribute('plain_photobooth_password') ?? $event->photobooth_password;
|
||||
|
||||
return [
|
||||
'enabled' => (bool) $event->photobooth_enabled,
|
||||
'status' => $event->photobooth_status,
|
||||
'username' => $event->photobooth_username,
|
||||
'password' => $password,
|
||||
'path' => $event->photobooth_path,
|
||||
'ftp_url' => $this->buildFtpUrl($event, $settings, $password),
|
||||
'expires_at' => optional($event->photobooth_expires_at)->toIso8601String(),
|
||||
'rate_limit_per_minute' => (int) $settings->rate_limit_per_minute,
|
||||
'ftp' => [
|
||||
'host' => config('photobooth.ftp.host'),
|
||||
'port' => $settings->ftp_port,
|
||||
'require_ftps' => (bool) $settings->require_ftps,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{event: Event, settings: PhotoboothSetting}
|
||||
*/
|
||||
protected function resolvePayload(): array
|
||||
{
|
||||
$resource = $this->resource;
|
||||
|
||||
if ($resource instanceof Event) {
|
||||
return [
|
||||
'event' => $resource,
|
||||
'settings' => PhotoboothSetting::current(),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'event' => $resource['event'] ?? $resource,
|
||||
'settings' => $resource['settings'] ?? PhotoboothSetting::current(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function buildFtpUrl(Event $event, PhotoboothSetting $settings, ?string $password): ?string
|
||||
{
|
||||
$host = config('photobooth.ftp.host');
|
||||
$username = $event->photobooth_username;
|
||||
|
||||
if (! $host || ! $username || ! $password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$scheme = $settings->require_ftps ? 'ftps' : 'ftp';
|
||||
$port = $settings->ftp_port ?: config('photobooth.ftp.port', 21);
|
||||
|
||||
return sprintf('%s://%s:%s@%s:%d', $scheme, $username, $password, $host, $port);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user