Improve caching, performance and add dry-run

This commit is contained in:
René Preuß
2021-07-22 16:42:01 +02:00
parent 53cff7d805
commit 820287dd2c
13 changed files with 342 additions and 40 deletions

View File

@@ -5,7 +5,7 @@ namespace App\Bunny\Filesystem;
use Illuminate\Support\Str;
use stdClass;
class EdgeFile implements File
class EdgeFile implements File, FileSerialized
{
private stdClass $file;
@@ -14,6 +14,16 @@ class EdgeFile implements File
$this->file = $file;
}
public static function fromFilename(string $path, string $sha256 = null): self
{
return new self((object)[
'Path' => Str::replaceLast($basename = basename($path), '', $path),
'ObjectName' => $basename,
'IsDirectory' => Str::endsWith($path, '/'),
'Checksum' => $sha256,
]);
}
public function getFilename($search = '', $replace = ''): string
{
return Str::replaceFirst($search, $replace, $this->file->Path . $this->file->ObjectName);
@@ -21,11 +31,24 @@ class EdgeFile implements File
public function isDirectory(): bool
{
return $this->file->IsDirectory;
return $this->getChecksum() === null;
}
public function getChecksum(): string
public function getChecksum(): ?string
{
return $this->file->Checksum;
return $this->file->IsDirectory ? null : $this->file->Checksum;
}
public function toArray(): array
{
return [
'sha256' => $this->getChecksum(),
'filename' => $this->getFilename(),
];
}
public static function fromArray(array $array): self
{
return self::fromFilename($array['filename'], $array['sha256']);
}
}