diff --git a/app/Services/UpdateService.php b/app/Services/UpdateService.php index 3b8ce34..335c827 100644 --- a/app/Services/UpdateService.php +++ b/app/Services/UpdateService.php @@ -7,6 +7,7 @@ use App\Repositories\LocationRepository; use App\Models\Source; use Ramsey\Uuid\Uuid; use Carbon\Carbon; +use GuzzleHttp\Exception\ConnectException; class UpdateService { @@ -26,18 +27,27 @@ class UpdateService $checked = []; //checks source url to make sure they valid foreach ($sources as $source) { - if ($this->urlExists('https://' . $source->url)) { - $result = []; - if ($source['type'] == 'mastodon') { - if ($source['token'] == null) { + $result = []; + if ($source['type'] == 'mastodon') { + if ($source['token'] == null) { + try { $result = \Mastodon::domain('https://' . $source['url']) ->get('/instance/domain_blocks'); - } else { + array_push($checked, ['source' => $source->url]); + } catch (ConnectException $e) { + array_push($missing, ['source' => $source->url]); + } + } else { + try { $result = \Mastodon::domain('https://' . $source['url']) ->token($source['token']) ->get('/instance/domain_blocks'); + array_push($checked, ['source' => $source->url]); + } catch (ConnectException $e) { } - } elseif ($source['type'] == 'custom' && $source['format'] == 'csv') { + } + } elseif ($source['type'] == 'custom' && $source['format'] == 'csv') { + try { $denylist = array_map('str_getcsv', file('https://' . $source['url'])); foreach ($denylist as $item) { array_push($result, [ @@ -45,11 +55,12 @@ class UpdateService 'severity' => $item[1], 'comment' => $item[2]]); } + array_push($checked, ['source' => $source->url]); + } catch (Exception $e) { + array_push($missing, ['source' => $source->url]); } - array_push($checked, ['source' => $source->url]); - } else { - array_push($missing, ['source' => $source->url]); - }; + } + $source->list_data = json_encode($result); $source->last_updated = Carbon::now(); $source->save();