2019-02-26 22:46:40 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2020-07-23 13:08:20 +09:00
|
|
|
use App\MetadataResolver\DeniedHostException;
|
2020-05-10 18:50:03 +09:00
|
|
|
use App\Services\MetadataResolveService;
|
2019-02-26 22:46:40 +09:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class CardController
|
|
|
|
{
|
2020-05-10 18:50:03 +09:00
|
|
|
public function show(Request $request, MetadataResolveService $service)
|
2019-02-26 22:46:40 +09:00
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'url:required|url'
|
|
|
|
]);
|
|
|
|
|
2020-07-23 13:08:20 +09:00
|
|
|
try {
|
|
|
|
$metadata = $service->execute($request->input('url'));
|
|
|
|
} catch (DeniedHostException $e) {
|
|
|
|
abort(403, $e->getMessage());
|
|
|
|
}
|
2019-06-24 22:39:01 +09:00
|
|
|
$metadata->load('tags');
|
|
|
|
|
2019-02-26 22:46:40 +09:00
|
|
|
$response = response($metadata);
|
|
|
|
if (!config('app.debug')) {
|
|
|
|
$response = $response->setCache(['public' => true, 'max_age' => 86400]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|