Skip to content

Commit

Permalink
Merge pull request #46 from xamthor/master
Browse files Browse the repository at this point in the history
Fix S3 issue with thumbnails generating.
  • Loading branch information
advoor authored Nov 28, 2020
2 parents 70f48f6 + 5ef6035 commit 4c04a4b
Showing 1 changed file with 53 additions and 6 deletions.
59 changes: 53 additions & 6 deletions src/Http/Controllers/EditorJsImageUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EditorJsImageUploadController extends Controller
*/
public function file(NovaRequest $request)
{

$validator = Validator::make($request->all(), [
'image' => 'required|image',
]);
Expand All @@ -34,8 +35,22 @@ public function file(NovaRequest $request)
config('nova-editor-js.toolSettings.image.disk')
);

$this->applyAlterations(Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->path($path));
$thumbnails = $this->applyThumbnails($path);
if(config('nova-editor-js.toolSettings.image.disk') !== 'local'){

$tempPath = $request->file('image')->store(
config('nova-editor-js.toolSettings.image.path'),
'local'
);

$this->applyAlterations(Storage::disk('local')->path($tempPath));
$thumbnails = $this->applyThumbnails($tempPath);

$this->deleteThumbnails(Storage::disk('local')->path($tempPath));
Storage::disk('local')->delete($path);
}else{
$this->applyAlterations(Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->path($path));
$thumbnails = $this->applyThumbnails($path);
}

return [
'success' => 1,
Expand Down Expand Up @@ -100,6 +115,7 @@ function ($attribute, $value, $fail) {
private function applyAlterations($path, $alterations = [])
{
try {

$image = Image::load($path);

$imageSettings = config('nova-editor-js.toolSettings.image.alterations');
Expand Down Expand Up @@ -178,16 +194,47 @@ private function applyThumbnails($path)

$newThumbnailName = $filename . $thumbnailName . '.' . $extension;
$newThumbnailPath = config('nova-editor-js.toolSettings.image.path') . '/' . $newThumbnailName;

Storage::disk(config('nova-editor-js.toolSettings.image.disk') )->copy($path, $newThumbnailPath);

Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->copy($path, $newThumbnailPath);
if(config('nova-editor-js.toolSettings.image.disk') !== 'local'){
Storage::disk('local')->copy($path, $newThumbnailPath);
$newPath = Storage::disk('local')->path($newThumbnailPath);
$this->applyAlterations($newPath, $setting);
}else{
$newPath = Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->path($newThumbnailPath);
$this->applyAlterations($newPath, $setting);
}

$newPath = Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->path($newThumbnailPath);
$this->applyAlterations($newPath, $setting);
$generatedThumbnails[] = Storage::disk(config('nova-editor-js.toolSettings.image.disk') )->url($newThumbnailPath);

$generatedThumbnails[] = Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->url($newThumbnailPath);
// Storage::disk('local')->delete($path, $newThumbnailPath);
}
}

return $generatedThumbnails;
}


private function deleteThumbnails($path)
{
$thumbnailSettings = config('nova-editor-js.toolSettings.image.thumbnails');

if (!empty($thumbnailSettings)) {
foreach ($thumbnailSettings as $thumbnailName => $setting) {
$filename = pathinfo($path, PATHINFO_FILENAME);
$extension = pathinfo($path, PATHINFO_EXTENSION);

$newThumbnailName = $filename . $thumbnailName . '.' . $extension;
$newThumbnailPath = config('nova-editor-js.toolSettings.image.path') . '/' . $newThumbnailName;

Storage::disk('local')->delete($path, $newThumbnailPath);
}
}

}




}

0 comments on commit 4c04a4b

Please sign in to comment.