✨ Auto-add related files
This commit is contained in:
parent
901a750ce3
commit
fef167862d
3 changed files with 49 additions and 2 deletions
|
|
@ -20,12 +20,12 @@ class GetShow extends Command
|
||||||
|
|
||||||
protected $description = 'Queue a show to re-encode or download';
|
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);
|
$this->line('Options: ' . json_encode($this->options()), verbosity: OutputInterface::VERBOSITY_DEBUG);
|
||||||
$input = $this->getInput();
|
$input = $this->getInput();
|
||||||
$this->line('Input: ' . json_encode($input), verbosity: OutputInterface::VERBOSITY_DEBUG);
|
$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);
|
$this->line('Job: ' . json_encode($job), verbosity: OutputInterface::VERBOSITY_DEBUG);
|
||||||
|
|
||||||
return static::SUCCESS;
|
return static::SUCCESS;
|
||||||
|
|
|
||||||
36
app/Data/DataPipes/ExtraFiles.php
Normal file
36
app/Data/DataPipes/ExtraFiles.php
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Data\DataPipes;
|
||||||
|
|
||||||
|
use App\Data\FileData;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Spatie\LaravelData\DataPipes\DataPipe;
|
||||||
|
use Spatie\LaravelData\Lazy;
|
||||||
|
use Spatie\LaravelData\Optional;
|
||||||
|
use Spatie\LaravelData\Support\DataClass;
|
||||||
|
use Spatie\LaravelData\Support\DataConfig;
|
||||||
|
use Spatie\LaravelData\Support\DataProperty;
|
||||||
|
|
||||||
|
class ExtraFiles implements DataPipe
|
||||||
|
{
|
||||||
|
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
||||||
|
{
|
||||||
|
if (!$properties->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||||
use Spatie\LaravelData\Attributes\MapInputName;
|
use Spatie\LaravelData\Attributes\MapInputName;
|
||||||
use Spatie\LaravelData\DataCollection;
|
use Spatie\LaravelData\DataCollection;
|
||||||
use Spatie\LaravelData\Attributes\WithCast;
|
use Spatie\LaravelData\Attributes\WithCast;
|
||||||
|
use Spatie\LaravelData\DataPipeline;
|
||||||
|
|
||||||
class InputData extends Data
|
class InputData extends Data
|
||||||
{
|
{
|
||||||
|
|
@ -40,4 +41,14 @@ class InputData extends Data
|
||||||
{
|
{
|
||||||
return !empty($this->files) && !!$this->files->count();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue