downloadRepository->insert( $this->getUser(), $input->url, $input->title, $input->filename, $input->imdbId, $input->mediaType, $input->episodeId, ); $input->downloadId = $download->getId(); $input->userId = $this->getUser()->getId(); $this->bus->dispatch(new AddEventLogCommand( $this->getUser(), DownloadEvents::DOWNLOAD_ADDED->type(), DownloadEvents::DOWNLOAD_ADDED->message(), (array) $download )); try { $this->bus->dispatch($input->toCommand()); } catch (\Throwable $exception) { return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR); } $this->broadcaster->alert( title: 'Success', message: "$input->title added to Queue." ); return $this->json(['status' => 200, 'message' => 'Added to Queue']); } #[Route('/api/download/{downloadId}', name: 'api_download_delete', methods: ['DELETE'])] public function deleteDownload( DeleteDownloadInput $input, DeleteDownloadHandler $handler, ): Response { $result = $handler->handle($input->toCommand()); $this->broadcaster->alert( title: 'Success', message: "{$result->download->getTitle()} has been deleted.", ); return $this->json($result); } #[Route('/api/download/{downloadId}/pause', name: 'api_download_pause', methods: ['PATCH'])] public function pauseDownload( PauseDownloadInput $input, PauseDownloadHandler $handler, ): Response { $result = $handler->handle($input->toCommand()); $this->broadcaster->alert( title: 'Success', message: "{$result->download->getTitle()} has been Paused.", ); return $this->json(['status' => 200, 'message' => 'Download Paused']); } #[Route('/api/download/{downloadId}/resume', name: 'api_download_resume', methods: ['PATCH'])] public function resumeDownload( ResumeDownloadInput $input, ResumeDownloadHandler $handler, ): Response { $result = $handler->handle($input->toCommand()); $this->broadcaster->alert( title: 'Success', message: "{$result->download->getTitle()} has been Resumed.", ); return $this->json(['status' => 200, 'message' => 'Download Resumed']); } #[Route('/api/download/season/{imdbId}/{season}', name: 'api_download_season', methods: ['GET'])] public function downloadSeason( DownloadSeasonInput $input, ): Response { $input->userId = $this->getUser()->getId(); $this->bus->dispatch($input->toCommand()); $this->broadcaster->alert( title: 'Success', message: "Your download for season $input->season has been added to the queue.", ); return $this->json(['status' => 200, 'message' => 'Download Resumed']); } }