Merge pull request #2733 from pixelfed/staging

Staging
This commit is contained in:
daniel 2021-04-20 23:32:58 -06:00 committed by GitHub
commit de8ee9f21f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 8713 additions and 6581 deletions

View file

@ -63,6 +63,9 @@
- Updated PublicApiController, show unlisted comments. ([e1c6297e](https://github.com/pixelfed/pixelfed/commit/e1c6297e))
- Updated ApiV1Controller, add missing variable. ([886ea617](https://github.com/pixelfed/pixelfed/commit/886ea617))
- Updated PublicApiController, limit network pagination to 3 months. ([10119bbb](https://github.com/pixelfed/pixelfed/commit/10119bbb))
- Updated admin instance page, add search and improve performance. ([f5829373](https://github.com/pixelfed/pixelfed/commit/f5829373))
- Updated AdminInstanceController, invalidate banned domain cache when updated. ([35393edf](https://github.com/pixelfed/pixelfed/commit/35393edf))
- Updated AP Helpers, use instance filtering. ([66b4f8c7](https://github.com/pixelfed/pixelfed/commit/66b4f8c7))
- ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)

View file

@ -14,29 +14,58 @@ trait AdminInstanceController
public function instances(Request $request)
{
$this->validate($request, [
'filter' => [
'nullable',
'string',
'min:1',
'max:20',
Rule::in(['autocw', 'unlisted', 'banned'])
Rule::in([
'cw',
'unlisted',
'banned',
// 'popular',
'new',
'all'
])
],
]);
if($request->has('filter') && $request->filled('filter')) {
if($request->has('q') && $request->filled('q')) {
$instances = Instance::where('domain', 'like', '%' . $request->input('q') . '%')->simplePaginate(10);
} else if($request->has('filter') && $request->filled('filter')) {
switch ($request->filter) {
case 'autocw':
$instances = Instance::whereAutoCw(true)->orderByDesc('id')->paginate(5);
case 'cw':
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->whereAutoCw(true)->orderByDesc('id')->simplePaginate(10);
break;
case 'unlisted':
$instances = Instance::whereUnlisted(true)->orderByDesc('id')->paginate(5);
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->whereUnlisted(true)->orderByDesc('id')->simplePaginate(10);
break;
case 'banned':
$instances = Instance::whereBanned(true)->orderByDesc('id')->paginate(5);
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->whereBanned(true)->orderByDesc('id')->simplePaginate(10);
break;
case 'new':
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->latest()->simplePaginate(10);
break;
// case 'popular':
// $popular = Profile::selectRaw('*, count(domain) as count')
// ->whereNotNull('domain')
// ->groupBy('domain')
// ->orderByDesc('count')
// ->take(10)
// ->get()
// ->pluck('domain')
// ->toArray();
// $instances = Instance::whereIn('domain', $popular)->simplePaginate(10);
// break;
default:
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->orderByDesc('id')->simplePaginate(10);
break;
}
} else {
$instances = Instance::orderByDesc('id')->paginate(5);
$instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->orderByDesc('id')->simplePaginate(10);
}
return view('admin.instances.home', compact('instances'));
}
@ -97,6 +126,10 @@ trait AdminInstanceController
break;
}
Cache::forget('instances:banned:domains');
Cache::forget('instances:unlisted:domains');
Cache::forget('instances:auto_cw:domains');
return response()->json([]);
}
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace App\Services;
use Cache;
use App\Instance;
class InstanceService
{
public static function getBannedDomains()
{
return Cache::remember('instances:banned:domains', now()->addHours(12), function() {
return Instance::whereBanned(true)->pluck('domain')->toArray();
});
}
public static function getUnlistedDomains()
{
return Cache::remember('instances:unlisted:domains', now()->addHours(12), function() {
return Instance::whereUnlisted(true)->pluck('domain')->toArray();
});
}
public static function getNsfwDomains()
{
return Cache::remember('instances:auto_cw:domains', now()->addHours(12), function() {
return Instance::whereAutoCw(true)->pluck('domain')->toArray();
});
}
}

View file

@ -6,6 +6,7 @@ use DB, Cache, Purify, Storage, Request, Validator;
use App\{
Activity,
Follower,
Instance,
Like,
Media,
Notification,
@ -25,6 +26,7 @@ use App\Util\ActivityPub\HttpSignature;
use Illuminate\Support\Str;
use App\Services\ActivityPubFetchService;
use App\Services\ActivityPubDeliveryService;
use App\Services\InstanceService;
use App\Services\MediaPathService;
use App\Services\MediaStorageService;
use App\Jobs\MediaPipeline\MediaStoragePipeline;
@ -161,19 +163,25 @@ class Helpers {
$host = parse_url($valid, PHP_URL_HOST);
if(count(dns_get_record($host, DNS_A | DNS_AAAA)) == 0) {
return false;
}
// if(count(dns_get_record($host, DNS_A | DNS_AAAA)) == 0) {
// return false;
// }
if(config('costar.enabled') == true) {
if(
(config('costar.domain.block') != null && Str::contains($host, config('costar.domain.block')) == true) ||
(config('costar.domain.block') != null && Str::contains($host, config('costar.domain.block')) == true) ||
(config('costar.actor.block') != null && in_array($url, config('costar.actor.block')) == true)
) {
return false;
}
}
$bannedInstances = InstanceService::getBannedDomains();
if(in_array($host, $bannedInstances)) {
return false;
}
if(in_array($host, $localhosts)) {
return false;
}
@ -257,7 +265,7 @@ class Helpers {
}
$res = self::fetchFromUrl($url);
if(!$res || empty($res) || isset($res['error']) ) {
return;
}
@ -269,7 +277,7 @@ class Helpers {
}
$scope = 'private';
$cw = isset($res['sensitive']) ? (bool) $res['sensitive'] : false;
if(isset($res['to']) == true) {
@ -312,13 +320,14 @@ class Helpers {
$cwDomains = config('costar.domain.cw');
if(in_array(parse_url($url, PHP_URL_HOST), $cwDomains) == true) {
$cw = true;
}
}
}
$id = isset($res['id']) ? $res['id'] : $url;
$idDomain = parse_url($id, PHP_URL_HOST);
$urlDomain = parse_url($url, PHP_URL_HOST);
if(!self::validateUrl($id)) {
return;
}
@ -347,16 +356,24 @@ class Helpers {
}
$ts = is_array($res['published']) ? $res['published'][0] : $res['published'];
if($scope == 'public' && in_array($urlDomain, InstanceService::getUnlistedDomains())) {
$scope = 'unlisted';
}
if(in_array($urlDomain, InstanceService::getNsfwDomains())) {
$cw = true;
}
$statusLockKey = 'helpers:status-lock:' . hash('sha256', $res['id']);
$status = Cache::lock($statusLockKey)
->get(function () use(
$profile,
$res,
$url,
$ts,
$reply_to,
$cw,
$scope,
$profile,
$res,
$url,
$ts,
$reply_to,
$cw,
$scope,
$id
) {
return DB::transaction(function() use($profile, $res, $url, $ts, $reply_to, $cw, $scope, $id) {
@ -426,7 +443,7 @@ class Helpers {
MediaStoragePipeline::dispatch($media);
}
}
$status->viewType();
return;
}
@ -472,21 +489,24 @@ class Helpers {
$profile = Profile::whereRemoteUrl($res['id'])->first();
if(!$profile) {
Instance::firstOrCreate([
'domain' => $domain
]);
$profileLockKey = 'helpers:profile-lock:' . hash('sha256', $res['id']);
$profile = Cache::lock($profileLockKey)->get(function () use($domain, $webfinger, $res, $runJobs) {
return DB::transaction(function() use($domain, $webfinger, $res, $runJobs) {
$profile = new Profile();
$profile->domain = strtolower($domain);
$profile->username = strtolower(Purify::clean($webfinger));
$profile->username = Purify::clean($webfinger);
$profile->name = isset($res['name']) ? Purify::clean($res['name']) : 'user';
$profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null;
$profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null;
$profile->inbox_url = strtolower($res['inbox']);
$profile->outbox_url = strtolower($res['outbox']);
$profile->remote_url = strtolower($res['id']);
$profile->inbox_url = $res['inbox'];
$profile->outbox_url = $res['outbox'];
$profile->remote_url = $res['id'];
$profile->public_key = $res['publicKey']['publicKeyPem'];
$profile->key_id = $res['publicKey']['id'];
$profile->webfinger = strtolower(Purify::clean($webfinger));
$profile->webfinger = Purify::clean($webfinger);
$profile->last_fetched_at = now();
$profile->save();
if(config('pixelfed.cloud_storage') == true) {
@ -497,7 +517,7 @@ class Helpers {
});
} else {
// Update info after 24 hours
if($profile->last_fetched_at == null ||
if($profile->last_fetched_at == null ||
$profile->last_fetched_at->lt(now()->subHours(24)) == true
) {
$profile->name = isset($res['name']) ? Purify::clean($res['name']) : 'user';

975
composer.lock generated

File diff suppressed because it is too large Load diff

14001
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -14,11 +14,11 @@
"axios": "^0.21.1",
"bootstrap": "^4.5.2",
"cross-env": "^5.2.1",
"jquery": "^3.5.1",
"lodash": "^4.17.19",
"jquery": "^3.6.0",
"lodash": "^4.17.21",
"popper.js": "^1.16.1",
"resolve-url-loader": "^2.3.2",
"sass": "^1.26.10",
"sass": "^1.32.11",
"sass-loader": "^7.3.1",
"vue": "^2.6.11",
"vue-masonry-css": "^1.0.3",
@ -39,7 +39,6 @@
"quill": "^1.3.7",
"readmore-js": "^2.2.1",
"sweetalert": "^2.1.2",
"tributejs": "^4.1.3",
"twitter-text": "^2.0.5",
"vue-blurhash": "^0.1.4",
"vue-carousel": "^0.18.0",
@ -48,7 +47,7 @@
"vue-infinite-loading": "^2.4.5",
"vue-loading-overlay": "^3.3.3",
"vue-timeago": "^5.1.2",
"vue-tribute": "^1.0.6",
"vue-tribute": "^1.0.7",
"zuck.js": "^1.6.0"
},
"collective": {

View file

@ -1,96 +1,87 @@
@extends('admin.partial.template-full')
@section('section')
<div class="title">
<h3 class="font-weight-bold d-inline-block">Instances</h3>
<span class="float-right">
<div class="dropdown">
<button class="btn btn-light btn-sm dropdown-toggle font-weight-bold" type="button" id="filterDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-filter"></i>
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="filterDropdown">
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=unlisted">Show only Unlisted</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=autocw">Show only Auto CW</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=banned">Show only Banned</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}">Show all</a>
<div class="dropdown-divider"></div>
<form class="" method="post">
@csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold btn-sm btn-block">Run Scan</button>
</form>
</div>
</div>
</span>
<div class="title d-flex justify-content-between align-items-center">
<h3 class="font-weight-bold mr-5">Instances</h3>
<div class="btn-group btn-group-sm">
<a class="btn btn-{{!request()->filled('filter')||request()->query('filter')=='all'?'primary':'outline-primary'}} font-weight-bold" href="?filter=all">All</a>
{{-- <a class="btn btn-{{request()->query('filter')=='popular'?'primary':'outline-primary'}} font-weight-bold" href="?filter=popular">Popular</a> --}}
<a class="btn btn-{{request()->query('filter')=='new'?'primary':'outline-primary'}} font-weight-bold" href="?filter=new">New</a>
<a class="btn btn-{{request()->query('filter')=='cw'?'primary':'outline-primary'}} font-weight-bold" href="?filter=cw">CW</a>
<a class="btn btn-{{request()->query('filter')=='banned'?'primary':'outline-primary'}} font-weight-bold" href="?filter=banned">Banned</a>
<a class="btn btn-{{request()->query('filter')=='unlisted'?'primary':'outline-primary'}} font-weight-bold" href="?filter=unlisted">Unlisted</a>
</div>
<div class="">
</div>
<form class="" method="get">
<input class="form-control rounded-pill" name="q" value="{{request()->query('q')}}" placeholder="Search domain">
</form>
</div>
<hr>
@if($instances->count() == 0 && request()->has('filter') == false)
<div class="alert alert-warning mb-3">
<p class="lead font-weight-bold mb-0">Warning</p>
<p class="font-weight-lighter mb-0">No instances were found.</p>
</div>
<p class="font-weight-lighter">Do you want to scan and populate instances from Profiles and Statuses?</p>
<p>
<form method="post">
@csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold">Run Scan</button>
</form>
</p>
@else
<ul class="list-group">
@foreach($instances as $instance)
<li class="list-group-item">
<div class="d-flex justify-content-between align-items-center">
<div>
<p class="h4 font-weight-normal mb-1">
{{$instance->domain}}
</p>
<p class="mb-0">
<a class="btn btn-outline-primary btn-sm py-0 font-weight-normal" href="{{$instance->getUrl()}}">Overview</a>
<button class="btn btn-outline-secondary btn-sm py-0 font-weight-normal btn-action mr-3"
data-instance-id="{{$instance->id}}"
data-instance-domain="{{$instance->domain}}"
data-instance-unlisted="{{$instance->unlisted}}"
data-instance-autocw="{{$instance->auto_cw}}"
data-instance-banned="{{$instance->banned}}"
>Actions</button>
@if($instance->unlisted)
<i class="fas fa-minus-circle text-danger" data-toggle="tooltip" title="Unlisted from timelines"></i>
@endif
@if($instance->auto_cw)
<i class="fas fa-eye-slash text-danger" data-toggle="tooltip" title="CW applied to all media"></i>
@endif
@if($instance->banned)
<i class="fas fa-shield-alt text-danger" data-toggle="tooltip" title="Instance is banned"></i>
@endif
</p>
</div>
<div>
<div class="d-inline-block pr-4">
<p class="h4 font-weight-light text-center">{{$instance->profiles()->count()}}</p>
<p class="mb-0 small font-weight-normal text-muted">Profiles</p>
</div>
<div class="d-inline-block pr-4">
<p class="h4 font-weight-light text-center">{{$instance->statuses()->count()}}</p>
<p class="mb-0 small font-weight-normal text-muted">Statuses</p>
</div>
<div class="d-inline-block pr-4">
<p class="h4 font-weight-light text-center text-muted">{{$instance->reported()->count()}}</p>
<p class="mb-0 small font-weight-normal text-muted">Reports</p>
</div>
<div class="d-inline-block">
<p class="h4 font-weight-light text-center text-muted filesize" data-size="{{$instance->media()->sum('size')}}">0</p>
<p class="mb-0 small font-weight-normal text-muted">Storage Used</p>
</div>
</div>
<div class="row">
<div class="col-12 col-md-8 offset-md-2">
@if($instances->count() == 0 && !request()->has('filter') && !request()->has('q'))
<div class="alert alert-warning mb-3">
<p class="lead font-weight-bold mb-0">Warning</p>
<p class="font-weight-lighter mb-0">No instances were found.</p>
</div>
</li>
@endforeach
</ul>
<div class="d-flex justify-content-center mt-5 small">
{{$instances->links()}}
<p class="font-weight-lighter">Do you want to scan and populate instances from Profiles and Statuses?</p>
<p>
<form method="post">
@csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold">Run Scan</button>
</form>
</p>
@else
<ul class="list-group">
@foreach($instances as $instance)
<li class="list-group-item">
<div>
<div class="d-flex justify-content-between align-items-center">
<p class="h4 font-weight-light mb-0 text-break mr-2">
{{$instance->domain}}
</p>
<p class="mb-0 text-right" style="min-width: 210px;">
@if($instance->unlisted)
<i class="fas fa-minus-circle text-danger" data-toggle="tooltip" title="Unlisted from timelines"></i>
@endif
@if($instance->auto_cw)
<i class="fas fa-eye-slash text-danger" data-toggle="tooltip" title="CW applied to all media"></i>
@endif
@if($instance->banned)
<i class="fas fa-shield-alt text-danger" data-toggle="tooltip" title="Instance is banned"></i>
@endif
<a class="btn btn-outline-primary btn-sm py-0 font-weight-normal ml-2" href="{{$instance->getUrl()}}">Overview</a>
<button class="btn btn-outline-secondary btn-sm py-0 font-weight-normal btn-action"
data-instance-id="{{$instance->id}}"
data-instance-domain="{{$instance->domain}}"
data-instance-unlisted="{{$instance->unlisted}}"
data-instance-autocw="{{$instance->auto_cw}}"
data-instance-banned="{{$instance->banned}}"
>Actions</button>
</p>
</div>
</div>
</li>
@endforeach
</ul>
<div class="d-flex justify-content-center mt-5 small">
{{$instances->links()}}
</div>
@endif
@if(request()->filled('q') && $instances->count() == 0)
<p class="text-center lead mb-0">No results found</p>
<p class="text-center font-weight-bold mb-0"><a href="/i/admin/instances">Go back</a></p>
@endif
@if(request()->filled('filter') && $instances->count() == 0)
<p class="text-center lead mb-0">No results found</p>
<p class="text-center font-weight-bold mb-0"><a href="/i/admin/instances">Go back</a></p>
@endif
</div>
</div>
@endif
@endsection
@push('scripts')
@ -109,7 +100,7 @@
let banned = this.getAttribute('data-instance-banned');
swal({
title: 'Instance Actions',
text: text,
text: text,
icon: 'warning',
buttons: {
unlist: {
@ -224,4 +215,4 @@
})
});
</script>
@endpush
@endpush