Implemented file sending during BINKP and EMSI sessions
This commit is contained in:
@@ -4,8 +4,11 @@ namespace App\Classes\File;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use League\Flysystem\UnreadableFileEncountered;
|
||||
|
||||
use App\Models\File;
|
||||
|
||||
/**
|
||||
* A file we are sending or receiving
|
||||
*
|
||||
@@ -35,6 +38,7 @@ class Item
|
||||
protected int $file_mtime = 0;
|
||||
protected int $file_type = 0;
|
||||
protected int $action = 0;
|
||||
protected File $filemodel;
|
||||
|
||||
public bool $sent = FALSE;
|
||||
public bool $received = FALSE;
|
||||
@@ -51,19 +55,27 @@ class Item
|
||||
|
||||
switch ($action) {
|
||||
case self::I_SEND:
|
||||
if (! is_string($file))
|
||||
throw new Exception('Invalid object creation - file should be a string');
|
||||
if ($file instanceof File) {
|
||||
$this->filemodel = $file;
|
||||
// @todo We should catch any exceptions if the default storage is s3 (it is) and we cannot find the file, or the s3 call fails
|
||||
$this->file_size = Storage::size($file->full_storage_path);
|
||||
$this->file_mtime = Storage::lastModified($file->full_storage_path);
|
||||
|
||||
if (! file_exists($file))
|
||||
throw new FileNotFoundException('Item doesnt exist: '.$file);
|
||||
} else {
|
||||
if (! is_string($file))
|
||||
throw new Exception('Invalid object creation - file should be a string');
|
||||
|
||||
if (! is_readable($file))
|
||||
throw new UnreadableFileEncountered('Item cannot be read: '.$file);
|
||||
if (! file_exists($file))
|
||||
throw new FileNotFoundException('Item doesnt exist: '.$file);
|
||||
|
||||
$this->file_name = $file;
|
||||
$x = stat($file);
|
||||
$this->file_size = $x['size'];
|
||||
$this->file_mtime = $x['mtime'];
|
||||
if (! is_readable($file))
|
||||
throw new UnreadableFileEncountered('Item cannot be read: '.$file);
|
||||
|
||||
$this->file_name = $file;
|
||||
$x = stat($file);
|
||||
$this->file_size = $x['size'];
|
||||
$this->file_mtime = $x['mtime'];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -104,7 +116,7 @@ class Item
|
||||
return $this->file_name;
|
||||
|
||||
case 'sendas':
|
||||
return basename($this->file_name);
|
||||
return $this->file_name ? basename($this->file_name) : $this->filemodel->file;
|
||||
|
||||
default:
|
||||
throw new Exception('Unknown key: '.$key);
|
||||
|
Reference in New Issue
Block a user