Implement creator studio and upload updates
This commit is contained in:
@@ -32,6 +32,9 @@ class NovaCardBackgroundService
|
||||
throw new RuntimeException('Nova card background processing requires Intervention Image.');
|
||||
}
|
||||
|
||||
$sourcePath = $this->resolveUploadPath($file);
|
||||
$binary = $this->readUploadedBinary($sourcePath);
|
||||
|
||||
$uuid = (string) Str::uuid();
|
||||
$extension = strtolower($file->getClientOriginalExtension() ?: 'jpg');
|
||||
$originalDisk = Storage::disk((string) config('nova_cards.storage.private_disk', 'local'));
|
||||
@@ -43,9 +46,9 @@ class NovaCardBackgroundService
|
||||
$processedPath = trim((string) config('nova_cards.storage.background_processed_prefix', 'cards/backgrounds/processed'), '/')
|
||||
. '/' . $user->id . '/' . $uuid . '.webp';
|
||||
|
||||
$originalDisk->put($originalPath, file_get_contents($file->getRealPath()) ?: '');
|
||||
$originalDisk->put($originalPath, $binary);
|
||||
|
||||
$image = $this->manager->read($file->getRealPath())->scaleDown(width: 2200, height: 2200);
|
||||
$image = $this->manager->read($binary)->scaleDown(width: 2200, height: 2200);
|
||||
$encoded = (string) $image->encode(new WebpEncoder(88));
|
||||
$processedDisk->put($processedPath, $encoded);
|
||||
|
||||
@@ -57,8 +60,30 @@ class NovaCardBackgroundService
|
||||
'height' => $image->height(),
|
||||
'mime_type' => (string) ($file->getMimeType() ?: 'image/jpeg'),
|
||||
'file_size' => (int) $file->getSize(),
|
||||
'sha256' => hash_file('sha256', $file->getRealPath()) ?: null,
|
||||
'sha256' => hash('sha256', $binary),
|
||||
'visibility' => 'card-only',
|
||||
]);
|
||||
}
|
||||
|
||||
private function resolveUploadPath(UploadedFile $file): string
|
||||
{
|
||||
$path = $file->getRealPath() ?: $file->getPathname();
|
||||
|
||||
if (! is_string($path) || trim($path) === '' || ! is_readable($path)) {
|
||||
throw new RuntimeException('Unable to resolve uploaded background path.');
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function readUploadedBinary(string $path): string
|
||||
{
|
||||
$binary = @file_get_contents($path);
|
||||
|
||||
if ($binary === false || $binary === '') {
|
||||
throw new RuntimeException('Unable to read uploaded background image.');
|
||||
}
|
||||
|
||||
return $binary;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user