diff --git a/app/Repositories/SourceRepository.php b/app/Repositories/SourceRepository.php index 341b568..29deab7 100644 --- a/app/Repositories/SourceRepository.php +++ b/app/Repositories/SourceRepository.php @@ -9,10 +9,16 @@ use GuzzleHttp\Exception\ConnectException; class SourceRepository { protected $source; + protected $missing; + protected $updated; + protected $sources; public function __construct(Source $source) { - $this->source = $source; + $this->source = $source; + $this->missing = []; + $this->updated = []; + $this->sources = $source::where("active", true)->get(); } public function getActive() @@ -20,51 +26,85 @@ class SourceRepository return $this->source::where("active", true)->get(); } - public function updateSourceData() + public function updateSourceData($index = 0) { - $sources = $this->getActive(); - $missing = []; - $checked = []; + //$sources = $this->getActive(); //checks all the sources to refresh data - foreach ($sources as $source) { - $result = []; - if ($source['type'] == 'mastodon') { - if ($source['token'] == null) { - try { - $result = \Mastodon::domain('https://' . $source['url']) - ->get('/instance/domain_blocks'); - array_push($checked, ['source' => $source->url]); - } catch (ConnectException $e) { - array_push($missing, ['source' => $source->url]); - } + $count = count($this->sources); + if ($count == 0) { + return [ + 'checked' => $this->updated, + 'notchecked' => $this->missing, + 'count' => $count, + 'updated' => 'false', + ]; + } else { + //check index + if ($index <= $count - 1) { + $source = $this->sources[$index]; + $result = $this->getMastoBlocklist($source); + if (count($result) > 0) { + $source->list_data = json_encode($result); + $source->last_updated = Carbon::now(); + $source->save(); + array_push($this->updated, ['source' => $source->url]); + $index++; + $result = $this->updateSourceData($index); } else { - try { - $result = \Mastodon::domain('https://' . $source['url']) - ->token($source['token']) - ->get('/instance/domain_blocks'); - array_push($checked, ['source' => $source->url]); - } catch (ConnectException $e) { - } + //if empty run the same index again + array_push($this->missing, ['source' => $source->url]); + $result = $this->updateSourceData($index); } - } elseif ($source['type'] == 'custom' && $source['format'] == 'csv') { + } else { + //continue + } + return [ + 'checked' => $this->updated, + 'notchecked' => $this->missing, + 'count' => $count, + 'updated' => 'true', + ]; + } + } + + private function getMastoBlocklist($source) + { + $result = []; + if ($source['type'] == 'mastodon') { + if ($source['token'] == null) { try { - $denylist = array_map('str_getcsv', file('https://' . $source['url'])); - foreach ($denylist as $item) { - array_push($result, [ - 'domain' => $item[0], - 'severity' => $item[1], - 'comment' => $item[2]]); - } - array_push($checked, ['source' => $source->url]); - } catch (Exception $e) { - array_push($missing, ['source' => $source->url]); + $result = \Mastodon::domain('https://' . $source['url']) + ->get('/instance/domain_blocks'); + //array_push($checked, ['source' => $source->url]); + } catch (ConnectException $e) { + //dd($source); + //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) { + //array_push($missing, ['source' => $source->url]); + //dd($source); } } - - $source->list_data = json_encode($result); - $source->last_updated = Carbon::now(); - $source->save(); + } elseif ($source['type'] == 'custom' && $source['format'] == 'csv') { + try { + $denylist = array_map('str_getcsv', file('https://' . $source['url'])); + foreach ($denylist as $item) { + array_push($result, [ + 'domain' => $item[0], + 'severity' => $item[1], + 'comment' => $item[2]]); + } + array_push($checked, ['source' => $source->url]); + } catch (Exception $e) { + array_push($missing, ['source' => $source->url]); + } } - return ['checked' => $checked, 'notchecked' => $missing]; + return $result; } } diff --git a/app/Services/UpdateService.php b/app/Services/UpdateService.php index 95436ef..b275b0a 100644 --- a/app/Services/UpdateService.php +++ b/app/Services/UpdateService.php @@ -23,8 +23,11 @@ class UpdateService public function data() { $response = $this->source->updateSourceData(); - return count($response['checked']) . ' SOURCES UPDATED - ' . - count($response['notchecked']) . ' SOURCES NOT CHECKED'; + if ($response['updated'] == 'true') { + return count($response['checked']) . ' SOURCES UPDATED'; + } else { + return 'NO SOURCES PRESENT'; + } } public function list() diff --git a/public/assets/css/global/frame.css b/public/assets/css/global/frame.css index e14b28c..e2bdef3 100644 --- a/public/assets/css/global/frame.css +++ b/public/assets/css/global/frame.css @@ -199,9 +199,8 @@ footer { padding: 10px; gap: 10px; height: auto; - width: 80%; + width: auto; margin: 20px auto; - max-width: 1000px; position: relative; } diff --git a/resources/views/frame.blade.php b/resources/views/frame.blade.php index 4dda0d0..a03b791 100644 --- a/resources/views/frame.blade.php +++ b/resources/views/frame.blade.php @@ -3,7 +3,7 @@ - + @yield('title') diff --git a/resources/views/front/index.blade.php b/resources/views/front/index.blade.php index efce5ad..ce74730 100644 --- a/resources/views/front/index.blade.php +++ b/resources/views/front/index.blade.php @@ -38,27 +38,8 @@ @endisset <section class="index-meta"> <article> - <h2>Recent Updates</h2> - @foreach($recent as $item) - <a class="list-link" role="listitem" href="/location/{{$item->uuid}}"> - @php - $rating = floor(($item->actions_count / $sources)*100); - @endphp - <span class="item-rating">{{$rating}}%</span> - <label class="item-name">{{$item->name}}</label> - <div class="item-silence"> - <img class="item-icon" src="/assets/images/global/status-silence.svg" title="silenced" /> - {{$item->silence_count}} - </div> - <div class="item-block"> - <img class="item-icon" src="/assets/images/global/status-suspend.svg" title="suspended" /> - {{$item->block_count}} - </div> - </a> - @endforeach - <h2>Info</h2> <div class="index-meta"> - <label>Locations Tracked</label> + <label>Active Locations Tracked</label> <label>{{$count}}</label> <label>Total Sources</label> <label>{{$sources}}</label>