Merge pull request #4544 from pixelfed/staging

Update MediaStorageService, improve head header handling
This commit is contained in:
daniel 2023-07-16 05:41:49 -06:00 committed by GitHub
commit 45090a0e76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 28 deletions

View file

@ -35,6 +35,9 @@
- Update TransformImports command, increment status_count on profile model ([ba7551d8](https://github.com/pixelfed/pixelfed/commit/ba7551d8))
- Update AP Helpers, improve url validation and add optional dns verification, disabled by default ([2bef3e41](https://github.com/pixelfed/pixelfed/commit/2bef3e41))
- Update admin users blade view, show last_active_at and other info ([e0b48b29](https://github.com/pixelfed/pixelfed/commit/e0b48b29))
- Update MediaStorageService, improve head header handling ([3590adbd](https://github.com/pixelfed/pixelfed/commit/3590adbd))
- Update admin user view, improve previews ([ff2c16fe](https://github.com/pixelfed/pixelfed/commit/ff2c16fe))
- Update FanoutDeletePipeline, fix AP object ([0d802c31](https://github.com/pixelfed/pixelfed/commit/0d802c31))
- ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.11.8 (2023-05-29)](https://github.com/pixelfed/pixelfed/compare/v0.11.7...v0.11.8)

View file

@ -53,10 +53,10 @@ class FanoutDeletePipeline implements ShouldQueue
"id" => $profile->permalink('#delete'),
"type" => "Delete",
"actor" => $profile->permalink(),
"to" => [
"https://www.w3.org/ns/activitystreams#Public",
"object" => [
"type" => "Person",
"id" => $profile->permalink()
],
"object" => $profile->permalink(),
];
$payload = json_encode($activity);

View file

@ -20,8 +20,8 @@ class Media extends Model
protected $guarded = [];
protected $casts = [
'srcset' => 'array',
'deleted_at' => 'datetime'
'srcset' => 'array',
'deleted_at' => 'datetime'
];
public function status()
@ -63,7 +63,7 @@ class Media extends Model
}
if($this->media_path && $this->mime && in_array($this->mime, ['image/jpeg', 'image/png'])) {
return $this->remote_media || Str::startsWith($this->media_path, 'http') ?
return $this->remote_media || Str::startsWith($this->media_path, 'http') ?
$this->media_path :
url(Storage::url($this->media_path));
}
@ -78,6 +78,9 @@ class Media extends Model
public function mimeType()
{
if(!$this->mime) {
return;
}
return explode('/', $this->mime)[0];
}

View file

@ -16,6 +16,7 @@ use App\Services\AccountService;
use App\Http\Controllers\AvatarController;
use GuzzleHttp\Exception\RequestException;
use App\Jobs\MediaPipeline\MediaDeletePipeline;
use Illuminate\Support\Arr;
class MediaStorageService {
@ -42,27 +43,16 @@ class MediaStorageService {
return false;
}
$h = $r->getHeaders();
$h = Arr::mapWithKeys($r->getHeaders(), function($item, $key) {
return [strtolower($key) => last($item)];
});
if (isset($h['content-length']) && isset($h['content-type'])) {
if(empty($h['content-length']) || empty($h['content-type'])) {
return false;
}
$len = is_array($h['content-length']) ? $h['content-length'][0] : $h['content-length'];
$mime = is_array($h['content-type']) ? $h['content-type'][0] : $h['content-type'];
} else {
if (isset($h['Content-Length'], $h['Content-Type']) == false) {
return false;
}
if(empty($h['Content-Length']) || empty($h['Content-Type']) ) {
return false;
}
$len = is_array($h['Content-Length']) ? $h['Content-Length'][0] : $h['Content-Length'];
$mime = is_array($h['Content-Type']) ? $h['Content-Type'][0] : $h['Content-Type'];
}
if(!isset($h['content-length'], $h['content-type'])) {
return false;
}
$len = (int) $h['content-length'];
$mime = $h['content-type'];
if($len < 10 || $len > ((config_cache('pixelfed.max_photo_size') * 1000))) {
return false;

View file

@ -140,10 +140,15 @@
<p class="title h4 font-weight-bold mt-2 py-2">Recent Posts</p>
<hr>
<div class="row">
@foreach($profile->statuses()->whereHas('media')->latest()->take(9)->get() as $item)
<div class="col-12 col-md-4 col-sm-6 px-0" style="margin-bottom: 1px;">
@foreach($profile->statuses()->whereHas('media')->latest()->take(16)->get() as $item)
@php($post = \App\Services\StatusService::get($item->id, false))
<div class="col-12 col-md-3 col-sm-6 mb-3 px-0">
<a href="{{$item->url()}}">
<img src="{{$item->thumb(true)}}" width="200px" height="200px">
@if($post)
<img src="{{$post['media_attachments'][0]['url']}}" width="200px" height="200px" style="object-fit: cover;" onerror="this.src='/storage/no-preview.png';this.onerror=null;">
@else
<img src="/storage/no-preview.png" width="200px" height="200px">
@endif
</a>
</div>
@endforeach