mirror of
https://github.com/friendica/friendica
synced 2025-04-27 12:30:11 +00:00
Editing of media descriptions is now possible as well
This commit is contained in:
parent
98aed4dde3
commit
3a0b0ffce5
3 changed files with 88 additions and 31 deletions
|
@ -51,41 +51,65 @@ class Attachment extends BaseFactory
|
|||
{
|
||||
$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)) {
|
||||
$type = 'audio';
|
||||
} elseif (($filetype == 'video') || ($attachment['type'] == Post\Media::VIDEO)) {
|
||||
$type = 'video';
|
||||
} elseif ($attachment['mimetype'] == 'image/gif') {
|
||||
$type = 'gifv';
|
||||
} elseif (($filetype == 'image') || ($attachment['type'] == Post\Media::IMAGE)) {
|
||||
$type = 'image';
|
||||
} else {
|
||||
$type = 'unknown';
|
||||
}
|
||||
|
||||
$remote = $attachment['url'];
|
||||
if ($type == 'image') {
|
||||
$url = Post\Media::getPreviewUrlForId($attachment['id']);
|
||||
$preview = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_SMALL);
|
||||
} else {
|
||||
$url = $attachment['url'];
|
||||
|
||||
if (!empty($attachment['preview'])) {
|
||||
$preview = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_SMALL);
|
||||
} else {
|
||||
$preview = '';
|
||||
}
|
||||
}
|
||||
|
||||
$object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, $type, $url, $preview, $remote);
|
||||
$attachments[] = $object->toArray();
|
||||
$attachments[] = $this->createFromMediaArray($attachment);
|
||||
}
|
||||
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id id of the media
|
||||
* @return array
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function createFromId(int $id): array
|
||||
{
|
||||
$attachment = Post\Media::getById($id);
|
||||
if (empty($attachment)) {
|
||||
return [];
|
||||
}
|
||||
return $this->createFromMediaArray($attachment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attachment
|
||||
* @return array
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private function createFromMediaArray(array $attachment): array
|
||||
{
|
||||
$filetype = !empty($attachment['mimetype']) ? strtolower(substr($attachment['mimetype'], 0, strpos($attachment['mimetype'], '/'))) : '';
|
||||
|
||||
if (($filetype == 'audio') || ($attachment['type'] == Post\Media::AUDIO)) {
|
||||
$type = 'audio';
|
||||
} elseif (($filetype == 'video') || ($attachment['type'] == Post\Media::VIDEO)) {
|
||||
$type = 'video';
|
||||
} elseif ($attachment['mimetype'] == 'image/gif') {
|
||||
$type = 'gifv';
|
||||
} elseif (($filetype == 'image') || ($attachment['type'] == Post\Media::IMAGE)) {
|
||||
$type = 'image';
|
||||
} else {
|
||||
$type = 'unknown';
|
||||
}
|
||||
|
||||
$remote = $attachment['url'];
|
||||
if ($type == 'image') {
|
||||
$url = Post\Media::getPreviewUrlForId($attachment['id']);
|
||||
$preview = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_SMALL);
|
||||
} else {
|
||||
$url = $attachment['url'];
|
||||
|
||||
if (!empty($attachment['preview'])) {
|
||||
$preview = Post\Media::getPreviewUrlForId($attachment['id'], Proxy::SIZE_SMALL);
|
||||
} else {
|
||||
$preview = '';
|
||||
}
|
||||
}
|
||||
|
||||
$object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, $type, $url, $preview, $remote);
|
||||
return $object->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id id of the photo
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue