mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
commit
268804856b
9 changed files with 326 additions and 12 deletions
|
@ -27,8 +27,8 @@ use App\Services\StoryService;
|
|||
use App\Services\ModLogService;
|
||||
use App\Jobs\DeletePipeline\DeleteAccountPipeline;
|
||||
use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline;
|
||||
use App\Jobs\DeletePipeline\DeleteRemoteStatusPipeline;
|
||||
use App\Jobs\StatusPipeline\StatusDelete;
|
||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||
use App\Http\Resources\AdminReport;
|
||||
use App\Http\Resources\AdminSpamReport;
|
||||
use App\Services\NotificationService;
|
||||
|
@ -1049,7 +1049,7 @@ trait AdminReportController
|
|||
StatusDelete::dispatch($status)->onQueue('high');
|
||||
} else {
|
||||
NetworkTimelineService::del($status->id);
|
||||
DeleteRemoteStatusPipeline::dispatch($status)->onQueue('high');
|
||||
RemoteStatusDelete::dispatch($status)->onQueue('high');
|
||||
}
|
||||
|
||||
Report::whereObjectId($report->object_id)
|
||||
|
|
|
@ -34,6 +34,7 @@ use App\Mail\PasswordChange;
|
|||
use App\Mail\ConfirmAppEmail;
|
||||
use App\Http\Resources\StatusStateless;
|
||||
use App\Jobs\StatusPipeline\StatusDelete;
|
||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||
use App\Jobs\ReportPipeline\ReportNotifyAdminViaEmail;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
|
||||
|
@ -838,7 +839,7 @@ class ApiV1Dot1Controller extends Controller
|
|||
Cache::forget('profile:embed:' . $status->profile_id);
|
||||
StatusService::del($status->id, true);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
StatusDelete::dispatch($status);
|
||||
$status->uri ? RemoteStatusDelete::dispatch($status) : StatusDelete::dispatch($status);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
||||
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
||||
use App\Jobs\StatusPipeline\StatusDelete;
|
||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||
use App\Jobs\SharePipeline\SharePipeline;
|
||||
use App\Jobs\SharePipeline\UndoSharePipeline;
|
||||
use App\AccountInterstitial;
|
||||
|
@ -242,7 +243,7 @@ class StatusController extends Controller
|
|||
Cache::forget('profile:embed:' . $status->profile_id);
|
||||
StatusService::del($status->id, true);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
StatusDelete::dispatch($status);
|
||||
$status->uri ? RemoteStatusDelete::dispatch($status) : StatusDelete::dispatch($status);
|
||||
}
|
||||
} else if ($status->profile_id == $user->profile_id || $user->is_admin == true) {
|
||||
Cache::forget('_api:statuses:recent_9:' . $status->profile_id);
|
||||
|
@ -250,7 +251,7 @@ class StatusController extends Controller
|
|||
Cache::forget('profile:embed:' . $status->profile_id);
|
||||
StatusService::del($status->id, true);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
StatusDelete::dispatch($status);
|
||||
$status->uri ? RemoteStatusDelete::dispatch($status) : StatusDelete::dispatch($status);
|
||||
}
|
||||
|
||||
if($request->wantsJson()) {
|
||||
|
|
30
app/Http/Resources/AdminProfile.php
Normal file
30
app/Http/Resources/AdminProfile.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Services\AccountService;
|
||||
|
||||
class AdminProfile extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$res = AccountService::get($this->id, true);
|
||||
$res['domain'] = $this->domain;
|
||||
$res['status'] = $this->status;
|
||||
$res['limits'] = [
|
||||
'exist' => $this->cw || $this->unlisted || $this->no_autolink,
|
||||
'autocw' => (bool) $this->cw,
|
||||
'unlisted' => (bool) $this->unlisted,
|
||||
'no_autolink' => (bool) $this->no_autolink,
|
||||
'banned' => (bool) $this->status == 'banned'
|
||||
];
|
||||
return $res;
|
||||
}
|
||||
}
|
139
app/Jobs/AdminPipeline/AdminProfileActionPipeline.php
Normal file
139
app/Jobs/AdminPipeline/AdminProfileActionPipeline.php
Normal file
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\AdminPipeline;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Avatar;
|
||||
use App\Follower;
|
||||
use App\Instance;
|
||||
use App\Media;
|
||||
use App\Profile;
|
||||
use App\Status;
|
||||
use Cache;
|
||||
use Storage;
|
||||
use Purify;
|
||||
use App\Services\ActivityPubFetchService;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\Services\StatusService;
|
||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||
|
||||
class AdminProfileActionPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $action;
|
||||
protected $profile;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($profile, $action)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
$action = $this->action;
|
||||
|
||||
switch($action) {
|
||||
case 'mark-all-cw':
|
||||
return $this->markAllPostsWithContentWarnings();
|
||||
break;
|
||||
case 'unlist-all':
|
||||
return $this->unlistAllPosts();
|
||||
break;
|
||||
case 'purge':
|
||||
return $this->purgeAllPosts();
|
||||
break;
|
||||
case 'refetch':
|
||||
return $this->refetchAllPosts();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function markAllPostsWithContentWarnings()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
|
||||
foreach(Status::whereProfileId($profile->id)->lazyById(10, 'id') as $status) {
|
||||
if($status->scope == 'direct') {
|
||||
continue;
|
||||
}
|
||||
$status->is_nsfw = true;
|
||||
$status->save();
|
||||
StatusService::del($status->id);
|
||||
}
|
||||
}
|
||||
|
||||
protected function unlistAllPosts()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
|
||||
foreach(Status::whereProfileId($profile->id)->lazyById(10, 'id') as $status) {
|
||||
if($status->scope != 'public') {
|
||||
continue;
|
||||
}
|
||||
$status->scope = 'unlisted';
|
||||
$status->visibility = 'unlisted';
|
||||
$status->save();
|
||||
StatusService::del($status->id);
|
||||
}
|
||||
}
|
||||
|
||||
protected function purgeAllPosts()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
|
||||
foreach(Status::withTrashed()->whereProfileId($profile->id)->lazyById(10, 'id') as $status) {
|
||||
RemoteStatusDelete::dispatch($status)->onQueue('delete');
|
||||
}
|
||||
}
|
||||
|
||||
protected function refetchAllPosts()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
$res = ActivityPubFetchService::get($profile->remote_url, false);
|
||||
if(!$res) {
|
||||
return;
|
||||
}
|
||||
$res = json_decode($res, true);
|
||||
$profile->following_count = Follower::whereProfileId($profile->id)->count();
|
||||
$profile->followers_count = Follower::whereFollowingId($profile->id)->count();
|
||||
$profile->name = isset($res['name']) ? Purify::clean($res['name']) : $profile->username;
|
||||
$profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null;
|
||||
if(isset($res['publicKey'])) {
|
||||
$profile->public_key = $res['publicKey']['publicKeyPem'];
|
||||
}
|
||||
if(
|
||||
isset($res['icon']) &&
|
||||
isset(
|
||||
$res['icon']['type'],
|
||||
$res['icon']['mediaType'],
|
||||
$res['icon']['url']) && $res['icon']['type'] == 'Image'
|
||||
) {
|
||||
if(in_array($res['icon']['mediaType'], ['image/jpeg', 'image/png'])) {
|
||||
$profile->avatar->remote_url = $res['icon']['url'];
|
||||
$profile->push();
|
||||
MediaStorageService::avatar($profile->avatar);
|
||||
}
|
||||
}
|
||||
$profile->save();
|
||||
AccountService::del($profile->id);
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ use App\Models\Conversation;
|
|||
use App\Models\Poll;
|
||||
use App\Models\PollVote;
|
||||
use App\Services\AccountService;
|
||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||
|
||||
class DeleteRemoteProfilePipeline implements ShouldQueue
|
||||
{
|
||||
|
@ -86,7 +87,7 @@ class DeleteRemoteProfilePipeline implements ShouldQueue
|
|||
Status::whereProfileId($pid)
|
||||
->chunk(50, function($statuses) {
|
||||
foreach($statuses as $status) {
|
||||
DeleteRemoteStatusPipeline::dispatch($status)->onQueue('delete');
|
||||
RemoteStatusDelete::dispatch($status)->onQueue('delete');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
140
app/Jobs/StatusPipeline/RemoteStatusDelete.php
Normal file
140
app/Jobs/StatusPipeline/RemoteStatusDelete.php
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\StatusPipeline;
|
||||
|
||||
use DB, Cache, Storage;
|
||||
use App\{
|
||||
AccountInterstitial,
|
||||
Bookmark,
|
||||
CollectionItem,
|
||||
DirectMessage,
|
||||
Like,
|
||||
Media,
|
||||
MediaTag,
|
||||
Mention,
|
||||
Notification,
|
||||
Report,
|
||||
Status,
|
||||
StatusArchived,
|
||||
StatusHashtag,
|
||||
StatusView
|
||||
};
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use League\Fractal;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use App\Transformer\ActivityPub\Verb\DeleteNote;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use GuzzleHttp\Pool;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Promise;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\CollectionService;
|
||||
use App\Services\StatusService;
|
||||
use App\Jobs\MediaPipeline\MediaDeletePipeline;
|
||||
|
||||
class RemoteStatusDelete implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
public $timeout = 90;
|
||||
public $tries = 2;
|
||||
public $maxExceptions = 1;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Status $status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$status = $this->status;
|
||||
|
||||
if($status->deleted_at) {
|
||||
return;
|
||||
}
|
||||
$profile = $this->status->profile;
|
||||
|
||||
StatusService::del($status->id, true);
|
||||
|
||||
if($profile->status_count && $profile->status_count > 0) {
|
||||
$profile->status_count = $profile->status_count - 1;
|
||||
$profile->save();
|
||||
}
|
||||
|
||||
return $this->unlinkRemoveMedia($status);
|
||||
}
|
||||
|
||||
public function unlinkRemoveMedia($status)
|
||||
{
|
||||
|
||||
if($status->in_reply_to_id) {
|
||||
$parent = Status::findOrFail($status->in_reply_to_id);
|
||||
--$parent->reply_count;
|
||||
$parent->save();
|
||||
StatusService::del($parent->id);
|
||||
}
|
||||
|
||||
AccountInterstitial::where('item_type', 'App\Status')
|
||||
->where('item_id', $status->id)
|
||||
->delete();
|
||||
Bookmark::whereStatusId($status->id)->delete();
|
||||
CollectionItem::whereObjectType('App\Status')
|
||||
->whereObjectId($status->id)
|
||||
->get()
|
||||
->each(function($col) {
|
||||
CollectionService::removeItem($col->collection_id, $col->object_id);
|
||||
$col->delete();
|
||||
});
|
||||
DirectMessage::whereStatusId($status->id)->delete();
|
||||
Like::whereStatusId($status->id)->forceDelete();
|
||||
Media::whereStatusId($status->id)
|
||||
->get()
|
||||
->each(function($media) {
|
||||
MediaDeletePipeline::dispatch($media)->onQueue('mmo');
|
||||
});
|
||||
MediaTag::where('status_id', $status->id)->delete();
|
||||
Mention::whereStatusId($status->id)->forceDelete();
|
||||
Notification::whereItemType('App\Status')
|
||||
->whereItemId($status->id)
|
||||
->forceDelete();
|
||||
Report::whereObjectType('App\Status')
|
||||
->whereObjectId($status->id)
|
||||
->delete();
|
||||
StatusArchived::whereStatusId($status->id)->delete();
|
||||
StatusHashtag::whereStatusId($status->id)->delete();
|
||||
StatusView::whereStatusId($status->id)->delete();
|
||||
Status::whereInReplyToId($status->id)->update(['in_reply_to_id' => null]);
|
||||
|
||||
$status->delete();
|
||||
|
||||
StatusService::del($status->id, true);
|
||||
AccountService::del($status->profile_id);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
|
@ -11,11 +11,13 @@ use Illuminate\Http\Client\RequestException;
|
|||
|
||||
class ActivityPubFetchService
|
||||
{
|
||||
public static function get($url)
|
||||
public static function get($url, $validateUrl = true)
|
||||
{
|
||||
if($validateUrl === true) {
|
||||
if(!Helpers::validateUrl($url)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$baseHeaders = [
|
||||
'Accept' => 'application/activity+json, application/ld+json',
|
||||
|
|
|
@ -25,7 +25,7 @@ use Illuminate\Support\Str;
|
|||
use App\Jobs\LikePipeline\LikePipeline;
|
||||
use App\Jobs\FollowPipeline\FollowPipeline;
|
||||
use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline;
|
||||
use App\Jobs\DeletePipeline\DeleteRemoteStatusPipeline;
|
||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||
use App\Jobs\StoryPipeline\StoryExpire;
|
||||
use App\Jobs\StoryPipeline\StoryFetch;
|
||||
use App\Jobs\StatusPipeline\StatusRemoteUpdatePipeline;
|
||||
|
@ -707,7 +707,7 @@ class Inbox
|
|||
if(!$status) {
|
||||
return;
|
||||
}
|
||||
DeleteRemoteStatusPipeline::dispatch($status)->onQueue('high');
|
||||
RemoteStatusDelete::dispatch($status)->onQueue('high');
|
||||
return;
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue