Implement paste storage

master
Les De Ridder 7 years ago
parent f389161b79
commit f8fbce2285
  1. 78
      app/Paste.php
  2. 21
      config/filesystems.php

@ -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'),
],
],

Loading…
Cancel
Save