Rework TIC processing and added test cases

This commit is contained in:
2023-11-22 10:40:15 +11:00
parent 5b24ff944f
commit 9fd8264c3f
30 changed files with 847 additions and 403 deletions

View File

@@ -21,9 +21,10 @@ class File extends Model
private const LOGKEY = 'MF-';
private bool $no_export = FALSE;
public string $prefix = '';
public Collection $set_path;
public Collection $set_seenby;
public string $src_file = '';
protected $casts = [
'kludges' => CollectionOrNull::class,
@@ -50,7 +51,7 @@ class File extends Model
return;
}
Log::info(sprintf('%s:- Storing file [%s] in [%s]',self::LOGKEY,$model->recvd_rel_name,$model->rel_name));
Log::info(sprintf('%s:- Storing file [%s] in [%s]',self::LOGKEY,$model->src_file,$model->rel_name));
$srcfs = Storage::disk(config('fido.local_disk'));
$tgtfs = Storage::disk(config('fido.file_disk'));
@@ -64,11 +65,11 @@ class File extends Model
}
// Store file
if ($tgtfs->put($model->rel_name,$srcfs->get($model->recvd_rel_name),'public')) {
$srcfs->delete($model->recvd_rel_name);
if ($tgtfs->put($model->rel_name,$srcfs->get($model->src_file),'public')) {
$srcfs->delete($model->src_file);
} else {
throw new \Exception(sprintf('Unable to move file [%s] to [%s]',$model->recvd_rel_name,$model->rel_name));
throw new \Exception(sprintf('Unable to move file [%s] to [%s]',$model->src_file,$model->rel_name));
}
});
@@ -88,7 +89,7 @@ class File extends Model
// Parse PATH
foreach ($model->set_path as $line) {
$matches = [];
preg_match(sprintf('#^(%s)\ ?([0-9]+)\ ?(.*)$#',Address::ftn_regex),$line,$matches);
preg_match(sprintf('#^(\d+:\d+/\d+(\.\d+)?(@%s)?)\ ((\d+)\ )?(.*)$#',Address::ftn_regex),$line,$matches);
if ($x=Arr::get($matches,1)) {
$ftn = Address::parseFTN($x);
@@ -101,7 +102,7 @@ class File extends Model
if (! $ao)
$ao = Address::createFTN($x,System::createUnknownSystem());
$path->push(['address'=>$ao,'datetime'=>Carbon::createFromTimestamp($matches[9]),'extra'=>$matches[10]]);
$path->push(['address'=>$ao,'datetime'=>Carbon::createFromTimestamp($matches[12]),'extra'=>$matches[13]]);
}
}
@@ -192,6 +193,11 @@ class File extends Model
/* ATTRIBUTES */
public function getOriginAttribute(): Address
{
return $this->path->sortBy('parent_id')->last();
}
/**
* Return the relative path to Storage::disk() in the store
*
@@ -202,26 +208,6 @@ class File extends Model
return sprintf('%04X/%s',$this->filearea_id,$this->name);
}
/**
* Return the relative path to Storage::disk() in the inbound;
*
* @return string
*/
public function getRecvdRelNameAttribute(): string
{
return sprintf('%s/%s',config('fido.dir'),$this->recvd_pref_name);
}
/**
* This is the name of the file, with the sender prefix
*
* @return string
*/
public function getRecvdPrefNameAttribute(): string
{
return sprintf('%s%s',$this->prefix ? $this->prefix.'-' : '',$this->name);
}
/* METHODS */
public function jsonSerialize(): array