Rework TIC processing to use Storage::disk(). Implemented handling of replaces and files that already exist

This commit is contained in:
2023-09-23 22:01:18 +10:00
parent 56544b89e1
commit ff04de52b5
10 changed files with 199 additions and 105 deletions

View File

@@ -2,19 +2,19 @@
namespace App\Classes\File;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Storage;
use App\Models\Address;
final class Item extends Receive
{
private const LOCATION = 'local';
/** @var Address The address that sent us this item */
private Address $ao;
private string $recvas;
private int $recvmtime;
private int $recvsize;
private Filesystem $fs;
/**
* @throws \Exception
@@ -29,19 +29,20 @@ final class Item extends Receive
$this->recvsize = $size;
$this->ftype = self::IS_FILE;
$this->fs = Storage::disk(config('fido.local_disk'));
}
public function __get($key) {
switch ($key) {
case 'exists':
return Storage::disk(self::LOCATION)->exists($this->rel_name);
return $this->fs->exists($this->rel_name);
case 'stor_name':
case 'pref_name':
return sprintf('%04X-%s',$this->ao->id,$this->recvas);
case 'rel_name':
return sprintf('%s/%s',config('fido.dir'),$this->stor_name);
return sprintf('%s/%s',config('fido.dir'),$this->pref_name);
case 'full_name':
return Storage::disk(self::LOCATION)->path($this->rel_name);
return $this->fs->path($this->rel_name);
case 'match_mtime':
return $this->mtime === $this->recvmtime;
@@ -59,10 +60,10 @@ final class Item extends Receive
return sprintf('%s %lu %lu',$this->recvas,$this->recvsize,$this->recvmtime);
case 'mtime':
return Storage::disk(self::LOCATION)->lastModified($this->rel_name);
return $this->fs->lastModified($this->rel_name);
case 'size':
return Storage::disk(self::LOCATION)->size($this->rel_name);
return $this->fs->size($this->rel_name);
default:
return parent::__get($key);