aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
authorwinter2025-01-28 22:00:20 +0000
committerwinter2025-01-28 22:00:20 +0000
commit093b34db9498d9ce1155c1fd8a59646aa483f85d (patch)
treeca596c39d6e001f118b8381cf77d746300add468 /routes
parent1af3a4e00ec63755a90109d8a63a1b6f6d95def6 (diff)
add upload/attach file feature for writing notes
Diffstat (limited to 'routes')
-rw-r--r--routes/note_fragment.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/routes/note_fragment.php b/routes/note_fragment.php
index 9d3b9bb..02655ec 100644
--- a/routes/note_fragment.php
+++ b/routes/note_fragment.php
@@ -6,9 +6,13 @@ use Digitigrade\Model\Actor;
use Digitigrade\Model\Interaction;
use Digitigrade\Model\InteractionKind;
use Digitigrade\Model\Note;
+use Digitigrade\Model\NoteAttachment;
use Digitigrade\Model\NotePrivacyScope;
+use Digitigrade\Model\StorageObject;
use Digitigrade\Model\UserAccount;
use Digitigrade\Router;
+use Digitigrade\StorageProvider;
+use Digitigrade\StorageProvider\FilesystemStorage;
Router::getInstance()->mount('/fragment/note/:id', function (array $args) {
if ($_SERVER['REQUEST_METHOD'] != 'DELETE') {
@@ -104,6 +108,11 @@ Router::getInstance()->mount('/fragment/note', function (array $args) {
foreach (($_POST['mentions'] ?? []) as $uid) {
$note->mentions[] = Actor::find($uid);
}
+ $index = 0;
+ foreach (($_POST['attachments'] ?? []) as $oid) {
+ $obj = StorageObject::findByOid($oid);
+ $note->attachments[] = NoteAttachment::fromStorageObject($obj, $index++, $obj->filename);
+ }
$note->save();
$note->publish();
$note->processTimelineAdditions();
@@ -128,4 +137,14 @@ Router::getInstance()->mount('/fragment/note/mentionPill', function (array $args
// start editing
render_template('user_mention_pill', ['type' => 'edit']);
}
+});
+
+Router::getInstance()->mount('/fragment/note/attachmentPill', function (array $args) {
+ // adding an attachment to a new post
+ if (isset($_FILES['file'])) {
+ // 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]);
+ }
}); \ No newline at end of file