Some fixes related to developing my Micropub client #50

Merged
jonny merged 1 commit from micropub_client_fixes into develop 2025-08-17 12:07:16 +02:00
6 changed files with 61 additions and 13 deletions

View file

@ -51,7 +51,7 @@ class MicropubRequest extends FormRequest
// Convert JSON type (h-entry) to simple type (entry)
if (isset($data['type']) && is_array($data['type'])) {
$type = current($data['type']);
if (strpos($type, 'h-') === 0) {
if (str_starts_with($type, 'h-')) {
$this->micropubData['type'] = substr($type, 2);
}
}
@ -67,7 +67,7 @@ class MicropubRequest extends FormRequest
$this->micropubData['content'] = Arr::get($data, 'properties.content.0');
$this->micropubData['in-reply-to'] = Arr::get($data, 'properties.in-reply-to.0');
$this->micropubData['published'] = Arr::get($data, 'properties.published.0');
$this->micropubData['location'] = Arr::get($data, 'location');
$this->micropubData['location'] = $this->getLocationData($data);
$this->micropubData['bookmark-of'] = Arr::get($data, 'properties.bookmark-of.0');
$this->micropubData['like-of'] = Arr::get($data, 'properties.like-of.0');
$this->micropubData['mp-syndicate-to'] = Arr::get($data, 'properties.mp-syndicate-to');
@ -103,4 +103,17 @@ class MicropubRequest extends FormRequest
$this->micropubData[$key] = $value;
}
}
private function getLocationData(array $data): array|string|null
{
if (! Arr::has($data, 'properties.location')) {
return null;
}
if (Arr::has($data, 'properties.location.0')) {
return Arr::get($data, 'properties.location.0');
}
return Arr::get($data, 'properties.location');
}
}

View file

@ -6,7 +6,7 @@ services:
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.3/app
image: sail-8.4/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:

View file

@ -13,6 +13,6 @@
@endforeach
</ul>
<p>
Create a <a href="/admin/clients/new">new entry</a>?
Create a <a href="/admin/clients/create">new entry</a>?
</p>
@stop

View file

@ -3,8 +3,8 @@
@section('content')
<h2>Login</h2>
<form action="login" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<form action="{{ route('login') }}" method="post">
@csrf
<input type="text" name="name" placeholder="username">
<input type="password" name="password" placeholder="password">
<input type="submit" name="submit" value="Login">

View file

@ -137,6 +137,16 @@ Route::middleware(MyAuthMiddleware::class)->prefix('admin')->group(function () {
Route::delete('/{syndicationTarget}', [SyndicationTargetsController::class, 'destroy']);
});
// Clients
Route::prefix('clients')->group(function () {
Route::get('/', [ClientsController::class, 'index']);
Route::get('/create', [ClientsController::class, 'create']);
Route::post('/', [ClientsController::class, 'store']);
Route::get('/{clientId}/edit', [ClientsController::class, 'edit']);
Route::put('/{clientId}', [ClientsController::class, 'update']);
Route::delete('/{clientId}', [ClientsController::class, 'destroy']);
});
// Bio
Route::prefix('bio')->group(function () {
Route::get('/', [BioController::class, 'show'])->name('admin.bio.show');

View file

@ -278,6 +278,31 @@ class MicropubControllerTest extends TestCase
Queue::assertPushed(SyndicateNoteToBluesky::class);
}
#[Test]
public function micropub_client_api_request_creates_new_note_with_geo_location(): void
{
$faker = Factory::create();
$note = $faker->text;
$response = $this->postJson(
'/api/post',
[
'type' => ['h-entry'],
'properties' => [
'content' => [$note],
'location' => ['geo:1.23,4.56'],
],
],
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
);
$response
->assertStatus(201)
->assertJson(['response' => 'created']);
$this->assertDatabaseHas('notes', [
'note' => $note,
'location' => '1.23, 4.56',
]);
}
/**
* Test a valid micropub requests using JSON syntax creates a new note with
* existing self-created place.
@ -323,13 +348,13 @@ class MicropubControllerTest extends TestCase
'type' => ['h-entry'],
'properties' => [
'content' => [$note],
],
'location' => [
'type' => ['h-card'],
'properties' => [
'name' => ['Awesome Venue'],
'latitude' => ['1.23'],
'longitude' => ['4.56'],
'location' => [
'type' => ['h-card'],
'properties' => [
'name' => ['Awesome Venue'],
'latitude' => ['1.23'],
'longitude' => ['4.56'],
],
],
],
],