mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 00:03:16 +00:00
Federate Media Licenses
This commit is contained in:
parent
b6e226aef9
commit
14a1367a8f
3 changed files with 28 additions and 9 deletions
|
@ -10,6 +10,7 @@ use League\Fractal;
|
|||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use App\Transformer\Api\MediaTransformer;
|
||||
use App\Util\Media\License;
|
||||
|
||||
class MediaService
|
||||
{
|
||||
|
@ -37,4 +38,24 @@ class MediaService
|
|||
{
|
||||
return Cache::forget(self::CACHE_KEY . $statusId);
|
||||
}
|
||||
|
||||
public static function activitypub($statusId)
|
||||
{
|
||||
$status = self::get($statusId);
|
||||
if(!$status) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($status)->map(function($s) use($license) {
|
||||
$license = isset($s['license']) && $s['license']['title'] ? $s['license']['title'] : null;
|
||||
return [
|
||||
'type' => 'Document',
|
||||
'mediaType' => $s['mime'],
|
||||
'url' => $s['url'],
|
||||
'name' => $s['description'],
|
||||
'blurhash' => $s['blurhash'],
|
||||
'license' => $license
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Transformer\ActivityPub;
|
|||
|
||||
use App\Status;
|
||||
use League\Fractal;
|
||||
use App\Services\MediaService;
|
||||
|
||||
class StatusTransformer extends Fractal\TransformerAbstract
|
||||
{
|
||||
|
@ -45,15 +46,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
|
|||
'sensitive' => (bool) $status->is_nsfw,
|
||||
'atomUri' => $status->url(),
|
||||
'inReplyToAtomUri' => null,
|
||||
'attachment' => $status->media->map(function ($media) {
|
||||
return [
|
||||
'type' => 'Document',
|
||||
'mediaType' => $media->mime,
|
||||
'url' => $media->url(),
|
||||
'name' => $media->caption,
|
||||
'blurhash' => $media->blurhash
|
||||
];
|
||||
}),
|
||||
'attachment' => MediaService::activitypub($status->id),
|
||||
'tag' => [],
|
||||
'location' => $status->place_id ? [
|
||||
'type' => 'Place',
|
||||
|
|
|
@ -32,6 +32,7 @@ use App\Services\MediaPathService;
|
|||
use App\Services\MediaStorageService;
|
||||
use App\Jobs\MediaPipeline\MediaStoragePipeline;
|
||||
use App\Jobs\AvatarPipeline\RemoteAvatarFetch;
|
||||
use App\Util\Media\License;
|
||||
|
||||
class Helpers {
|
||||
|
||||
|
@ -428,6 +429,7 @@ class Helpers {
|
|||
$type = $media['mediaType'];
|
||||
$url = $media['url'];
|
||||
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
|
||||
$license = isset($media['license']) ? License::nameToId($media['license']) : null;
|
||||
$valid = self::validateUrl($url);
|
||||
if(in_array($type, $allowed) == false || $valid == false) {
|
||||
continue;
|
||||
|
@ -441,6 +443,9 @@ class Helpers {
|
|||
$media->user_id = null;
|
||||
$media->media_path = $url;
|
||||
$media->remote_url = $url;
|
||||
if($license) {
|
||||
$media->license = $license;
|
||||
}
|
||||
$media->mime = $type;
|
||||
$media->version = 3;
|
||||
$media->save();
|
||||
|
|
Loading…
Reference in a new issue