Refactor method names/views for the Micropub Client
This commit is contained in:
parent
4af305ba3b
commit
e032cd5861
3 changed files with 16 additions and 22 deletions
|
@ -36,15 +36,12 @@ class MicropubClientController extends Controller
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\View\Factory view
|
* @return \Illuminate\View\Factory view
|
||||||
*/
|
*/
|
||||||
public function newNotePage(Request $request)
|
public function create(Request $request)
|
||||||
{
|
{
|
||||||
$url = $request->session()->get('me');
|
$url = $request->session()->get('me');
|
||||||
$syndication = $request->session()->get('syndication');
|
$syndication = $request->session()->get('syndication');
|
||||||
|
|
||||||
return view('micropubnewnotepage', [
|
return view('micropub.create', compact('url', 'syndication'));
|
||||||
'url' => $url,
|
|
||||||
'syndication' => $syndication,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +52,7 @@ class MicropubClientController extends Controller
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function postNewNote(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$domain = $request->session()->get('me');
|
$domain = $request->session()->get('me');
|
||||||
$token = $request->session()->get('token');
|
$token = $request->session()->get('token');
|
||||||
|
@ -65,7 +62,7 @@ class MicropubClientController extends Controller
|
||||||
$this->indieClient
|
$this->indieClient
|
||||||
);
|
);
|
||||||
if (! $micropubEndpoint) {
|
if (! $micropubEndpoint) {
|
||||||
return redirect('notes/new')->withErrors('Unable to determine micropub API endpoint', 'endpoint');
|
return redirect(route('micropub-client'))->withErrors('Unable to determine micropub API endpoint', 'endpoint');
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = $this->postNoteRequest($request, $micropubEndpoint, $token);
|
$response = $this->postNoteRequest($request, $micropubEndpoint, $token);
|
||||||
|
@ -79,7 +76,7 @@ class MicropubClientController extends Controller
|
||||||
return redirect($location);
|
return redirect($location);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect('notes/new')->withErrors('Endpoint didn’t create the note.', 'endpoint');
|
return redirect(route('micropub-client'))->withErrors('Endpoint didn’t create the note.', 'endpoint');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,9 +96,8 @@ class MicropubClientController extends Controller
|
||||||
$domain = $request->session()->get('me');
|
$domain = $request->session()->get('me');
|
||||||
$token = $request->session()->get('token');
|
$token = $request->session()->get('token');
|
||||||
$micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint($domain, $this->indieClient);
|
$micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint($domain, $this->indieClient);
|
||||||
|
|
||||||
if (! $micropubEndpoint) {
|
if (! $micropubEndpoint) {
|
||||||
return redirect('notes/new')->withErrors('Unable to determine micropub API endpoint', 'endpoint');
|
return redirect(route('micropub-client'))->withErrors('Unable to determine micropub API endpoint', 'endpoint');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -110,14 +106,14 @@ class MicropubClientController extends Controller
|
||||||
'query' => ['q' => 'syndicate-to'],
|
'query' => ['q' => 'syndicate-to'],
|
||||||
]);
|
]);
|
||||||
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
|
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
|
||||||
return redirect('notes/new')->withErrors('Bad response when refreshing syndication targets', 'endpoint');
|
return redirect(route('micropub-client'))->withErrors('Bad response when refreshing syndication targets', 'endpoint');
|
||||||
}
|
}
|
||||||
$body = (string) $response->getBody();
|
$body = (string) $response->getBody();
|
||||||
$syndication = $this->parseSyndicationTargets($body);
|
$syndication = $this->parseSyndicationTargets($body);
|
||||||
|
|
||||||
$request->session()->put('syndication', $syndication);
|
$request->session()->put('syndication', $syndication);
|
||||||
|
|
||||||
return redirect('notes/new');
|
return redirect(route('micropub-client'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,7 +180,7 @@ class MicropubClientController extends Controller
|
||||||
'headers' => $headers,
|
'headers' => $headers,
|
||||||
]);
|
]);
|
||||||
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
|
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
|
||||||
return redirect('notes/new')
|
return redirect(route('micropub-client'))
|
||||||
->withErrors('There was a bad response from the micropub endpoint.', 'endpoint');
|
->withErrors('There was a bad response from the micropub endpoint.', 'endpoint');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ New Note «
|
||||||
@endif
|
@endif
|
||||||
@include('templates.new-note-form', [
|
@include('templates.new-note-form', [
|
||||||
'micropub' => true,
|
'micropub' => true,
|
||||||
'action' => '/notes/new'
|
'action' => route('micropub-client-post')
|
||||||
])
|
])
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
|
@ -35,8 +35,6 @@ New Note «
|
||||||
window.Promise || document.write('<script src="https://unpkg.com/promise-polyfill/promise.min.js"><\/script>');
|
window.Promise || document.write('<script src="https://unpkg.com/promise-polyfill/promise.min.js"><\/script>');
|
||||||
window.fetch || document.write('<script src="https://unpkg.com/whatwg-fetch/fetch.js"><\/script>');
|
window.fetch || document.write('<script src="https://unpkg.com/whatwg-fetch/fetch.js"><\/script>');
|
||||||
</script>
|
</script>
|
||||||
<!--<script src="/assets/frontend/store2.min.js"></script>
|
|
||||||
<script src="/assets/js/form-save.js"></script>-->
|
|
||||||
<script defer src="/assets/js/newnote.js"></script>
|
<script defer src="/assets/js/newnote.js"></script>
|
||||||
|
|
||||||
<link rel="stylesheet" href="/assets/frontend/alertify.css">
|
<link rel="stylesheet" href="/assets/frontend/alertify.css">
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Route::group(['domain' => config('url.longurl')], function () {
|
Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::get('/', 'NotesController@showNotes');
|
Route::get('/', 'NotesController@index');
|
||||||
|
|
||||||
//Static project page
|
//Static project page
|
||||||
Route::get('projects', function () {
|
Route::get('projects', function () {
|
||||||
|
@ -89,8 +89,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
|
|
||||||
//micropub new notes page
|
//micropub new notes page
|
||||||
//this needs to be first so `notes/new` doesn't match `notes/{id}`
|
//this needs to be first so `notes/new` doesn't match `notes/{id}`
|
||||||
Route::get('notes/new', 'MicropubClientController@newNotePage');
|
|
||||||
Route::post('notes/new', 'MicropubClientController@postNewNote');
|
|
||||||
|
|
||||||
//Notes pages using NotesController
|
//Notes pages using NotesController
|
||||||
Route::get('notes', 'NotesController@index');
|
Route::get('notes', 'NotesController@index');
|
||||||
|
@ -104,10 +103,11 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::post('api/token', 'IndieAuthController@tokenEndpoint');
|
Route::post('api/token', 'IndieAuthController@tokenEndpoint');
|
||||||
Route::get('logout', 'IndieAuthController@indieauthLogout');
|
Route::get('logout', 'IndieAuthController@indieauthLogout');
|
||||||
|
|
||||||
//micropub endoints
|
// Micropub
|
||||||
Route::post('api/post', 'MicropubController@post');
|
Route::get('micropub/create', 'MicropubClientController@create')->name('micropub-client');
|
||||||
|
Route::post('micropub', 'MicropubClientController@store')->name('micropub-client-post');
|
||||||
Route::get('api/post', 'MicropubController@getEndpoint');
|
Route::get('api/post', 'MicropubController@getEndpoint');
|
||||||
|
Route::post('api/post', 'MicropubController@post');
|
||||||
//micropub refresh syndication targets
|
//micropub refresh syndication targets
|
||||||
Route::get('refresh-syndication-targets', 'MicropubClientController@refreshSyndicationTargets');
|
Route::get('refresh-syndication-targets', 'MicropubClientController@refreshSyndicationTargets');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue