Merge branch 'feature/media-endpoint' of github.com:jonnybarnes/jonnybarnes.uk into feature/media-endpoint
This commit is contained in:
commit
2f5ad52181
8 changed files with 53 additions and 33 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Media;
|
||||||
use App\Place;
|
use App\Place;
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
@ -203,10 +204,10 @@ class MicropubController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
//nope, how about a config query?
|
//nope, how about a config query?
|
||||||
//this should have a media endpoint as well at some point
|
|
||||||
if ($request->input('q') == 'config') {
|
if ($request->input('q') == 'config') {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'syndicate-to' => config('syndication.targets'),
|
'syndicate-to' => config('syndication.targets'),
|
||||||
|
'media-endpoint' => route('media-endpoint'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,28 +259,53 @@ class MicropubController extends Controller
|
||||||
if ($request->file('file')->isValid()) {
|
if ($request->file('file')->isValid()) {
|
||||||
//save media
|
//save media
|
||||||
try {
|
try {
|
||||||
$filename = Uuid::uuid4() . $request->file->extension();
|
$filename = Uuid::uuid4() . '.' . $request->file('file')->extension();
|
||||||
} catch (UnsatisfiedDependencyException $e) {
|
} catch (UnsatisfiedDependencyException $e) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'response' => 'error',
|
'response' => 'error',
|
||||||
'error' => 'internal_server_error',
|
'error' => 'internal_server_error',
|
||||||
'error_description' => 'A problem occured handling your request'
|
'error_description' => 'A problem occured handling your request'
|
||||||
], 500)
|
], 500);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$path = $request->file->storeAs('media', $filename, 's3');
|
$path = $request->file('file')->storeAs('media', $filename, 's3');
|
||||||
} catch(Excetion $e) { // which exception?
|
} catch (Exception $e) { // which exception?
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'response' => 'error',
|
'response' => 'error',
|
||||||
'error' => 'service_unavailable',
|
'error' => 'service_unavailable',
|
||||||
'error_description' => 'Unable to save media to S3'
|
'error_description' => 'Unable to save media to S3'
|
||||||
], 503)
|
], 503);
|
||||||
|
}
|
||||||
|
$media = new Media();
|
||||||
|
$media->token = $token;
|
||||||
|
$media->path = $path;
|
||||||
|
$media->save();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'response' => 'created',
|
||||||
|
'location' => $media->url,
|
||||||
|
], 201)->header('Location', $media->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $path;
|
return response()->json([
|
||||||
|
'response' => 'error',
|
||||||
|
'error' => 'invalid_request',
|
||||||
|
'error_description' => 'The uploaded file failed validation',
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
//return URL for media
|
return response()->json([
|
||||||
|
'response' => 'error',
|
||||||
|
'error' => 'insufficient_scope',
|
||||||
|
'error_description' => 'The provided token has insufficient scopes',
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'response' => 'error',
|
||||||
|
'error' => 'unauthorized',
|
||||||
|
'error_description' => 'No token provided with request',
|
||||||
|
], 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|
|
@ -58,12 +58,6 @@ class NotesController extends Controller
|
||||||
$note->place->icon
|
$note->place->icon
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$photoURLs = [];
|
|
||||||
$photos = $note->getMedia();
|
|
||||||
foreach ($photos as $photo) {
|
|
||||||
$photoURLs[] = $photo->getUrl();
|
|
||||||
}
|
|
||||||
$note->photoURLs = $photoURLs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$homepage = ($request->path() == '/');
|
$homepage = ($request->path() == '/');
|
||||||
|
@ -164,13 +158,6 @@ class NotesController extends Controller
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$photoURLs = [];
|
|
||||||
$photos = $note->getMedia();
|
|
||||||
foreach ($photos as $photo) {
|
|
||||||
$photoURLs[] = $photo->getUrl();
|
|
||||||
}
|
|
||||||
$note->photoURLs = $photoURLs;
|
|
||||||
|
|
||||||
return view('notes.show', compact('note', 'replies', 'reposts', 'likes'));
|
return view('notes.show', compact('note', 'replies', 'reposts', 'likes'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,10 @@ class VerifyCsrfToken extends BaseVerifier
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $except = [
|
protected $except = [
|
||||||
'api/token',
|
'api/media',
|
||||||
'api/post',
|
'api/post',
|
||||||
'webmention',
|
'api/token',
|
||||||
'places/new',
|
'places/new',
|
||||||
|
'webmention',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,14 @@ class Media extends Model
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Note');
|
return $this->belongsTo('App\Note');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the URL for an S3 media file.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUrlAttribute()
|
||||||
|
{
|
||||||
|
return config('filesystems.disks.s3.url') . '/' . $this->path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ return [
|
||||||
'secret' => env('AWS_S3_SECRET'),
|
'secret' => env('AWS_S3_SECRET'),
|
||||||
'region' => env('AWS_S3_REGION'),
|
'region' => env('AWS_S3_REGION'),
|
||||||
'bucket' => env('AWS_S3_BUCKET'),
|
'bucket' => env('AWS_S3_BUCKET'),
|
||||||
|
'url' => env('AWS_S3_URL'),
|
||||||
],
|
],
|
||||||
|
|
||||||
'media' => [
|
'media' => [
|
||||||
|
|
|
@ -14,13 +14,13 @@ class CreateMediaEndpointTable extends Migration
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::create('media_endpoint', function (Blueprint $table) {
|
Schema::create('media_endpoint', function (Blueprint $table) {
|
||||||
$table->uuid('id');
|
$table->increments('id');
|
||||||
$table->varchar('client_id')->nullable();
|
$table->text('token')->nullable();
|
||||||
$table->varchar('filetype');
|
$table->string('path');
|
||||||
$table->unsignedInteger('note_id')->nullable();
|
$table->unsignedInteger('note_id')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
||||||
$table->primary('id');
|
$table->index('token');
|
||||||
$table->foreign('note_id')->references('id')->on('notes');
|
$table->foreign('note_id')->references('id')->on('notes');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,6 @@
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<div class="e-content p-name">
|
<div class="e-content p-name">
|
||||||
{!! $note->note !!}
|
{!! $note->note !!}
|
||||||
@if(count($note->photoURLs) > 0)
|
|
||||||
@foreach($note->photoURLs as $photoURL)
|
|
||||||
<img src="{{ $photoURL }}" alt="" class="note-photo u-photo">
|
|
||||||
@endforeach
|
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
<div class="note-metadata">
|
<div class="note-metadata">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -115,7 +115,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
// Micropub Endpoint
|
// Micropub Endpoint
|
||||||
Route::get('api/post', 'MicropubController@get');
|
Route::get('api/post', 'MicropubController@get');
|
||||||
Route::post('api/post', 'MicropubController@post');
|
Route::post('api/post', 'MicropubController@post');
|
||||||
Route::post('api/media', 'MicropubController@media');
|
Route::post('api/media', 'MicropubController@media')->name('media-endpoint');
|
||||||
|
|
||||||
//webmention
|
//webmention
|
||||||
Route::get('webmention', 'WebMentionsController@get');
|
Route::get('webmention', 'WebMentionsController@get');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue