diff --git a/src/Controller/InstanceController.php b/src/Controller/InstanceController.php index 4248c2a..414f27f 100644 --- a/src/Controller/InstanceController.php +++ b/src/Controller/InstanceController.php @@ -6,6 +6,7 @@ use AlexMorbo\React\Trassir\Router\Router; use AlexMorbo\React\Trassir\Traits\DBTrait; use AlexMorbo\React\Trassir\TrassirHelper; +use Carbon\Carbon; use Clue\React\SQLite\DatabaseInterface; use Fig\Http\Message\StatusCodeInterface; use Psr\Http\Message\ServerRequestInterface; @@ -62,6 +63,15 @@ public function addRoutes(Router $router): void $stream ) ); + $router->get( + "/api/instance/{instanceId}/channel/{channelId}/archive/{start}/{end}", + fn(ServerRequestInterface $request, $instanceId, $channelId, $start, $end) => $this->getChannelArchive( + $instanceId, + $channelId, + $start, + $end, + ) + ); } public function getInstances(): PromiseInterface @@ -298,5 +308,26 @@ function ($video) use ($request) { ); } + public function getChannelArchive(string $instanceId, string $channelId, string $start, string $end): PromiseInterface + { + return $this->trassirHelper->getInstance($instanceId) + ->then( + function (Instance $instance) use ($channelId, $start, $end) { + $from = Carbon::parse(urldecode($start)); + $to = Carbon::parse(urldecode($end)); + + return $instance->getTrassir()( + $instance->getName(), + $channelId, + $container, + $stream + ); + return resolve(Response::json([ + 'from' => $from, + 'to' => $to + ])); + } + ); + } } \ No newline at end of file