mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-06 12:02:45 +03:00
Added mulit image-type compatability to manager & app and added scaled image selection
This commit is contained in:
@@ -33,23 +33,24 @@ class ImageController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* Get all images, Paginated
|
||||
* Get all gallery images, Paginated
|
||||
* @param int $page
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getAllGallery($page = 0)
|
||||
public function getAllByType($type, $page = 0)
|
||||
{
|
||||
$imgData = $this->imageRepo->getAllGallery($page);
|
||||
$imgData = $this->imageRepo->getPaginatedByType($type, $page);
|
||||
return response()->json($imgData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles image uploads for use on pages.
|
||||
* @param string $type
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function uploadGallery(Request $request)
|
||||
public function uploadByType($type, Request $request)
|
||||
{
|
||||
$this->checkPermission('image-create');
|
||||
$this->validate($request, [
|
||||
@@ -57,10 +58,25 @@ class ImageController extends Controller
|
||||
]);
|
||||
|
||||
$imageUpload = $request->file('file');
|
||||
$image = $this->imageRepo->saveNew($imageUpload, 'gallery');
|
||||
$image = $this->imageRepo->saveNew($imageUpload, $type);
|
||||
return response()->json($image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a sized thumbnail for an image.
|
||||
* @param $id
|
||||
* @param $width
|
||||
* @param $height
|
||||
* @param $crop
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getThumbnail($id, $width, $height, $crop)
|
||||
{
|
||||
$this->checkPermission('image-create');
|
||||
$image = $this->imageRepo->getById($id);
|
||||
$thumbnailUrl = $this->imageRepo->getThumbnail($image, $width, $height, $crop == 'false');
|
||||
return response()->json(['url' => $thumbnailUrl]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update image details
|
||||
|
@@ -18,7 +18,8 @@ class UserController extends Controller
|
||||
|
||||
/**
|
||||
* UserController constructor.
|
||||
* @param $user
|
||||
* @param User $user
|
||||
* @param UserRepo $userRepo
|
||||
*/
|
||||
public function __construct(User $user, UserRepo $userRepo)
|
||||
{
|
||||
|
@@ -57,10 +57,12 @@ Route::group(['middleware' => 'auth'], function () {
|
||||
|
||||
// Image routes
|
||||
Route::group(['prefix' => 'images'], function() {
|
||||
Route::get('/gallery/all', 'ImageController@getAllGallery');
|
||||
Route::get('/gallery/all/{page}', 'ImageController@getAllGallery');
|
||||
Route::post('/gallery/upload', 'ImageController@uploadGallery');
|
||||
// Standard get, update and deletion for all types
|
||||
Route::get('/thumb/{id}/{width}/{height}/{crop}', 'ImageController@getThumbnail');
|
||||
Route::put('/update/{imageId}', 'ImageController@update');
|
||||
Route::post('/{type}/upload', 'ImageController@uploadByType');
|
||||
Route::get('/{type}/all', 'ImageController@getAllByType');
|
||||
Route::get('/{type}/all/{page}', 'ImageController@getAllByType');
|
||||
Route::delete('/{imageId}', 'ImageController@destroy');
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user