10
10
11
11
class Wysiwyg extends Base
12
12
{
13
- public function upload (ImageManager $ intervention ): string
13
+ public function upload ()
14
14
{
15
- $ funcNum = $ this ->req ->get ('CKEditorFuncNum ' );
16
15
try {
17
16
$ this ->req ->validate (['upload ' => config ('api_admin.wysiwyg.image_upload_rules ' , 'image ' )]);
18
17
$ file = $ this ->req ->file ('upload ' );
@@ -27,14 +26,13 @@ public function upload(ImageManager $intervention): string
27
26
$ interventionImage ->fit ($ size [0 ], $ size [1 ] ?? null );
28
27
$ interventionImage ->save ($ target );
29
28
}
30
- return ' <script>window.parent.CKEDITOR.tools.callFunction( \'' . $ funcNum . '\' , \'' . $ image ->getPath () . '\' );</script> ' ;
29
+ return $ this -> jsonResponse ([ ' url ' => $ image ->getPath ()]) ;
31
30
} 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 ())]]);
34
32
} 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 ' )]]) ;
36
34
} 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 ' )]]) ;
38
36
}
39
37
}
40
38
0 commit comments