2021-04-01 10:59:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes\File;
|
|
|
|
|
2023-09-23 12:01:18 +00:00
|
|
|
use Illuminate\Contracts\Filesystem\Filesystem;
|
2023-06-22 07:36:22 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
use App\Models\Address;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
final class Item extends Receive
|
|
|
|
{
|
|
|
|
/** @var Address The address that sent us this item */
|
|
|
|
private Address $ao;
|
|
|
|
private string $recvas;
|
|
|
|
private int $recvmtime;
|
|
|
|
private int $recvsize;
|
2023-09-23 12:01:18 +00:00
|
|
|
private Filesystem $fs;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
/**
|
2023-07-02 13:40:08 +00:00
|
|
|
* @throws \Exception
|
2021-04-01 10:59:15 +00:00
|
|
|
*/
|
2023-07-17 06:36:53 +00:00
|
|
|
public function __construct(Address $ao,string $recvas,int $mtime,int $size)
|
2021-04-01 10:59:15 +00:00
|
|
|
{
|
2023-07-17 06:36:53 +00:00
|
|
|
parent::__construct();
|
2023-07-15 12:10:05 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
$this->ao = $ao;
|
|
|
|
$this->recvas = $recvas;
|
|
|
|
$this->recvmtime = $mtime;
|
|
|
|
$this->recvsize = $size;
|
2023-07-15 12:10:05 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
$this->ftype = self::IS_FILE;
|
2023-09-23 12:01:18 +00:00
|
|
|
$this->fs = Storage::disk(config('fido.local_disk'));
|
2023-07-17 06:36:53 +00:00
|
|
|
}
|
2023-07-15 12:10:05 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
public function __get($key) {
|
|
|
|
switch ($key) {
|
|
|
|
case 'exists':
|
2023-09-23 12:01:18 +00:00
|
|
|
return $this->fs->exists($this->rel_name);
|
2023-07-15 12:10:05 +00:00
|
|
|
|
2023-09-23 12:01:18 +00:00
|
|
|
case 'pref_name':
|
2023-09-05 08:41:41 +00:00
|
|
|
return sprintf('%04X-%s',$this->ao->id,$this->recvas);
|
2023-07-17 06:36:53 +00:00
|
|
|
case 'rel_name':
|
2023-09-23 12:01:18 +00:00
|
|
|
return sprintf('%s/%s',config('fido.dir'),$this->pref_name);
|
2023-07-17 06:36:53 +00:00
|
|
|
case 'full_name':
|
2023-09-23 12:01:18 +00:00
|
|
|
return $this->fs->path($this->rel_name);
|
2023-07-15 12:10:05 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
case 'match_mtime':
|
|
|
|
return $this->mtime === $this->recvmtime;
|
|
|
|
case 'match_size':
|
|
|
|
return $this->size === $this->recvsize;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
case 'nameas':
|
|
|
|
return $this->recvas;
|
|
|
|
case 'recvmtime':
|
|
|
|
return $this->recvmtime;
|
|
|
|
case 'recvsize':
|
|
|
|
return $this->recvsize;
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
case 'name_size_time':
|
|
|
|
return sprintf('%s %lu %lu',$this->recvas,$this->recvsize,$this->recvmtime);
|
2021-04-01 10:59:15 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
case 'mtime':
|
2023-09-23 12:01:18 +00:00
|
|
|
return $this->fs->lastModified($this->rel_name);
|
2023-07-15 12:10:05 +00:00
|
|
|
|
2023-07-17 06:36:53 +00:00
|
|
|
case 'size':
|
2023-09-23 12:01:18 +00:00
|
|
|
return $this->fs->size($this->rel_name);
|
2021-04-01 10:59:15 +00:00
|
|
|
|
|
|
|
default:
|
2023-07-17 06:36:53 +00:00
|
|
|
return parent::__get($key);
|
2021-04-01 10:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|