Bring Micropub endpoint closer to the spec
- Detect form-encoded action=... requests, so form-encoded updates work and unhandled actions are no longer created as notes - Default to h-entry when no type is given - Read form-encoded photos from `photo` rather than `photos` - Pass `category` through EntryData so bookmark tags are saved - Accept single values for form-encoded multi-value properties - Return 403 for insufficient_scope and 401 for invalid tokens - Return 400 invalid_request for unsupported post types, update operations and models instead of reporting them as 500s Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cc2ff2b2a2
commit
6e96ca8304
1 changed files with 179 additions and 50 deletions
|
|
@ -25,6 +25,7 @@ class EntryData extends MicropubData
|
|||
public readonly mixed $syndication,
|
||||
public readonly ?array $photos,
|
||||
public readonly ?string $postStatus,
|
||||
public readonly ?array $category,
|
||||
) {}
|
||||
|
||||
public static function fromRequest(Request $request): static
|
||||
|
|
@ -51,6 +52,7 @@ class EntryData extends MicropubData
|
|||
syndication: Arr::get($data, 'properties.syndication.0'),
|
||||
photos: Arr::get($data, 'properties.photo'),
|
||||
postStatus: Arr::get($data, 'properties.post-status.0'),
|
||||
category: Arr::get($data, 'properties.category'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -62,17 +64,27 @@ class EntryData extends MicropubData
|
|||
location: $request->input('location'),
|
||||
bookmarkOf: $request->input('bookmark-of'),
|
||||
likeOf: $request->input('like-of'),
|
||||
mpSyndicateTo: $request->input('mp-syndicate-to'),
|
||||
mpSyndicateTo: self::wrapFormValue($request->input('mp-syndicate-to')),
|
||||
name: $request->input('name'),
|
||||
description: $request->input('description'),
|
||||
geo: $request->input('geo'),
|
||||
checkin: $request->input('checkin'),
|
||||
syndication: $request->input('syndication'),
|
||||
photos: $request->input('photos'),
|
||||
photos: self::wrapFormValue($request->input('photo')),
|
||||
postStatus: $request->input('post-status'),
|
||||
category: self::wrapFormValue($request->input('category')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form-encoded multi-value properties may be sent with or without the []
|
||||
* suffix, so a single value arrives as a string rather than an array.
|
||||
*/
|
||||
private static function wrapFormValue(mixed $value): ?array
|
||||
{
|
||||
return $value === null ? null : Arr::wrap($value);
|
||||
}
|
||||
|
||||
private static function extractLocationData(array $data): array|string|null
|
||||
{
|
||||
if (! Arr::has($data, 'properties.location')) {
|
||||
|
|
@ -104,6 +116,7 @@ class EntryData extends MicropubData
|
|||
syndication: $data['syndication'] ?? null,
|
||||
photos: $data['photos'] ?? null,
|
||||
postStatus: $data['post-status'] ?? null,
|
||||
category: $data['category'] ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +138,7 @@ class EntryData extends MicropubData
|
|||
'syndication' => $this->syndication,
|
||||
'photos' => $this->photos,
|
||||
'post-status' => $this->postStatus,
|
||||
'category' => $this->category,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue