Merge pull request #32 from eai04191/feature-Metadata-Expires
This commit is contained in:
commit
0d4a61ef15
@ -43,14 +43,14 @@ class LinkCollector
|
||||
// 無かったら取得
|
||||
// TODO: ある程度古かったら再取得とかありだと思う
|
||||
$metadata = Metadata::find($url);
|
||||
if ($metadata == null) {
|
||||
if ($metadata == null || ($metadata->expires_at !== null && $metadata->expires_at < now())) {
|
||||
try {
|
||||
$resolved = $this->metadataResolver->resolve($url);
|
||||
Metadata::create([
|
||||
'url' => $url,
|
||||
Metadata::updateOrCreate(['url' => $url], [
|
||||
'title' => $resolved->title,
|
||||
'description' => $resolved->description,
|
||||
'image' => $resolved->image
|
||||
'image' => $resolved->image,
|
||||
'expires_at' => $resolved->expires_at
|
||||
]);
|
||||
} catch (TransferException $e) {
|
||||
// 何らかの通信エラーによってメタデータの取得に失敗した時、とりあえずエラーログにURLを残す
|
||||
|
@ -10,6 +10,8 @@ class Metadata extends Model
|
||||
protected $primaryKey = 'url';
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $fillable = ['url', 'title', 'description', 'image'];
|
||||
protected $visible = ['url', 'title', 'description', 'image'];
|
||||
protected $fillable = ['url', 'title', 'description', 'image', 'expires_at'];
|
||||
protected $visible = ['url', 'title', 'description', 'image', 'expires_at'];
|
||||
|
||||
protected $dates = ['created_at', 'updated_at', 'expires_at'];
|
||||
}
|
||||
|
@ -2,9 +2,13 @@
|
||||
|
||||
namespace App\MetadataResolver;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Metadata
|
||||
{
|
||||
public $title = '';
|
||||
public $description = '';
|
||||
public $image = '';
|
||||
/** @var Carbon|null */
|
||||
public $expires_at = null;
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddExpiresOnMetadata extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('metadata', function (Blueprint $table) {
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('metadata', function (Blueprint $table) {
|
||||
$table->removeColumn('expires_at');
|
||||
});
|
||||
}
|
||||
}
|
@ -26,13 +26,13 @@ Route::get('/checkin/card', function (Request $request, MetadataResolver $resolv
|
||||
$url = $formatter->normalizeUrl($request->input('url'));
|
||||
|
||||
$metadata = App\Metadata::find($url);
|
||||
if ($metadata == null) {
|
||||
if ($metadata == null || ($metadata->expires_at !== null && $metadata->expires_at < now())) {
|
||||
$resolved = $resolver->resolve($url);
|
||||
$metadata = App\Metadata::create([
|
||||
'url' => $url,
|
||||
$metadata = App\Metadata::updateOrCreate(['url' => $url], [
|
||||
'title' => $resolved->title,
|
||||
'description' => $resolved->description,
|
||||
'image' => $resolved->image
|
||||
'image' => $resolved->image,
|
||||
'expires_at' => $resolved->expires_at
|
||||
]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user