@@ -34,8 +34,22 @@ public function file(NovaRequest $request)
3434 config ('nova-editor-js.toolSettings.image.disk ' )
3535 );
3636
37- $ this ->applyAlterations (Storage::disk (config ('nova-editor-js.toolSettings.image.disk ' ))->path ($ path ));
38- $ thumbnails = $ this ->applyThumbnails ($ path );
37+ if (config ('nova-editor-js.toolSettings.image.disk ' ) !== 'local ' ) {
38+
39+ $ tempPath = $ request ->file ('image ' )->store (
40+ config ('nova-editor-js.toolSettings.image.path ' ),
41+ 'local '
42+ );
43+
44+ $ this ->applyAlterations (Storage::disk ('local ' )->path ($ tempPath ));
45+ $ thumbnails = $ this ->applyThumbnails ($ tempPath );
46+
47+ $ this ->deleteThumbnails (Storage::disk ('local ' )->path ($ tempPath ));
48+ Storage::disk ('local ' )->delete ($ path );
49+ } else {
50+ $ this ->applyAlterations (Storage::disk (config ('nova-editor-js.toolSettings.image.disk ' ))->path ($ path ));
51+ $ thumbnails = $ this ->applyThumbnails ($ path );
52+ }
3953
4054 return [
4155 'success ' => 1 ,
@@ -108,7 +122,7 @@ private function applyAlterations($path, $alterations = [])
108122 $ imageSettings = $ alterations ;
109123 }
110124
111- if (empty ($ imageSettings ))
125+ if (empty ($ imageSettings ))
112126 return ;
113127
114128 if (!empty ($ imageSettings ['resize ' ]['width ' ])) {
@@ -181,7 +195,13 @@ private function applyThumbnails($path)
181195
182196 Storage::disk (config ('nova-editor-js.toolSettings.image.disk ' ))->copy ($ path , $ newThumbnailPath );
183197
184- $ newPath = Storage::disk (config ('nova-editor-js.toolSettings.image.disk ' ))->path ($ newThumbnailPath );
198+ if (config ('nova-editor-js.toolSettings.image.disk ' ) !== 'local ' ) {
199+ Storage::disk ('local ' )->copy ($ path , $ newThumbnailPath );
200+ $ newPath = Storage::disk ('local ' )->path ($ newThumbnailPath );
201+ } else {
202+ $ newPath = Storage::disk (config ('nova-editor-js.toolSettings.image.disk ' ))->path ($ newThumbnailPath );
203+ }
204+
185205 $ this ->applyAlterations ($ newPath , $ setting );
186206
187207 $ generatedThumbnails [] = Storage::disk (config ('nova-editor-js.toolSettings.image.disk ' ))->url ($ newThumbnailPath );
@@ -190,4 +210,25 @@ private function applyThumbnails($path)
190210
191211 return $ generatedThumbnails ;
192212 }
213+
214+
215+ /**
216+ * @param $path
217+ */
218+ private function deleteThumbnails ($ path )
219+ {
220+ $ thumbnailSettings = config ('nova-editor-js.toolSettings.image.thumbnails ' );
221+
222+ if (!empty ($ thumbnailSettings )) {
223+ foreach ($ thumbnailSettings as $ thumbnailName => $ setting ) {
224+ $ filename = pathinfo ($ path , PATHINFO_FILENAME );
225+ $ extension = pathinfo ($ path , PATHINFO_EXTENSION );
226+
227+ $ newThumbnailName = $ filename . $ thumbnailName . '. ' . $ extension ;
228+ $ newThumbnailPath = config ('nova-editor-js.toolSettings.image.path ' ) . '/ ' . $ newThumbnailName ;
229+
230+ Storage::disk ('local ' )->delete ($ path , $ newThumbnailPath );
231+ }
232+ }
233+ }
193234}
0 commit comments