21 lines
755 B
PHP
21 lines
755 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace App\Dashboard;
|
|
|
|
use App\Http\{Request, Response};
|
|
use App\Auth\SessionStore;
|
|
use App\Repository\SnapshotRepository;
|
|
|
|
final class SnapshotProxy
|
|
{
|
|
public function __construct(private SnapshotRepository $snaps, private SessionStore $sess) {}
|
|
|
|
public function serve(Request $req, array $params): Response
|
|
{
|
|
if ($this->sess->get('user_id') === null) return Response::json(['error' => 'unauthorized'], 401);
|
|
$uuid = (string)($params['uuid'] ?? '');
|
|
$path = $this->snaps->pathByUuid($uuid);
|
|
if ($path === null || !is_file($path)) return Response::json(['error' => 'not_found'], 404);
|
|
return Response::bytes((string)file_get_contents($path), 'image/jpeg', 200);
|
|
}
|
|
}
|