Cleanup Code

This commit is contained in:
Philipp 2021-06-09 00:09:32 +02:00
parent 263774eb46
commit d4387d45ee
No known key found for this signature in database
GPG key ID: 9A28B7D4FF5667BD
18 changed files with 86 additions and 78 deletions

View file

@ -46,13 +46,11 @@ class Attachment extends BaseFactory
* @param int $uriId Uri-ID of the attachments
* @return array
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public function createFromUriId(int $uriId)
public function createFromUriId(int $uriId): array
{
$attachments = [];
foreach (Post\Media::getByURIId($uriId, [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE]) as $attachment) {
$filetype = !empty($attachment['mimetype']) ? strtolower(substr($attachment['mimetype'], 0, strpos($attachment['mimetype'], '/'))) : '';
if (($filetype == 'audio') || ($attachment['type'] == Post\Media::AUDIO)) {
@ -70,19 +68,19 @@ class Attachment extends BaseFactory
$remote = $attachment['url'];
if ($type == 'image') {
if (Proxy::isLocalImage($attachment['url'])) {
$url = $attachment['url'];
$url = $attachment['url'];
$preview = $attachment['preview'] ?? $url;
$remote = '';
$remote = '';
} else {
$url = Proxy::proxifyUrl($attachment['url']);
$url = Proxy::proxifyUrl($attachment['url']);
$preview = Proxy::proxifyUrl($attachment['url'], false, Proxy::SIZE_SMALL);
}
} else {
$url = Proxy::proxifyUrl($attachment['url']);
$url = Proxy::proxifyUrl($attachment['url ']);
$preview = Proxy::proxifyUrl($attachment['preview'] ?? '');
}
$object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, $type, $url, $preview, $remote);
$object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, $type, $url, $preview, $remote);
$attachments[] = $object->toArray();
}
@ -91,21 +89,21 @@ class Attachment extends BaseFactory
/**
* @param int $id id of the photo
*
* @return array
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public function createFromPhoto(int $id)
public function createFromPhoto(int $id): array
{
$photo = Photo::selectFirst(['resource-id', 'uid', 'id', 'title', 'type'], ['id' => $id]);
if (empty($photo)) {
return null;
return [];
}
$attachment = ['id' => $photo['id'], 'description' => $photo['title']];
$phototypes = Images::supportedTypes();
$ext = $phototypes[$photo['type']];
$photoTypes = Images::supportedTypes();
$ext = $photoTypes[$photo['type']];
$url = $this->baseUrl . '/photo/' . $photo['resource-id'] . '-0.' . $ext;