2017-08-27 04:44:53 +09:00
|
|
|
<?php
|
|
|
|
|
2018-04-15 02:05:41 +09:00
|
|
|
use App\MetadataResolver\MetadataResolver;
|
2018-06-07 23:46:40 +09:00
|
|
|
use App\Utilities\Formatter;
|
2017-08-27 04:44:53 +09:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| API Routes
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| Here is where you can register API routes for your application. These
|
|
|
|
| routes are loaded by the RouteServiceProvider within a group which
|
|
|
|
| is assigned the "api" middleware group. Enjoy building your API!
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Route::middleware('auth:api')->get('/user', function (Request $request) {
|
|
|
|
return $request->user();
|
|
|
|
});
|
2018-01-05 00:26:48 +09:00
|
|
|
|
2018-06-07 23:46:40 +09:00
|
|
|
Route::get('/checkin/card', function (Request $request, MetadataResolver $resolver, Formatter $formatter) {
|
2018-01-05 00:26:48 +09:00
|
|
|
$request->validate([
|
|
|
|
'url:required|url'
|
|
|
|
]);
|
2018-06-07 23:46:40 +09:00
|
|
|
$url = $formatter->normalizeUrl($request->input('url'));
|
|
|
|
|
|
|
|
$metadata = App\Metadata::find($url);
|
2019-01-15 23:58:14 +09:00
|
|
|
if ($metadata == null || ($metadata->expires_at !== null && new DateTime($metadata->expires_at) < new DateTime("now"))) {
|
2018-06-07 23:46:40 +09:00
|
|
|
$resolved = $resolver->resolve($url);
|
|
|
|
$metadata = App\Metadata::create([
|
|
|
|
'url' => $url,
|
|
|
|
'title' => $resolved->title,
|
|
|
|
'description' => $resolved->description,
|
2019-01-15 15:31:15 +09:00
|
|
|
'image' => $resolved->image,
|
|
|
|
'expires_at' => $resolved->expires_at
|
2018-06-07 23:46:40 +09:00
|
|
|
]);
|
|
|
|
}
|
2018-01-05 00:26:48 +09:00
|
|
|
|
2018-04-15 02:05:41 +09:00
|
|
|
$response = response()->json($metadata);
|
|
|
|
if (!config('app.debug')) {
|
|
|
|
$response = $response->setCache(['public' => true, 'max_age' => 86400]);
|
2018-01-05 00:26:48 +09:00
|
|
|
}
|
2019-01-15 00:05:01 +09:00
|
|
|
|
2018-04-15 02:05:41 +09:00
|
|
|
return $response;
|
2019-01-15 00:05:01 +09:00
|
|
|
});
|