cache = $cache; $this->fileRepository = $fileRepository; } /** * Returns a listing of files in a given directory. * * @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\ListFilesRequest $request * @return \Illuminate\Http\JsonResponse */ public function listDirectory(ListFilesRequest $request): JsonResponse { return JsonResponse::create([ 'contents' => $this->fileRepository->setServer($request->getModel(Server::class))->getDirectory( $request->get('directory') ?? '/' ), ]); } /** * Creates a new folder on the server. * * @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\CreateFolderRequest $request * @return \Illuminate\Http\Response */ public function createFolder(CreateFolderRequest $request): Response { $this->fileRepository ->setServer($request->getModel(Server::class)) ->createDirectory($request->input('name'), $request->input('directory', '/')); return Response::create('', Response::HTTP_NO_CONTENT); } /** * Renames a file on the remote machine. * * @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\RenameFileRequest $request * @return \Illuminate\Http\Response */ public function renameFile(RenameFileRequest $request): Response { $this->fileRepository ->setServer($request->getModel(Server::class)) ->renameFile($request->input('rename_from'), $request->input('rename_to')); return Response::create('', Response::HTTP_NO_CONTENT); } /** * Configure a reference to a file to download in the cache so that when the * user hits the Daemon and it verifies with the Panel they'll actually be able * to download that file. * * Returns the token that needs to be used when downloading the file. * * @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\DownloadFileRequest $request * @return \Illuminate\Http\JsonResponse * @throws \Exception */ public function download(DownloadFileRequest $request): JsonResponse { /** @var \Pterodactyl\Models\Server $server */ $server = $request->getModel(Server::class); $token = Uuid::uuid4()->toString(); $this->cache->put( 'Server:Downloads:' . $token, ['server' => $server->uuid, 'path' => $request->route()->parameter('file')], Carbon::now()->addMinutes(5) ); return JsonResponse::create(['token' => $token]); } }