Dan Brown

Improved image upload error handling and fixed bad user-avatar rewriting

1 +<?php namespace BookStack\Exceptions;
2 +
3 +
4 +use Exception;
5 +
6 +class ImageUploadException extends Exception {}
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
2 2
3 namespace BookStack\Http\Controllers; 3 namespace BookStack\Http\Controllers;
4 4
5 +use BookStack\Exceptions\ImageUploadException;
5 use BookStack\Repos\ImageRepo; 6 use BookStack\Repos\ImageRepo;
6 use Illuminate\Filesystem\Filesystem as File; 7 use Illuminate\Filesystem\Filesystem as File;
7 use Illuminate\Http\Request; 8 use Illuminate\Http\Request;
...@@ -69,7 +70,13 @@ class ImageController extends Controller ...@@ -69,7 +70,13 @@ class ImageController extends Controller
69 ]); 70 ]);
70 71
71 $imageUpload = $request->file('file'); 72 $imageUpload = $request->file('file');
73 +
74 + try {
72 $image = $this->imageRepo->saveNew($imageUpload, $type); 75 $image = $this->imageRepo->saveNew($imageUpload, $type);
76 + } catch (ImageUploadException $e) {
77 + return response($e->getMessage(), 500);
78 + }
79 +
73 return response()->json($image); 80 return response()->json($image);
74 } 81 }
75 82
......
...@@ -56,6 +56,7 @@ module.exports = function (ngApp) { ...@@ -56,6 +56,7 @@ module.exports = function (ngApp) {
56 var usingIds = typeof scope.currentId !== 'undefined' || scope.currentId === 'false'; 56 var usingIds = typeof scope.currentId !== 'undefined' || scope.currentId === 'false';
57 scope.image = scope.currentImage; 57 scope.image = scope.currentImage;
58 scope.value = scope.currentImage || ''; 58 scope.value = scope.currentImage || '';
59 + if (usingIds) scope.value = scope.currentId;
59 60
60 function setImage(imageModel, imageUrl) { 61 function setImage(imageModel, imageUrl) {
61 scope.image = imageUrl; 62 scope.image = imageUrl;
......