From b8534d85983e09079814c75c8b422ba6bb722e50 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 23 Jun 2023 17:33:47 +1000 Subject: [PATCH] Make filename unique for each area, rename column to name/lname for files --- app/Classes/FTN/Tic.php | 10 +++--- app/Classes/File/Item.php | 2 +- app/Models/File.php | 4 +-- .../2023_06_23_170537_unique_filenames.php | 34 +++++++++++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2023_06_23_170537_unique_filenames.php diff --git a/app/Classes/FTN/Tic.php b/app/Classes/FTN/Tic.php index ec8e168..cefc58f 100644 --- a/app/Classes/FTN/Tic.php +++ b/app/Classes/FTN/Tic.php @@ -81,7 +81,7 @@ class Tic extends FTNBase public function isNodelist(): bool { return (($this->fo->nodelist_filearea_id === $this->fo->filearea->domain->filearea_id) - && (preg_match(str_replace(['.','?'],['\.','.'],'#^'.$this->fo->filearea->domain->nodelist_filename.'$#i'),$this->fo->file))); + && (preg_match(str_replace(['.','?'],['\.','.'],'#^'.$this->fo->filearea->domain->nodelist_filename.'$#i'),$this->fo->name))); } /** @@ -101,7 +101,7 @@ class Tic extends FTNBase $result->put('ORIGIN',$fo->path->first()->ftn3d); $result->put('FROM',$sysaddress->ftn3d); $result->put('TO',$ao->ftn3d); - $result->put('FILE',$fo->file); + $result->put('FILE',$fo->name); $result->put('SIZE',$fo->size); if ($fo->description) $result->put('DESC',$fo->description); @@ -176,7 +176,7 @@ class Tic extends FTNBase if (! Storage::disk('local')->exists($x=sprintf('%s/%s-%s',config('app.fido'),$hex,$matches[2]))) throw new FileNotFoundException(sprintf('File not found? [%s]',$x)); - $this->fo->{$k} = $matches[2]; + $this->fo->name = $matches[2]; $this->fo->fullname = $x; break; @@ -191,8 +191,10 @@ class Tic extends FTNBase case 'pw': $pw = $matches[2]; - case 'desc': case 'lfile': + $this->fo->lname = $matches[2]; + + case 'desc': case 'magic': case 'replaces': case 'size': diff --git a/app/Classes/File/Item.php b/app/Classes/File/Item.php index a8eb7eb..5caaffc 100644 --- a/app/Classes/File/Item.php +++ b/app/Classes/File/Item.php @@ -116,7 +116,7 @@ class Item return $this->file_name; case 'sendas': - return $this->file_name ? basename($this->file_name) : $this->filemodel->file; + return $this->file_name ? basename($this->file_name) : $this->filemodel->name; default: throw new Exception('Unknown key: '.$key); diff --git a/app/Models/File.php b/app/Models/File.php index 9c98a31..f996c0a 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -3,11 +3,9 @@ namespace App\Models; use Carbon\Carbon; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\File as FileFacade; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Rennokki\QueryCache\Traits\QueryCacheable; @@ -161,7 +159,7 @@ class File extends Model public function getFullStoragePathAttribute(): string { - return sprintf('%04X/%s',$this->filearea_id,$this->file); + return sprintf('%04X/%s',$this->filearea_id,$this->name); } /* METHODS */ diff --git a/database/migrations/2023_06_23_170537_unique_filenames.php b/database/migrations/2023_06_23_170537_unique_filenames.php new file mode 100644 index 0000000..ce5645a --- /dev/null +++ b/database/migrations/2023_06_23_170537_unique_filenames.php @@ -0,0 +1,34 @@ +unique(['filearea_id','name']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +};