Add bookmarks via micropub
This commit is contained in:
parent
f16034d963
commit
a5d3ba7829
2 changed files with 61 additions and 0 deletions
|
@ -82,6 +82,14 @@ class MicropubController extends Controller
|
||||||
'location' => config('app.url') . "/likes/$like->id",
|
'location' => config('app.url') . "/likes/$like->id",
|
||||||
], 201)->header('Location', config('app.url') . "/likes/$like->id");
|
], 201)->header('Location', config('app.url') . "/likes/$like->id");
|
||||||
}
|
}
|
||||||
|
if ($request->has('properties.bookmark-of') || $request->has('bookmark-of')) {
|
||||||
|
$bookmark = (new BookmarkService())->createBookmark($request);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'response' => 'created',
|
||||||
|
'location' => config('app.url') . "/bookmarks/$bookmark->id",
|
||||||
|
], 201)->header('Location', config('app.url') . "/bookmarks/$bookmark->id");
|
||||||
|
}
|
||||||
$data = [];
|
$data = [];
|
||||||
$data['client-id'] = $tokenData->getClaim('client_id');
|
$data['client-id'] = $tokenData->getClaim('client_id');
|
||||||
if ($request->header('Content-Type') == 'application/json') {
|
if ($request->header('Content-Type') == 'application/json') {
|
||||||
|
|
53
app/Services/BookmarkService.php
Normal file
53
app/Services/BookmarkService.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Bookmark;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Jobs\ProcessBookmark;
|
||||||
|
|
||||||
|
class BookmarkService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new Bookmark.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*/
|
||||||
|
public function createLike(Request $request): Bookmark
|
||||||
|
{
|
||||||
|
if ($request->header('Content-Type') == 'application/json') {
|
||||||
|
//micropub request
|
||||||
|
$url = normalize_url($request->input('properties.bookmark-of.0'));
|
||||||
|
$name = $request->input('properties.name.0');
|
||||||
|
$content = $request->input('properties.content.0');
|
||||||
|
$categories = $request->input('properties.category');
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
($request->header('Content-Type') == 'x-www-url-formencoded')
|
||||||
|
||
|
||||||
|
($request->header('Content-Type') == 'multipart/form-data')
|
||||||
|
) {
|
||||||
|
$url = normalize_url($request->input('bookmark-of'));
|
||||||
|
$name = $request->input('name');
|
||||||
|
$content = $request->input('content');
|
||||||
|
$categories = $request->input('category[]');
|
||||||
|
}
|
||||||
|
|
||||||
|
$bookmark = Bookmark::create([
|
||||||
|
'url' => $url,
|
||||||
|
'name' => $name,
|
||||||
|
'content' => $content,
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach($categories as $category) {
|
||||||
|
$tag = Tag::firstOrCreate(['tag' => $category]);
|
||||||
|
$bookmark->tags()->save($tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessBookmark::dispatch($bookmark);
|
||||||
|
|
||||||
|
return $Bookmark;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue