1010
1111class Wysiwyg extends Base
1212{
13- public function upload (ImageManager $ intervention ): string
13+ public function upload ()
1414 {
15- $ funcNum = $ this ->req ->get ('CKEditorFuncNum ' );
1615 try {
1716 $ this ->req ->validate (['upload ' => config ('api_admin.wysiwyg.image_upload_rules ' , 'image ' )]);
1817 $ file = $ this ->req ->file ('upload ' );
@@ -27,14 +26,13 @@ public function upload(ImageManager $intervention): string
2726 $ interventionImage ->fit ($ size [0 ], $ size [1 ] ?? null );
2827 $ interventionImage ->save ($ target );
2928 }
30- return ' <script>window.parent.CKEDITOR.tools.callFunction( \'' . $ funcNum . '\' , \'' . $ image ->getPath () . '\' );</script> ' ;
29+ return $ this -> jsonResponse ([ ' url ' => $ image ->getPath ()]) ;
3130 } catch (ValidationException $ e ) {
32- return '<script>window.parent.CKEDITOR.tools.callFunction( \'' . $ funcNum . '\', null, ' .
33- json_encode (implode (', ' , $ e ->errors ())) . ');</script> ' ;
31+ return $ this ->jsonResponse (['error ' => ['message ' => implode (', ' , $ e ->errors ())]]);
3432 } catch (FileException $ e ) {
35- return ' <script>window.parent.CKEDITOR.tools.callFunction( \'' . $ funcNum . '\' , null, \' Could not upload image... \' );</script> ' ;
33+ return $ this -> jsonResponse ([ ' error ' => [ ' message ' => trans ( ' admin_api::messaages.wysiwyg_upload_file_error ' )]]) ;
3634 } catch (\Throwable $ e ) {
37- return ' <script>window.parent.CKEDITOR.tools.callFunction( \'' . $ funcNum . '\' , null, \' Something went wrong... \' );</script> ' ;
35+ return $ this -> jsonResponse ([ ' error ' => [ ' message ' => trans ( ' admin_api::messaages.wysiwyg_upload_server_error ' )]]) ;
3836 }
3937 }
4038
0 commit comments