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;
|
||||
|
||||
use App\Media;
|
||||
use App\Place;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Http\Request;
|
||||
|
@ -203,10 +204,10 @@ class MicropubController extends Controller
|
|||
]);
|
||||
}
|
||||
//nope, how about a config query?
|
||||
//this should have a media endpoint as well at some point
|
||||
if ($request->input('q') == 'config') {
|
||||
return response()->json([
|
||||
'syndicate-to' => config('syndication.targets'),
|
||||
'media-endpoint' => route('media-endpoint'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -258,28 +259,53 @@ class MicropubController extends Controller
|
|||
if ($request->file('file')->isValid()) {
|
||||
//save media
|
||||
try {
|
||||
$filename = Uuid::uuid4() . $request->file->extension();
|
||||
$filename = Uuid::uuid4() . '.' . $request->file('file')->extension();
|
||||
} catch (UnsatisfiedDependencyException $e) {
|
||||
return response()->json([
|
||||
'response' => 'error',
|
||||
'error' => 'internal_server_error',
|
||||
'error_description' => 'A problem occured handling your request'
|
||||
], 500)
|
||||
], 500);
|
||||
}
|
||||
try {
|
||||
$path = $request->file->storeAs('media', $filename, 's3');
|
||||
} catch(Excetion $e) { // which exception?
|
||||
$path = $request->file('file')->storeAs('media', $filename, 's3');
|
||||
} catch (Exception $e) { // which exception?
|
||||
return response()->json([
|
||||
'response' => 'error',
|
||||
'error' => 'service_unavailable',
|
||||
'error_description' => 'Unable to save media to S3'
|
||||
], 503)
|
||||
], 503);
|
||||
}
|
||||
$media = new Media();
|
||||
$media->token = $token;
|
||||
$media->path = $path;
|
||||
$media->save();
|
||||
|
||||
return $path;
|
||||
return response()->json([
|
||||
'response' => 'created',
|
||||
'location' => $media->url,
|
||||
], 201)->header('Location', $media->url);
|
||||
}
|
||||
|
||||
//return URL for media
|
||||
return response()->json([
|
||||
'response' => 'error',
|
||||
'error' => 'invalid_request',
|
||||
'error_description' => 'The uploaded file failed validation',
|
||||
], 400);
|
||||
}
|
||||
|
||||
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([
|
||||
|
|
|
@ -58,12 +58,6 @@ class NotesController extends Controller
|
|||
$note->place->icon
|
||||
);
|
||||
}
|
||||
$photoURLs = [];
|
||||
$photos = $note->getMedia();
|
||||
foreach ($photos as $photo) {
|
||||
$photoURLs[] = $photo->getUrl();
|
||||
}
|
||||
$note->photoURLs = $photoURLs;
|
||||
}
|
||||
|
||||
$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'));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,10 @@ class VerifyCsrfToken extends BaseVerifier
|
|||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'api/token',
|
||||
'api/media',
|
||||
'api/post',
|
||||
'webmention',
|
||||
'api/token',
|
||||
'places/new',
|
||||
'webmention',
|
||||
];
|
||||
}
|
||||
|
|
|
@ -20,4 +20,14 @@ class Media extends Model
|
|||
{
|
||||
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'),
|
||||
'region' => env('AWS_S3_REGION'),
|
||||
'bucket' => env('AWS_S3_BUCKET'),
|
||||
'url' => env('AWS_S3_URL'),
|
||||
],
|
||||
|
||||
'media' => [
|
||||
|
|
|
@ -14,13 +14,13 @@ class CreateMediaEndpointTable extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::create('media_endpoint', function (Blueprint $table) {
|
||||
$table->uuid('id');
|
||||
$table->varchar('client_id')->nullable();
|
||||
$table->varchar('filetype');
|
||||
$table->increments('id');
|
||||
$table->text('token')->nullable();
|
||||
$table->string('path');
|
||||
$table->unsignedInteger('note_id')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->primary('id');
|
||||
$table->index('token');
|
||||
$table->foreign('note_id')->references('id')->on('notes');
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,11 +8,6 @@
|
|||
<div class="note">
|
||||
<div class="e-content p-name">
|
||||
{!! $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 class="note-metadata">
|
||||
<div>
|
||||
|
|
|
@ -115,7 +115,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
|||
// Micropub Endpoint
|
||||
Route::get('api/post', 'MicropubController@get');
|
||||
Route::post('api/post', 'MicropubController@post');
|
||||
Route::post('api/media', 'MicropubController@media');
|
||||
Route::post('api/media', 'MicropubController@media')->name('media-endpoint');
|
||||
|
||||
//webmention
|
||||
Route::get('webmention', 'WebMentionsController@get');
|
||||
|
|
Loading…
Add table
Reference in a new issue