Files
mtdb_movie/common/Domains/Validation/ValidateLinkWithGoogleSafeBrowsing.php
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

44 lines
1.3 KiB
PHP
Executable File

<?php
namespace Common\Domains\Validation;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;
class ValidateLinkWithGoogleSafeBrowsing
{
public function execute(string $url): bool
{
$key = settings('links.google_safe_browsing_key');
if (!$key) {
return true;
}
$response = Http::withHeaders([
'Referer' => config('app.url'),
])
->post(
"https://safebrowsing.googleapis.com/v4/threatMatches:find?key=$key",
[
'client' => [
'clientId' => config('app.name'),
'clientVersion' => config('common.site.version'),
],
'threatInfo' => [
'threatTypes' => [
'MALWARE',
'SOCIAL_ENGINEERING',
'THREAT_TYPE_UNSPECIFIED',
],
'platformTypes' => ['ANY_PLATFORM'],
'threatEntryTypes' => ['URL'],
'threatEntries' => [['url' => $url]],
],
],
)
->throw();
return Arr::get($response, 'matches.0.threatType') === null;
}
}