From fef167862dc405548eb3b03ae5099564b20c7256 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Wed, 7 Sep 2022 22:49:21 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Auto-add=20related=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Commands/GetShow.php | 4 ++-- app/Data/DataPipes/ExtraFiles.php | 36 +++++++++++++++++++++++++++++++ app/Data/InputData.php | 11 ++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 app/Data/DataPipes/ExtraFiles.php diff --git a/app/Commands/GetShow.php b/app/Commands/GetShow.php index 5686899..864f2b4 100644 --- a/app/Commands/GetShow.php +++ b/app/Commands/GetShow.php @@ -20,12 +20,12 @@ class GetShow extends Command protected $description = 'Queue a show to re-encode or download'; - public function handle(): int + public function handle(ProcessInput $proc): int { $this->line('Options: ' . json_encode($this->options()), verbosity: OutputInterface::VERBOSITY_DEBUG); $input = $this->getInput(); $this->line('Input: ' . json_encode($input), verbosity: OutputInterface::VERBOSITY_DEBUG); - $job = app()->make(ProcessInput::class)->getJob($input); + $job = $proc->getJob($input); $this->line('Job: ' . json_encode($job), verbosity: OutputInterface::VERBOSITY_DEBUG); return static::SUCCESS; diff --git a/app/Data/DataPipes/ExtraFiles.php b/app/Data/DataPipes/ExtraFiles.php new file mode 100644 index 0000000..9f25c5b --- /dev/null +++ b/app/Data/DataPipes/ExtraFiles.php @@ -0,0 +1,36 @@ +has('files') || !$properties->get('files')->count()) { + return $properties; + } + + $files = $properties->get('files'); + $col = $files->toCollection(); + foreach ($files->items() as $file) { + $pi = pathinfo($file->path); + foreach (glob($pi['dirname'].'/'.$pi['filename'].'*') as $path) { + if (!$col->first(fn (FileData $data) => $data->path === $path)) { + $files[] = $path; + } + } + } + $properties['files'] = $files; + + return $properties; + } +} diff --git a/app/Data/InputData.php b/app/Data/InputData.php index b162ca8..bfb2c00 100644 --- a/app/Data/InputData.php +++ b/app/Data/InputData.php @@ -7,6 +7,7 @@ use Spatie\LaravelData\Attributes\DataCollectionOf; use Spatie\LaravelData\Attributes\MapInputName; use Spatie\LaravelData\DataCollection; use Spatie\LaravelData\Attributes\WithCast; +use Spatie\LaravelData\DataPipeline; class InputData extends Data { @@ -40,4 +41,14 @@ class InputData extends Data { return !empty($this->files) && !!$this->files->count(); } + + public static function pipeline(): DataPipeline + { + return parent::pipeline()->through(DataPipes\ExtraFiles::class); + } + + public static function fillPipeline(): DataPipeline + { + return parent::fillPipeline()->through(DataPipes\ExtraFiles::class); + } }