Add model to store syndication target data

This commit is contained in:
Jonny Barnes 2022-10-22 14:18:21 +01:00
parent 7cd9956b92
commit ea8395a651
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
5 changed files with 154 additions and 9 deletions

View file

@ -6,6 +6,7 @@ namespace App\Http\Controllers;
use App\Http\Responses\MicropubResponses;
use App\Models\Place;
use App\Models\SyndicationTarget;
use App\Services\Micropub\HCardService;
use App\Services\Micropub\HEntryService;
use App\Services\Micropub\UpdateService;
@ -121,21 +122,19 @@ class MicropubController extends Controller
{
try {
$tokenData = $this->tokenService->validateToken(request()->input('access_token'));
} catch (RequiredConstraintsViolated | InvalidTokenStructure $exception) {
$micropubResponses = new MicropubResponses();
return $micropubResponses->invalidTokenResponse();
} catch (RequiredConstraintsViolated | InvalidTokenStructure) {
return (new MicropubResponses())->invalidTokenResponse();
}
if (request()->input('q') === 'syndicate-to') {
return response()->json([
'syndicate-to' => config('syndication.targets'),
'syndicate-to' => SyndicationTarget::all(),
]);
}
if (request()->input('q') == 'config') {
if (request()->input('q') === 'config') {
return response()->json([
'syndicate-to' => config('syndication.targets'),
'syndicate-to' => SyndicationTarget::all(),
'media-endpoint' => route('media-endpoint'),
]);
}

View file

@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SyndicationTarget extends Model
{
use HasFactory;
/**
* The attributes that are visible when serializing the model.
*
* @var array<string>
*/
protected $visible = [
'uid',
'name',
'service',
'user',
];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [
'service',
'user',
];
/**
* Get the service data as a single attribute.
*
* @vreturn Attribute
*/
protected function service(): Attribute
{
return Attribute::get(
get: fn ($value, $attributes) => [
'name' => $attributes['service_name'],
'url' => $attributes['service_url'],
'photo' => $attributes['service_photo'],
],
);
}
/**
* Get the user data as a single attribute.
*
* @vreturn Attribute
*/
protected function user(): Attribute
{
return Attribute::get(
get: fn ($value, $attributes) => [
'name' => $attributes['user_name'],
'url' => $attributes['user_url'],
'photo' => $attributes['user_photo'],
],
);
}
}