mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update Services, fix mastoapi compat
This commit is contained in:
parent
85fc9dd0a8
commit
454b4e21dd
2 changed files with 40 additions and 15 deletions
|
@ -18,26 +18,48 @@ class MediaService
|
|||
|
||||
public static function get($statusId)
|
||||
{
|
||||
$status = Status::find($statusId);
|
||||
if(!$status) {
|
||||
return [];
|
||||
}
|
||||
$ttl = $status->created_at->lt(now()->subMinutes(30)) ? 129600 : 30;
|
||||
return Cache::remember(self::CACHE_KEY.$statusId, $ttl, function() use($status) {
|
||||
if(!$status) {
|
||||
return Cache::remember(self::CACHE_KEY.$statusId, 86400, function() use($statusId) {
|
||||
$media = Media::whereStatusId($statusId)->orderBy('order')->get();
|
||||
if(!$media) {
|
||||
return [];
|
||||
}
|
||||
if(in_array($status->type, ['group:post', 'photo', 'video', 'video:album', 'photo:album', 'loop', 'photo:video:album'])) {
|
||||
$media = Media::whereStatusId($status->id)->orderBy('order')->get();
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Collection($media, new MediaTransformer());
|
||||
return $fractal->createData($resource)->toArray();
|
||||
}
|
||||
return [];
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Collection($media, new MediaTransformer());
|
||||
return $fractal->createData($resource)->toArray();
|
||||
});
|
||||
}
|
||||
|
||||
public static function getMastodon($id)
|
||||
{
|
||||
$media = self::get($id);
|
||||
if(!$media) {
|
||||
return [];
|
||||
}
|
||||
$medias = collect($media)
|
||||
->map(function($media) {
|
||||
$mime = $media['mime'] ? explode('/', $media['mime']) : false;
|
||||
unset(
|
||||
$media['optimized_url'],
|
||||
$media['license'],
|
||||
$media['is_nsfw'],
|
||||
$media['orientation'],
|
||||
$media['filter_name'],
|
||||
$media['filter_class'],
|
||||
$media['mime']
|
||||
);
|
||||
|
||||
$media['type'] = $mime ? strtolower($mime[0]) : 'unknown';
|
||||
return $media;
|
||||
})
|
||||
->filter(function($m) {
|
||||
return $m && isset($m['url']);
|
||||
})
|
||||
->values();
|
||||
|
||||
return $medias->toArray();
|
||||
}
|
||||
|
||||
public static function del($statusId)
|
||||
{
|
||||
return Cache::forget(self::CACHE_KEY . $statusId);
|
||||
|
|
|
@ -71,6 +71,7 @@ class StatusService
|
|||
$status['account']['note_text'],
|
||||
$status['account']['pronouns'],
|
||||
$status['account']['website'],
|
||||
$status['media_attachments'],
|
||||
);
|
||||
$status['account']['avatar_static'] = $status['account']['avatar'];
|
||||
$status['account']['bot'] = false;
|
||||
|
@ -80,6 +81,8 @@ class StatusService
|
|||
$status['account']['header_static'] = url('/storage/headers/missing.png');
|
||||
$status['account']['last_status_at'] = null;
|
||||
|
||||
$status['media_attachments'] = array_values(MediaService::getMastodon($status['id']));
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue