38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Display;
|
|
use App\Services\DisplayPlaylistConfigBuilder;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
class DisplayPreviewController extends Controller
|
|
{
|
|
public function show(string $token): BinaryFileResponse
|
|
{
|
|
Display::query()
|
|
->where('preview_token', $token)
|
|
->firstOrFail();
|
|
|
|
return response()->file(public_path('_cabinet/display/index.html'));
|
|
}
|
|
|
|
public function config(string $token, DisplayPlaylistConfigBuilder $configBuilder): JsonResponse
|
|
{
|
|
$display = Display::query()
|
|
->where('preview_token', $token)
|
|
->firstOrFail();
|
|
|
|
$playlist = $display->draftPlaylist()
|
|
->with('modules.items')
|
|
->first();
|
|
|
|
if (! $playlist || $playlist->modules->isEmpty()) {
|
|
return response()->json(['error' => 'Display preview not configured'], 404);
|
|
}
|
|
|
|
return response()->json($configBuilder->fromPlaylist($playlist));
|
|
}
|
|
}
|