mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Update MediaStorageService, dispatch deletes to MediaDeletePipeline
This commit is contained in:
parent
0cef5aec26
commit
37dbb3de29
3 changed files with 82 additions and 0 deletions
67
app/Jobs/MediaPipeline/MediaDeletePipeline.php
Normal file
67
app/Jobs/MediaPipeline/MediaDeletePipeline.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\MediaPipeline;
|
||||
|
||||
use App\Media;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MediaDeletePipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $media;
|
||||
|
||||
public function __construct(Media $media)
|
||||
{
|
||||
$this->media = $media;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$media = $this->media;
|
||||
$path = $media->media_path;
|
||||
$thumb = $media->thumbnail_path;
|
||||
|
||||
if(!$path) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$e = explode('/', $path);
|
||||
array_pop($e);
|
||||
$i = implode('/', $e);
|
||||
|
||||
if(config('pixelfed.cloud_storage') == true) {
|
||||
$disk = Storage::disk(config('filesystems.cloud'));
|
||||
if($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
if($disk->exists($thumb)) {
|
||||
$disk->delete($thumb);
|
||||
}
|
||||
|
||||
if(count($e) > 4 && count($disk->files($i)) == 0) {
|
||||
$disk->deleteDirectory($i);
|
||||
}
|
||||
}
|
||||
|
||||
$disk = Storage::disk(config('filesystems.local'));
|
||||
if($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
if($disk->exists($thumb)) {
|
||||
$disk->delete($thumb);
|
||||
}
|
||||
if(count($e) > 4 && count($disk->files($i)) == 0) {
|
||||
$disk->deleteDirectory($i);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@ use App\User;
|
|||
use GuzzleHttp\Client;
|
||||
use App\Http\Controllers\AvatarController;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use App\Jobs\MediaPipeline\MediaDeletePipeline;
|
||||
|
||||
class MediaStorageService {
|
||||
|
||||
|
@ -227,4 +228,12 @@ class MediaStorageService {
|
|||
|
||||
unlink($tmpName);
|
||||
}
|
||||
|
||||
public static function delete(Media $media, $confirm = false)
|
||||
{
|
||||
if(!$confirm) {
|
||||
return;
|
||||
}
|
||||
MediaDeletePipeline::dispatch($media);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,12 @@ class Bouncer {
|
|||
$exemptionKey = 'pf:bouncer_v0:exemption_by_pid:' . $status->profile_id;
|
||||
$exemptionTtl = now()->addDays(12);
|
||||
|
||||
if( $status->in_reply_to_id != null &&
|
||||
$status->in_reply_to_profile_id == $status->profile_id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$exemption = Cache::remember($exemptionKey, $exemptionTtl, function() use($status) {
|
||||
$uid = $status->profile->user_id;
|
||||
$ids = AccountInterstitial::whereUserId($uid)
|
||||
|
|
Loading…
Reference in a new issue