Federate Media Licenses

This commit is contained in:
Daniel Supernault 2021-07-25 03:17:49 -06:00
parent b6e226aef9
commit 14a1367a8f
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 28 additions and 9 deletions

View file

@ -10,6 +10,7 @@ use League\Fractal;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Transformer\Api\MediaTransformer; use App\Transformer\Api\MediaTransformer;
use App\Util\Media\License;
class MediaService class MediaService
{ {
@ -37,4 +38,24 @@ class MediaService
{ {
return Cache::forget(self::CACHE_KEY . $statusId); 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
];
});
}
} }

View file

@ -4,6 +4,7 @@ namespace App\Transformer\ActivityPub;
use App\Status; use App\Status;
use League\Fractal; use League\Fractal;
use App\Services\MediaService;
class StatusTransformer extends Fractal\TransformerAbstract class StatusTransformer extends Fractal\TransformerAbstract
{ {
@ -45,15 +46,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'sensitive' => (bool) $status->is_nsfw, 'sensitive' => (bool) $status->is_nsfw,
'atomUri' => $status->url(), 'atomUri' => $status->url(),
'inReplyToAtomUri' => null, 'inReplyToAtomUri' => null,
'attachment' => $status->media->map(function ($media) { 'attachment' => MediaService::activitypub($status->id),
return [
'type' => 'Document',
'mediaType' => $media->mime,
'url' => $media->url(),
'name' => $media->caption,
'blurhash' => $media->blurhash
];
}),
'tag' => [], 'tag' => [],
'location' => $status->place_id ? [ 'location' => $status->place_id ? [
'type' => 'Place', 'type' => 'Place',

View file

@ -32,6 +32,7 @@ use App\Services\MediaPathService;
use App\Services\MediaStorageService; use App\Services\MediaStorageService;
use App\Jobs\MediaPipeline\MediaStoragePipeline; use App\Jobs\MediaPipeline\MediaStoragePipeline;
use App\Jobs\AvatarPipeline\RemoteAvatarFetch; use App\Jobs\AvatarPipeline\RemoteAvatarFetch;
use App\Util\Media\License;
class Helpers { class Helpers {
@ -428,6 +429,7 @@ class Helpers {
$type = $media['mediaType']; $type = $media['mediaType'];
$url = $media['url']; $url = $media['url'];
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null; $blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
$license = isset($media['license']) ? License::nameToId($media['license']) : null;
$valid = self::validateUrl($url); $valid = self::validateUrl($url);
if(in_array($type, $allowed) == false || $valid == false) { if(in_array($type, $allowed) == false || $valid == false) {
continue; continue;
@ -441,6 +443,9 @@ class Helpers {
$media->user_id = null; $media->user_id = null;
$media->media_path = $url; $media->media_path = $url;
$media->remote_url = $url; $media->remote_url = $url;
if($license) {
$media->license = $license;
}
$media->mime = $type; $media->mime = $type;
$media->version = 3; $media->version = 3;
$media->save(); $media->save();