Update
This commit is contained in:
@@ -23,7 +23,9 @@ public function crawl(Request $request): JsonResponse
|
||||
'block_ads' => 'boolean',
|
||||
'block_cookie_banners' => 'boolean',
|
||||
'block_trackers' => 'boolean',
|
||||
'wait_until_network_idle' => 'boolean'
|
||||
'webhook_url' => 'nullable|url|max:2048',
|
||||
'webhook_events_filter' => 'nullable|array',
|
||||
'webhook_events_filter.*' => 'in:queued,processing,completed,failed'
|
||||
]);
|
||||
|
||||
$uuid = Str::uuid()->toString();
|
||||
@@ -33,13 +35,15 @@ public function crawl(Request $request): JsonResponse
|
||||
'type' => 'crawl',
|
||||
'url' => $validated['url'],
|
||||
'status' => 'queued',
|
||||
'webhook_url' => $validated['webhook_url'] ?? null,
|
||||
'webhook_events_filter' => isset($validated['webhook_events_filter']) ? $validated['webhook_events_filter'] : ['queued', 'processing', 'completed', 'failed'],
|
||||
'parameters' => array_filter([
|
||||
'timeout' => $validated['timeout'] ?? 30,
|
||||
'delay' => $validated['delay'] ?? 0,
|
||||
'block_ads' => $validated['block_ads'] ?? true,
|
||||
'block_cookie_banners' => $validated['block_cookie_banners'] ?? true,
|
||||
'block_trackers' => $validated['block_trackers'] ?? true,
|
||||
'wait_until_network_idle' => $validated['wait_until_network_idle'] ?? false
|
||||
'block_trackers' => $validated['block_trackers'] ?? true
|
||||
// wait_until_network_idle is always enabled in BrowsershotService
|
||||
])
|
||||
]);
|
||||
|
||||
|
||||
@@ -24,7 +24,10 @@ public function shot(Request $request): JsonResponse
|
||||
'delay' => 'integer|min:0|max:30000',
|
||||
'block_ads' => 'boolean',
|
||||
'block_cookie_banners' => 'boolean',
|
||||
'block_trackers' => 'boolean'
|
||||
'block_trackers' => 'boolean',
|
||||
'webhook_url' => 'nullable|url|max:2048',
|
||||
'webhook_events_filter' => 'nullable|array',
|
||||
'webhook_events_filter.*' => 'in:queued,processing,completed,failed'
|
||||
]);
|
||||
|
||||
$uuid = Str::uuid()->toString();
|
||||
@@ -34,6 +37,8 @@ public function shot(Request $request): JsonResponse
|
||||
'type' => 'shot',
|
||||
'url' => $validated['url'],
|
||||
'status' => 'queued',
|
||||
'webhook_url' => $validated['webhook_url'] ?? null,
|
||||
'webhook_events_filter' => isset($validated['webhook_events_filter']) ? $validated['webhook_events_filter'] : ['queued', 'processing', 'completed', 'failed'],
|
||||
'parameters' => array_filter([
|
||||
'viewport_width' => $validated['viewport_width'] ?? 1920,
|
||||
'viewport_height' => $validated['viewport_height'] ?? 1080,
|
||||
|
||||
72
app/Http/Controllers/Api/WebhookErrorController.php
Normal file
72
app/Http/Controllers/Api/WebhookErrorController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CrawlShotJob;
|
||||
use App\Services\WebhookService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class WebhookErrorController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$jobs = CrawlShotJob::where('webhook_attempts', '>', 0)
|
||||
->whereNotNull('webhook_url')
|
||||
->orderBy('updated_at', 'desc')
|
||||
->paginate(20);
|
||||
|
||||
$response = [
|
||||
'jobs' => $jobs->items(),
|
||||
'pagination' => [
|
||||
'current_page' => $jobs->currentPage(),
|
||||
'total_pages' => $jobs->lastPage(),
|
||||
'total_items' => $jobs->total(),
|
||||
'per_page' => $jobs->perPage()
|
||||
]
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function retry(string $uuid): JsonResponse
|
||||
{
|
||||
$job = CrawlShotJob::where('uuid', $uuid)->first();
|
||||
|
||||
if (!$job) {
|
||||
return response()->json(['error' => 'Job not found'], 404);
|
||||
}
|
||||
|
||||
if (!$job->webhook_url) {
|
||||
return response()->json(['error' => 'Job has no webhook URL'], 400);
|
||||
}
|
||||
|
||||
// Attempt webhook immediately
|
||||
WebhookService::send($job);
|
||||
|
||||
return response()->json([
|
||||
'uuid' => $job->uuid,
|
||||
'message' => 'Webhook retry attempted'
|
||||
]);
|
||||
}
|
||||
|
||||
public function clear(string $uuid): JsonResponse
|
||||
{
|
||||
$job = CrawlShotJob::where('uuid', $uuid)->first();
|
||||
|
||||
if (!$job) {
|
||||
return response()->json(['error' => 'Job not found'], 404);
|
||||
}
|
||||
|
||||
$job->update([
|
||||
'webhook_attempts' => 0,
|
||||
'webhook_last_error' => null,
|
||||
'webhook_next_retry_at' => null
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'uuid' => $job->uuid,
|
||||
'message' => 'Webhook error cleared'
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user