2023-05-30 09:56:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Route;
|
2023-05-30 14:29:46 +00:00
|
|
|
use App\Http\Controllers\WebCrawlController;
|
2023-05-30 09:56:38 +00:00
|
|
|
|
2023-05-30 17:19:53 +00:00
|
|
|
Route::get('/crawl', function (Request $request) {
|
2023-05-31 09:35:41 +00:00
|
|
|
$url = $request->query('url');
|
|
|
|
|
|
|
|
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) {
|
|
|
|
return response()->json([
|
|
|
|
'error' => 'Missing required parameter `url` or invalid URL',
|
|
|
|
], 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
$depth = $request->query('depth', 3);
|
|
|
|
|
|
|
|
$crawlerController = new WebCrawlController();
|
|
|
|
return $crawlerController->crawlWebsite($request);
|
2023-05-30 17:19:53 +00:00
|
|
|
});
|
2023-05-30 12:10:17 +00:00
|
|
|
|
2023-05-31 09:35:41 +00:00
|
|
|
Route::get('/', function () {
|
|
|
|
$crawlerController = new WebCrawlController();
|
|
|
|
return $crawlerController->index();
|
|
|
|
});
|
2023-05-30 12:10:17 +00:00
|
|
|
|
2023-05-31 09:35:41 +00:00
|
|
|
Route::delete('/crawl/{id}', function ($id) {
|
|
|
|
$crawlerController = new WebCrawlController();
|
|
|
|
return $crawlerController->destroy($id);
|
|
|
|
});
|
|
|
|
|
|
|
|
Route::delete('/crawl', function () {
|
|
|
|
$crawlerController = new WebCrawlController();
|
|
|
|
return $crawlerController->destroyAll();
|
|
|
|
});
|