Allow files to be added to notes

This is specifically when a Micropub client is using the JSON syntax and
initially uploads the photo via the media endpoint
This commit is contained in:
Jonny Barnes 2025-12-27 17:55:29 +00:00
commit 76db869af5
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
11 changed files with 33 additions and 23 deletions

View file

@ -80,6 +80,9 @@ class MicropubRequest extends FormRequest
// Add checkin value
$this->micropubData['checkin'] = Arr::get($data, 'checkin');
$this->micropubData['syndication'] = Arr::get($data, 'properties.syndication.0');
// Add photos
$this->micropubData['photos'] = Arr::get($data, 'properties.photo');
}
private function normalizeMicropubForm(): void

View file

@ -33,20 +33,20 @@ class ProcessMedia implements ShouldQueue
public function handle(ImageManager $manager): void
{
// Load file
$file = Storage::disk('local')->get('media/' . $this->filename);
$file = Storage::disk('local')->get($this->filename);
// Open file
try {
$image = $manager->read($file);
} catch (DecoderException) {
// not an image; delete file and end job
Storage::disk('local')->delete('media/' . $this->filename);
Storage::disk('local')->delete($this->filename);
return;
}
// Save the file publicly
Storage::disk('public')->put('media/' . $this->filename, $file);
Storage::disk('public')->put($this->filename, $file);
// Create smaller versions if necessary
if ($image->width() > 1000) {
@ -57,13 +57,13 @@ class ProcessMedia implements ShouldQueue
$basename = trim(implode('.', $filenameParts), '.');
$medium = $image->resize(width: 1000);
Storage::disk('public')->put('media/' . $basename . '-medium.' . $extension, (string) $medium->encode());
Storage::disk('public')->put($basename . '-medium.' . $extension, (string) $medium->encode());
$small = $image->resize(width: 500);
Storage::disk('public')->put('media/' . $basename . '-small.' . $extension, (string) $small->encode());
Storage::disk('public')->put($basename . '-small.' . $extension, (string) $small->encode());
}
// Now we can delete the locally saved image
Storage::disk('local')->delete('media/' . $this->filename);
Storage::disk('local')->delete($this->filename);
}
}

View file

@ -48,12 +48,12 @@ class NoteService
$note->place()->associate($this->getCheckin($data));
$note->swarm_url = $this->getSwarmUrl($data);
}
//
// $note->instagram_url = $this->getInstagramUrl($request);
//
// foreach ($this->getMedia($request) as $media) {
// $note->media()->save($media);
// }
// $note->instagram_url = $this->getInstagramUrl($request);
foreach ($this->getMedia($data) as $media) {
$note->media()->save($media);
}
$note->save();
@ -188,16 +188,16 @@ class NoteService
/**
* Get the media URLs from the request to create a new note.
*/
private function getMedia(array $request): array
private function getMedia(array $data): array
{
$media = [];
$photos = Arr::get($request, 'photo') ?? Arr::get($request, 'properties.photo');
$photos = Arr::get($data, 'photos');
if (isset($photos)) {
foreach ((array) $photos as $photo) {
// check the media was uploaded to my endpoint, and use path
if (Str::startsWith($photo, config('filesystems.disks.s3.url'))) {
$path = substr($photo, strlen(config('filesystems.disks.s3.url')));
if (Str::startsWith($photo, config('filesystems.disks.public.url'))) {
$path = substr($photo, strlen(config('filesystems.disks.public.url')));
$media[] = Media::where('path', ltrim($path, '/'))->firstOrFail();
} else {
$newMedia = Media::firstOrNew(['path' => $photo]);