← All changes
|
app/src/Controllers/Ajax/MediaLibraryAjaxController.php
+15
-31
1.3.5
→
1.9.2
View file →
| @@ -105,43 +105,27 @@ | ||
| 105 | 105 | |
| 106 | 106 | // change "images" to "image" for accurate mime_type |
| 107 | 107 | $assetType = rtrim( $assetType, 's' ); |
| 108 | 108 | |
| 109 | - $mimTypes = [ | |
| 110 | - 'image' => ['image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/tiff', 'image/x-icon'], | |
| 111 | - 'photo' => ['image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/tiff', 'image/x-icon'], | |
| 112 | - 'video' => 'video', | |
| 113 | - 'audio' => 'audio', | |
| 114 | - 'vector' => 'image/svg+xml' | |
| 115 | - ]; | |
| 109 | + if( $mimTypes = $this->mediaLibraryService->getSupportedMimeTypes( $assetType ) ){ | |
| 110 | + $queryParams['post_mime_type'] = $mimTypes; | |
| 111 | + } | |
| 116 | 112 | |
| 117 | - if( in_array( $assetType, array_keys( $mimTypes ) ) ){ | |
| 118 | - $queryParams['post_mime_type'] = $mimTypes[ $assetType ]; | |
| 113 | + $attachments = $this->mediaLibraryService->query( $queryParams ); | |
| 114 | + $result = $this->mediaLibraryService->getQueryOutput( $attachments, $assetType ); | |
| 115 | + if( empty( $result ) ){ | |
| 116 | + return \Depicter::json(['errors' => ['Search not found.'] ])->withStatus(404); | |
| 119 | 117 | } |
| 120 | 118 | |
| 119 | + $totalPages = $result['totalPages']; | |
| 120 | + unset( $result['totalPages'] ); | |
| 121 | 121 | |
| 122 | - $attachments = $this->mediaLibraryService->query( $queryParams ); | |
| 123 | - $result = $this->mediaLibraryService->getQueryOutput( $attachments, $assetType ); | |
| 124 | - if( empty( $result ) ){ | |
| 125 | - return \Depicter::json(['errors' => ['Search not found.'] ])->withStatus(404); | |
| 126 | - } | |
| 122 | + $total = $result['total']; | |
| 123 | + unset( $result['total'] ); | |
| 127 | 124 | |
| 128 | - $totalPages = $result['totalPages']; | |
| 129 | - unset( $result['totalPages'] ); | |
| 130 | - | |
| 131 | - $total = $result['total']; | |
| 132 | - unset( $result['total'] ); | |
| 133 | - | |
| 134 | - return \Depicter::json( $result ) | |
| 135 | - ->withHeader('X-Total-Pages', $totalPages ) | |
| 136 | - ->withHeader('X-Total', $total ) | |
| 137 | - ->withStatus(200 ); | |
| 138 | -try { | |
| 139 | - } catch ( \Exception $exception ){ | |
| 140 | - return \Depicter::json([ | |
| 141 | - 'errors' => [ $exception->getMessage() . 'jjjj' ] | |
| 142 | - ]); | |
| 143 | - } | |
| 144 | - | |
| 125 | + return \Depicter::json( $result ) | |
| 126 | + ->withHeader('X-Total-Pages', $totalPages ) | |
| 127 | + ->withHeader('X-Total', $total ) | |
| 128 | + ->withStatus(200 ); | |
| 145 | 129 | } |
| 146 | 130 | |
| 147 | 131 | } |