Compare commits

...

3 commits

Author SHA1 Message Date
ro
2932af0d3f show multiple instance comments
the previous update cycle only showed the latest comment from Sources
concerning a specific instance

now all available comments are pulled from denylist data to be displayed
under Description on the front end
2024-09-17 15:41:31 -06:00
ro
0eeab6355e updated image uploading, edited html templates
changed the the way files are uploaded to go into their own directory
called 'references' organized by location, identified by uuid. the
'references' directory was added to git ignore to those images are not
saved in the repo, since every install will have their own set of images

also updated reference links to be shown on the front end if they have
been added to a location

unnecessary links where moved from the admin member template since they
have been incorporated into the appropriate area.

a template for editing member account information has also been added.
2024-09-13 15:12:43 -06:00
ro
43e0004ac5 Updated blocklist retrival process, template edits
The process for updating blocklists per source wasn't effecient, so it
has been rewritten to process each source individually before moving on,
relieving some processing load on the server and ensuring every source
comes back with data, even in the event it doesn't grab it the first
time.

also removed the recent list from the index page as the recently updated
list doesn't reflect what's been the last to get updated and changed the
theme color to match the current palette.
2024-09-12 19:20:13 -06:00
14 changed files with 155 additions and 78 deletions

1
.gitignore vendored
View file

@ -4,6 +4,7 @@
/public/hot
/public/storage
/public/reference
/public/assets/images/references
/storage/*.key
/vendor
.env

View file

@ -34,6 +34,16 @@ class DenController extends Controller
]);
}
public function profile(Request $request)
{
$member = Auth::user();
return view('back.profile', [
'handle' => $member->handle,
'title' => "Your Profile",
'role' => $member->role
]);
}
public function member(Request $request)
{
$member = Auth::user();

View file

@ -79,12 +79,16 @@ class FrontIndexController extends Controller
($member->role == 1 || $member->role == 2) ? $edit = true : $edit = false;
}
$links = explode(',', $location->archive_links);
$comments = explode('+', $location->description);
return view('front.location', [
'title' => str_replace(".", " ", $name),
'location' => $location,
'comments' => $comments,
'actions' => $location->block_count + $location->silence_count,
'sources_count' => count($sources),
'images' => json_decode($location->images),
'links' => $links,
'updated' => $location->updated_at->format('Y M d'),
'edit' => $edit
]);

View file

@ -56,24 +56,34 @@ class LocationRepository
public function editLocation($request)
{
$location = $this->getLocation($request->id);
$images = [];
$location = $this->getLocation($request->id);
$publicPath = '../public/';
$refPath = 'assets/images/references/' . $location->uuid;
$images = [];
if ($request->hasfile("references")) {
foreach ($request->references as $file) {
$path = $file->store('reference');
array_push($images, ["path" => $path]);
if (!is_dir($publicPath . $refPath)) {
mkdir($publicPath . $refPath, 0755, true);
}
$filename = urlencode($file->getClientOriginalName());
$file->move($publicPath . $refPath, $filename);
//$path = $file->store('reference');
array_push($images, ["path" => '/' . $refPath . '/' . $filename]);
}
}
$request->merge(['images' => json_encode($images)]);
if (!empty($images)) {
$request->merge(['images' => json_encode($images)]);
$location->images = json_encode($images);
}
$location->name = $request->name;
$location->description = $request->description;
$location->archive_links = $request->archive_links;
$location->images = json_encode($images);
$result = [];
if ($location->save()) {
return ['status' => true, 'message' => "Location Editited -IMG- " . $request->hasfile("references")];
return ['status' => true, 'message' => "Location Editited" . $request->hasfile("references")];
} else {
return ['status' => false, 'message' => "Location Not Editited"];
}

View file

@ -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,80 @@ class SourceRepository
return $this->source::where("active", true)->get();
}
public function updateSourceData()
public function updateSourceData($index = 0)
{
$sources = $this->getActive();
$missing = [];
$checked = [];
//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');
} catch (ConnectException $e) {
//TODO: Logo Errors
}
} else {
try {
$result = \Mastodon::domain('https://' . $source['url'])
->token($source['token'])
->get('/instance/domain_blocks');
} catch (ConnectException $e) {
//TODO: Logo Errors
}
}
$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;
}
}

View file

@ -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()
@ -33,14 +36,15 @@ class UpdateService
$fresh = 0;
$unified = [];
$sources = $this->source->getActive();
$sources = $this->source->getActive();
$locations = $this->location->getActiveLocations();
foreach ($sources as $source) {
//$listData = json_decode();
foreach (json_decode($source->list_data) as $item) {
$index = array_search($item->domain, array_column($unified, 'url'));
if ($index) {
//if there is a match, update the count
//if there is a match, update the count and comment
if ($item->severity == "suspend" || $item->severity == "defederate") {
++$unified[$index]['block_count'];
array_push($unified[$index]['block_vote'], $source->url);
@ -48,6 +52,9 @@ class UpdateService
++$unified[$index]['silence_count'];
array_push($unified[$index]['silence_vote'], $source->url);
}
if (!is_null($item->comment) && $item->comment != ' ' && $item->comment != '') {
$unified[$index]['comment'] = $item->comment . '+' . $unified[$index]['comment'];
}
} else {
$silence = 0;
$suspend = 0;
@ -74,6 +81,12 @@ class UpdateService
}
}
//clear out all previous descriptions
foreach ($locations as $loc) {
$loc->description = ' ';
$loc->save();
}
foreach ($unified as $item) {
$location = $this->location->getLocation($item['url']);
if ($location) {
@ -86,6 +99,12 @@ class UpdateService
$location->silence_count = $item['silence_count'];
$location->silence_vote = [];
$location->silence_vote = $item['silence_vote'];
//clear descriptions
if (!is_null($item['comment']) || !$item['comment'] != " ") {
$location->description = $item['comment'];
} else {
$location->description = 'description pending';
}
$location->actions_count = $item['block_count'] + $item['silence_count'];

View file

@ -199,9 +199,8 @@ footer {
padding: 10px;
gap: 10px;
height: auto;
width: 80%;
width: auto;
margin: 20px auto;
max-width: 1000px;
position: relative;
}

View file

@ -24,7 +24,7 @@
<h3>Images</h3>
@if($images != null)
@foreach($images as $image)
<a href="/{{$image->path}}" class="location-image" style="background: url(/{{$image->path}}) no-repeat center center / cover #fc6399" />
<a href="{{$image->path}}" class="location-image" style="background: url({{$image->path}}) no-repeat center center / cover #fc6399" />
</a>
@endforeach
@endif

View file

@ -6,8 +6,6 @@
<section>
<article>
<h2>Member Listing </h2>
<a href="/den/admin/update">UPDATE LOCATIONS</a><br />
<a href="/den/admin/compile">COMPILE LOCATIONS</a>
</article>
</section>
@endsection

View file

@ -0,0 +1,12 @@
@extends('frame')
@section('title', 'Den | Your Profile')
@section('main-content')
<section>
<article>
<h2>Edit Profile Deets </h2>
Hi. This is where you change stuff.
</article>
</section>
@endsection

View file

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="theme-color" content="#d66365" />
<meta name="theme-color" content="#c3639e" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
@yield('title')

View file

@ -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>

View file

@ -7,12 +7,16 @@
<section>
<article>
<h2>Description</h2>
{{$location->description}}<br />
@foreach($comments as $comment)
@if($comment != " " && $comment != '')
{{trim($comment)}}<br /><br />
@endif
@endforeach
<h2>References</h2>
<h3>Images</h3>
@if($images != null)
@foreach($images as $image)
<a href="/{{$image->path}}" class="location-image" style="background: url(/{{$image->path}}) no-repeat center center / cover #fc6399" />
<a href="{{$image->path}}" class="location-image" style="background: url({{$image->path}}) no-repeat center center / cover #fc6399" />
</a>
@endforeach
@endif
@ -21,6 +25,9 @@
$rating = floor(($action / $sources_count)*100);
@endphp
<h3>Links</h3>
@foreach($links as $link)
<a href="{{$link}}">{{$link}}</a><br />
@endforeach
<div class="location-rating">
<div>
<img class="rating-icon" src="/assets/images/global/heat.svg" title="heat-rating" />

View file

@ -40,6 +40,7 @@ Route::get("/logout", [AuthController::class, 'leave']);
//back
Route::group(['prefix' => 'den', 'middleware' => 'member.check'], function () {
Route::get("/", [DenController::class, 'start']);
Route::get("/you", [DenController::class, 'profile']);
Route::get("/member", [DenController::class, 'member']);
Route::get("/listings/{pageNum}", [DenController::class, 'location']);
Route::get("/location/edit/{uuid}", [DenController::class, 'locationEdit']);