diff options
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/note_fragment.php | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/routes/note_fragment.php b/routes/note_fragment.php index 02655ec..be1c33f 100644 --- a/routes/note_fragment.php +++ b/routes/note_fragment.php @@ -109,9 +109,11 @@ Router::getInstance()->mount('/fragment/note', function (array $args) { $note->mentions[] = Actor::find($uid); } $index = 0; - foreach (($_POST['attachments'] ?? []) as $oid) { - $obj = StorageObject::findByOid($oid); - $note->attachments[] = NoteAttachment::fromStorageObject($obj, $index++, $obj->filename); + $attachments = $_POST['attachments'] ?? []; + $altTexts = $_POST['altTexts'] ?? []; + for ($i = 0; $i < count($attachments); $i++) { + $obj = StorageObject::findByOid($attachments[$i]); + $note->attachments[] = NoteAttachment::fromStorageObject($obj, $index++, $altTexts[$i] ?: null); } $note->save(); $note->publish(); @@ -145,6 +147,12 @@ Router::getInstance()->mount('/fragment/note/attachmentPill', function (array $a // store the file and return a pill for it // TODO: allow other providers $obj = StorageObject::createFromUpload(FilesystemStorage::class, $_FILES['file']); - render_template('attachment_pill', ['type' => 'file', 'oid' => $obj->oid, 'name' => $obj->filename]); + $type = str_starts_with($obj->mimetype, 'image/') ? 'image' : 'file'; + render_template('attachment_pill', [ + 'type' => $type, + 'oid' => $obj->oid, + 'name' => $obj->filename, + 'href' => $obj->getUrl() + ]); } });
\ No newline at end of file |
