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 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 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 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/)) - ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10) ## [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) public function instances(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'filter' => [ 'filter' => [
'nullable', 'nullable',
'string', 'string',
'min:1', 'min:1',
'max:20', '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) { switch ($request->filter) {
case 'autocw': case 'cw':
$instances = Instance::whereAutoCw(true)->orderByDesc('id')->paginate(5); $instances = Instance::select('id', 'domain', 'unlisted', 'auto_cw', 'banned')->whereAutoCw(true)->orderByDesc('id')->simplePaginate(10);
break; break;
case 'unlisted': 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; break;
case 'banned': 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; break;
} }
} else { } 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')); return view('admin.instances.home', compact('instances'));
} }
@ -97,6 +126,10 @@ trait AdminInstanceController
break; break;
} }
Cache::forget('instances:banned:domains');
Cache::forget('instances:unlisted:domains');
Cache::forget('instances:auto_cw:domains');
return response()->json([]); 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\{ use App\{
Activity, Activity,
Follower, Follower,
Instance,
Like, Like,
Media, Media,
Notification, Notification,
@ -25,6 +26,7 @@ use App\Util\ActivityPub\HttpSignature;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Services\ActivityPubFetchService; use App\Services\ActivityPubFetchService;
use App\Services\ActivityPubDeliveryService; use App\Services\ActivityPubDeliveryService;
use App\Services\InstanceService;
use App\Services\MediaPathService; use App\Services\MediaPathService;
use App\Services\MediaStorageService; use App\Services\MediaStorageService;
use App\Jobs\MediaPipeline\MediaStoragePipeline; use App\Jobs\MediaPipeline\MediaStoragePipeline;
@ -161,9 +163,9 @@ class Helpers {
$host = parse_url($valid, PHP_URL_HOST); $host = parse_url($valid, PHP_URL_HOST);
if(count(dns_get_record($host, DNS_A | DNS_AAAA)) == 0) { // if(count(dns_get_record($host, DNS_A | DNS_AAAA)) == 0) {
return false; // return false;
} // }
if(config('costar.enabled') == true) { if(config('costar.enabled') == true) {
if( if(
@ -174,6 +176,12 @@ class Helpers {
} }
} }
$bannedInstances = InstanceService::getBannedDomains();
if(in_array($host, $bannedInstances)) {
return false;
}
if(in_array($host, $localhosts)) { if(in_array($host, $localhosts)) {
return false; return false;
} }
@ -319,6 +327,7 @@ class Helpers {
$idDomain = parse_url($id, PHP_URL_HOST); $idDomain = parse_url($id, PHP_URL_HOST);
$urlDomain = parse_url($url, PHP_URL_HOST); $urlDomain = parse_url($url, PHP_URL_HOST);
if(!self::validateUrl($id)) { if(!self::validateUrl($id)) {
return; return;
} }
@ -347,6 +356,14 @@ class Helpers {
} }
$ts = is_array($res['published']) ? $res['published'][0] : $res['published']; $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']); $statusLockKey = 'helpers:status-lock:' . hash('sha256', $res['id']);
$status = Cache::lock($statusLockKey) $status = Cache::lock($statusLockKey)
->get(function () use( ->get(function () use(
@ -472,21 +489,24 @@ class Helpers {
$profile = Profile::whereRemoteUrl($res['id'])->first(); $profile = Profile::whereRemoteUrl($res['id'])->first();
if(!$profile) { if(!$profile) {
Instance::firstOrCreate([
'domain' => $domain
]);
$profileLockKey = 'helpers:profile-lock:' . hash('sha256', $res['id']); $profileLockKey = 'helpers:profile-lock:' . hash('sha256', $res['id']);
$profile = Cache::lock($profileLockKey)->get(function () use($domain, $webfinger, $res, $runJobs) { $profile = Cache::lock($profileLockKey)->get(function () use($domain, $webfinger, $res, $runJobs) {
return DB::transaction(function() use($domain, $webfinger, $res, $runJobs) { return DB::transaction(function() use($domain, $webfinger, $res, $runJobs) {
$profile = new Profile(); $profile = new Profile();
$profile->domain = strtolower($domain); $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->name = isset($res['name']) ? Purify::clean($res['name']) : 'user';
$profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null; $profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null;
$profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null; $profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null;
$profile->inbox_url = strtolower($res['inbox']); $profile->inbox_url = $res['inbox'];
$profile->outbox_url = strtolower($res['outbox']); $profile->outbox_url = $res['outbox'];
$profile->remote_url = strtolower($res['id']); $profile->remote_url = $res['id'];
$profile->public_key = $res['publicKey']['publicKeyPem']; $profile->public_key = $res['publicKey']['publicKeyPem'];
$profile->key_id = $res['publicKey']['id']; $profile->key_id = $res['publicKey']['id'];
$profile->webfinger = strtolower(Purify::clean($webfinger)); $profile->webfinger = Purify::clean($webfinger);
$profile->last_fetched_at = now(); $profile->last_fetched_at = now();
$profile->save(); $profile->save();
if(config('pixelfed.cloud_storage') == true) { if(config('pixelfed.cloud_storage') == true) {

975
composer.lock generated

File diff suppressed because it is too large Load diff

13997
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

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

View file

@ -1,30 +1,28 @@
@extends('admin.partial.template-full') @extends('admin.partial.template-full')
@section('section') @section('section')
<div class="title"> <div class="title d-flex justify-content-between align-items-center">
<h3 class="font-weight-bold d-inline-block">Instances</h3> <h3 class="font-weight-bold mr-5">Instances</h3>
<span class="float-right"> <div class="btn-group btn-group-sm">
<div class="dropdown"> <a class="btn btn-{{!request()->filled('filter')||request()->query('filter')=='all'?'primary':'outline-primary'}} font-weight-bold" href="?filter=all">All</a>
<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"> {{-- <a class="btn btn-{{request()->query('filter')=='popular'?'primary':'outline-primary'}} font-weight-bold" href="?filter=popular">Popular</a> --}}
<i class="fas fa-filter"></i> <a class="btn btn-{{request()->query('filter')=='new'?'primary':'outline-primary'}} font-weight-bold" href="?filter=new">New</a>
</button> <a class="btn btn-{{request()->query('filter')=='cw'?'primary':'outline-primary'}} font-weight-bold" href="?filter=cw">CW</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="filterDropdown"> <a class="btn btn-{{request()->query('filter')=='banned'?'primary':'outline-primary'}} font-weight-bold" href="?filter=banned">Banned</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=unlisted">Show only Unlisted</a> <a class="btn btn-{{request()->query('filter')=='unlisted'?'primary':'outline-primary'}} font-weight-bold" href="?filter=unlisted">Unlisted</a>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=autocw">Show only Auto CW</a> </div>
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}?filter=banned">Show only Banned</a> <div class="">
<a class="dropdown-item font-weight-light" href="{{route('admin.instances')}}">Show all</a> </div>
<div class="dropdown-divider"></div> <form class="" method="get">
<form class="" method="post"> <input class="form-control rounded-pill" name="q" value="{{request()->query('q')}}" placeholder="Search domain">
@csrf
<button type="submit" class="btn btn-primary py-1 font-weight-bold btn-sm btn-block">Run Scan</button>
</form> </form>
</div> </div>
</div>
</span>
</div>
<hr> <hr>
@if($instances->count() == 0 && request()->has('filter') == false)
<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"> <div class="alert alert-warning mb-3">
<p class="lead font-weight-bold mb-0">Warning</p> <p class="lead font-weight-bold mb-0">Warning</p>
<p class="font-weight-lighter mb-0">No instances were found.</p> <p class="font-weight-lighter mb-0">No instances were found.</p>
@ -40,20 +38,12 @@
<ul class="list-group"> <ul class="list-group">
@foreach($instances as $instance) @foreach($instances as $instance)
<li class="list-group-item"> <li class="list-group-item">
<div class="d-flex justify-content-between align-items-center">
<div> <div>
<p class="h4 font-weight-normal mb-1"> <div class="d-flex justify-content-between align-items-center">
<p class="h4 font-weight-light mb-0 text-break mr-2">
{{$instance->domain}} {{$instance->domain}}
</p> </p>
<p class="mb-0"> <p class="mb-0 text-right" style="min-width: 210px;">
<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) @if($instance->unlisted)
<i class="fas fa-minus-circle text-danger" data-toggle="tooltip" title="Unlisted from timelines"></i> <i class="fas fa-minus-circle text-danger" data-toggle="tooltip" title="Unlisted from timelines"></i>
@endif @endif
@ -63,26 +53,16 @@
@if($instance->banned) @if($instance->banned)
<i class="fas fa-shield-alt text-danger" data-toggle="tooltip" title="Instance is banned"></i> <i class="fas fa-shield-alt text-danger" data-toggle="tooltip" title="Instance is banned"></i>
@endif @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> </p>
</div> </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> </div>
</li> </li>
@endforeach @endforeach
@ -91,6 +71,17 @@
{{$instances->links()}} {{$instances->links()}}
</div> </div>
@endif @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>
@endsection @endsection
@push('scripts') @push('scripts')