Implement paste storage

This commit is contained in:
Les De Ridder 2016-05-29 02:14:29 +02:00
부모 f389161b79
커밋 f8fbce2285
2개의 변경된 파일78개의 추가작업 그리고 21개의 파일을 삭제

파일 보기

@ -4,6 +4,9 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
use Storage;
class Paste extends Model
{
public $incrementing = false;
@ -14,14 +17,9 @@ class Paste extends Model
return $this->hasOne(Deletion::class);
}
public function isDeleted()
{
return $this->deletion !== null;
}
public function soft_delete($reason, $deleted_by)
{
if($this->isDeleted())
if($this->deleted)
{
return false;
}
@ -35,4 +33,72 @@ class Paste extends Model
return true;
}
public function try_hard_delete()
{
if(Storage::disk('ephemeral')->exists($this->id) && $this->has_expired)
{
Storage::disk('ephemeral')->delete($this->id);
}
}
public function getDeletedAttribute()
{
return $this->deletion !== null;
}
public function getExpiresAttribute()
{
return $this->expires_at !== null;
}
public function getHasExpiredAttribute()
{
return $this->expires && $this->expires_at < Carbon::now();
}
public function getContentAttribute()
{
if($this->deleted)
{
return null;
}
if($this->expires)
{
if($this->has_expired)
{
$this->try_hard_delete();
return null;
}
else
{
return Storage::disk('ephemeral')->get($this->id);
}
}
else
{
return Storage::disk('persistent')->get($this->id);
}
}
public function setContentAttribute($content)
{
if($this->deleted || $this->has_expired)
{
//TODO: Throw an exception
return;
}
if($this->expires)
{
Storage::disk('ephemeral')->put($this->id, $content);
}
else
{
Storage::disk('persistent')->put($this->id, $content);
}
}
}

파일 보기

@ -15,7 +15,7 @@ return [
|
*/
'default' => 'local',
'default' => 'null',
/*
|--------------------------------------------------------------------------
@ -28,7 +28,7 @@ return [
|
*/
'cloud' => 's3',
'cloud' => 'null',
/*
|--------------------------------------------------------------------------
@ -43,23 +43,14 @@ return [
'disks' => [
'local' => [
'persistent' => [
'driver' => 'local',
'root' => storage_path('app'),
'root' => storage_path('app/persistent'),
],
'public' => [
'ephemeral' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
'root' => storage_path('app/ephemeral'),
],
],