2023-05-30 14:29:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2023-06-01 05:33:46 +00:00
|
|
|
use App\Http\Requests\WebCrawlRequest;
|
|
|
|
use App\Services\WebCrawlerService;
|
2023-05-30 14:29:46 +00:00
|
|
|
|
|
|
|
class WebCrawlController extends Controller
|
|
|
|
{
|
2023-06-01 05:33:46 +00:00
|
|
|
protected $webCrawlerService;
|
|
|
|
|
|
|
|
public function __construct(WebCrawlerService $webCrawlerService)
|
|
|
|
{
|
|
|
|
$this->webCrawlerService = $webCrawlerService;
|
|
|
|
}
|
2023-05-30 14:29:46 +00:00
|
|
|
|
|
|
|
public function index()
|
2023-05-30 17:19:53 +00:00
|
|
|
{
|
2023-06-01 05:33:46 +00:00
|
|
|
return $this->webCrawlerService->getAllCrawls();
|
2023-05-30 17:19:53 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 05:33:46 +00:00
|
|
|
public function crawlWebsite(WebCrawlRequest $request)
|
2023-05-31 09:35:41 +00:00
|
|
|
{
|
|
|
|
$url = $request->query('url');
|
2023-05-31 11:52:51 +00:00
|
|
|
$depth = $request->query('depth', 0);
|
2023-05-31 10:17:19 +00:00
|
|
|
$refresh = $request->query('refresh', false);
|
2023-05-30 17:19:53 +00:00
|
|
|
|
2023-06-01 05:33:46 +00:00
|
|
|
return $this->webCrawlerService->crawlWebsite($url, $depth, $refresh);
|
2023-05-30 14:29:46 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 17:19:53 +00:00
|
|
|
public function destroy($id)
|
2023-05-30 14:29:46 +00:00
|
|
|
{
|
2023-06-01 05:33:46 +00:00
|
|
|
return $this->webCrawlerService->deleteCrawl($id);
|
2023-05-31 09:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function destroyAll()
|
|
|
|
{
|
2023-06-01 05:33:46 +00:00
|
|
|
return $this->webCrawlerService->deleteAllCrawls();
|
2023-05-30 14:29:46 +00:00
|
|
|
}
|
|
|
|
}
|