|
|
@@ -3,9 +3,8 @@
|
|
|
namespace Webkul\Theme\Repositories;
|
|
|
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
-use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Str;
|
|
|
-use Intervention\Image\ImageManager;
|
|
|
+use Longyi\ImageUpload\Services\ImageUploadService;
|
|
|
use Stevebauman\Purify\Facades\Purify;
|
|
|
use Webkul\Core\Eloquent\Repository;
|
|
|
use Webkul\Theme\Contracts\ThemeCustomization;
|
|
|
@@ -58,9 +57,6 @@ class ThemeCustomizationRepository extends Repository
|
|
|
/**
|
|
|
* Mass update the status of themes in the repository.
|
|
|
*
|
|
|
- * This method updates multiple records in the database based on the provided
|
|
|
- * theme IDs.
|
|
|
- *
|
|
|
* @param int $themeIds
|
|
|
* @return int The number of records updated.
|
|
|
*/
|
|
|
@@ -77,10 +73,17 @@ class ThemeCustomizationRepository extends Repository
|
|
|
public function uploadImage(array $data, ThemeCustomization $theme)
|
|
|
{
|
|
|
$locale = core()->getRequestedLocaleCode();
|
|
|
+ $imageUploadService = app(ImageUploadService::class);
|
|
|
|
|
|
if (isset($data[$locale]['deleted_sliders'])) {
|
|
|
foreach ($data[$locale]['deleted_sliders'] as $slider) {
|
|
|
- Storage::delete(str_replace('storage/', '', $slider['image']));
|
|
|
+ $deletePath = str_replace('storage/', '', $slider['image']);
|
|
|
+ $deletePath = str_replace(rtrim(env('AWS_URL', ''), '/') . '/', '', $deletePath);
|
|
|
+ try {
|
|
|
+ $imageUploadService->delete(ltrim($deletePath, '/'));
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // S3 删除失败不阻塞流程
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -99,11 +102,8 @@ class ThemeCustomizationRepository extends Repository
|
|
|
];
|
|
|
} elseif ($image['image'] instanceof UploadedFile) {
|
|
|
try {
|
|
|
- $manager = new ImageManager;
|
|
|
-
|
|
|
- $path = 'theme/'.$theme->id.'/'.Str::random(40).'.webp';
|
|
|
-
|
|
|
- Storage::put($path, $manager->make($image['image'])->encode('webp'));
|
|
|
+ $directory = 'uploads/theme/' . $theme->id;
|
|
|
+ $result = $imageUploadService->upload($image['image'], $directory);
|
|
|
} catch (\Exception $e) {
|
|
|
session()->flash('error', $e->getMessage());
|
|
|
|
|
|
@@ -111,11 +111,11 @@ class ThemeCustomizationRepository extends Repository
|
|
|
}
|
|
|
|
|
|
if (($data['type'] ?? '') == 'static_content') {
|
|
|
- return Storage::url($path);
|
|
|
+ return $result['url'];
|
|
|
}
|
|
|
|
|
|
$options['images'][] = [
|
|
|
- 'image' => 'storage/'.$path,
|
|
|
+ 'image' => $result['url'],
|
|
|
'link' => $image['link'],
|
|
|
'title' => $image['title'],
|
|
|
];
|