This commit is contained in:
2026-04-15 19:34:56 +05:00
parent 34ffed1e4a
commit e243821f50
26 changed files with 2072 additions and 1258 deletions

View File

@@ -53,9 +53,19 @@ class Child
foreach ($color['screens'] as $screen) {
$folder = Carbon::now()->format('Y/m/d');
$path = $screen['image']->store($screen['image']);
// Store original
$path = $screen['image']->store("uploads/screens/{$folder}");
$thumbPath = $this->storeImageToS3($screen['image']);
// Store and resize thumb
$tempPath = $screen['image']->store('temp', 'public');
$thumbPath = $this->image->resize($tempPath, 322, 'screens', true);
// Get screen size (local or s3)
if (env('FILESYSTEM_DISK') == 's3') {
$this->size = Storage::disk('s3')->size($path);
} else {
$this->size = filesize(public_path($path));
}
Screen::create([
'path' => $path,
@@ -68,28 +78,4 @@ class Child
}
}
}
private function storeImageToS3($image): string
{
$path = '';
// first store temp file and resize it, then upload to s3
// 1 - store temp file
$tempPath = $image->store('temp', 'public');
if ($tempPath) {
$tempFilePath = storage_path('app/public/' . $tempPath);
$image = new ImageResize();
$path = $image->resize($tempPath, 322, 'screens');
$this->size = filesize(public_path($path));
// 2 - upload local $path to s3
// Store the image on S3
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
Storage::disk('s3')->put($path, file_get_contents(public_path($path)));
unlink($path);
}
}
return $path;
}
}

View File

@@ -79,19 +79,23 @@ class ChildUpdate
{
if (!empty($screens)) {
foreach ($screens as $screen) {
if ($screen['id'] == 'undefined' || $screen['id'] == 'null' || $screen['id'] = null) {
if ($screen['id'] == 'undefined' || $screen['id'] == 'null' || $screen['id'] == null) {
$folder = Carbon::now()->format('Y/m/d');
if ($screen['image']) {
// 1. Store original (S3 if enabled)
$path = $screen['image']->store("uploads/screens/{$folder}");
$image = Screen::create([
// 2. Local temp for resizing
$tempPath = $screen['image']->store('temp', 'public');
$thumbPath = $this->image->resize($tempPath, 322, 'screens', true);
Screen::create([
'path' => $path,
'path_thumb' => "uploads/screens/thumbs/{$folder}/" . basename($path),
'path_thumb' => $thumbPath,
'name' => basename($path),
'product_id' => $child_id,
'size' => Storage::size($path)
'size' => Storage::disk(env('FILESYSTEM_DISK'))->size($path)
]);
$this->image->resize($image->path, 322, 'screens');
}
}
}

View File

@@ -33,18 +33,21 @@ class Screen
*/
public function handle()
{
$folder = Carbon::now()->format('Y/m/d');
//$folder = 'uploads/screens/'.date('Y', time()).'/'.Carbon::now()->format('m').'/'.Carbon::now()->format('d');
foreach ($this->request as $screen) {
$folder = Carbon::now()->format('Y/m/d');
// 1. Store original (S3 if enabled)
$path = $screen->store("uploads/screens/original/{$folder}");
$thumb = $this->img->resize($path, 350, 'screens');
// 2. Local temp for resizing
$tempPath = $screen->store('temp', 'public');
$thumb = $this->img->resize($tempPath, 350, 'screens', true);
$screens = new Screens();
$screens->name = basename($path);
$screens->path = $path;
$screens->path_thumb = $thumb;
$screens->size = filesize($path);
$screens->size = Storage::disk(env('FILESYSTEM_DISK'))->size($path);
$screens->product_id = $this->id;
$screens->save();
}