Skip to content

Commit

Permalink
Merge pull request #48 from advoor/s3-fix
Browse files Browse the repository at this point in the history
S3 fix
  • Loading branch information
advoor authored Nov 28, 2020
2 parents 70f48f6 + 2368f01 commit 828ddef
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions dist/js/field.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @license
* Lodash <https://lodash.com/>
* Copyright JS Foundation and other contributors <https://js.foundation/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
Expand Down Expand Up @@ -87,8 +87,7 @@
/**
* Raw HTML Tool for CodeX Editor
*
* @author CodeX (team@ifmo.su)
* @author CodeX (team@codex.so)
* @copyright CodeX 2018
* @license The MIT License (MIT)
* @version 2.0.0
*/
6 changes: 6 additions & 0 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
* Initial Editor data
*/
data: currentContent,
/**
* Min height of editor
*/
minHeight: 35,
onReady: function () {
},
Expand Down
49 changes: 45 additions & 4 deletions src/Http/Controllers/EditorJsImageUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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 @@ -108,7 +122,7 @@ private function applyAlterations($path, $alterations = [])
$imageSettings = $alterations;
}

if(empty($imageSettings))
if (empty($imageSettings))
return;

if (!empty($imageSettings['resize']['width'])) {
Expand Down Expand Up @@ -181,7 +195,13 @@ private function applyThumbnails($path)

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

$newPath = Storage::disk(config('nova-editor-js.toolSettings.image.disk'))->path($newThumbnailPath);
if (config('nova-editor-js.toolSettings.image.disk') !== 'local') {
Storage::disk('local')->copy($path, $newThumbnailPath);
$newPath = Storage::disk('local')->path($newThumbnailPath);
} else {
$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);
Expand All @@ -190,4 +210,25 @@ private function applyThumbnails($path)

return $generatedThumbnails;
}


/**
* @param $path
*/
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 828ddef

Please sign in to comment.