]> BookStack Code Mirror - bookstack/commitdiff
Improved image upload error handling and fixed bad user-avatar rewriting
authorDan Brown <redacted>
Sun, 17 Jan 2016 15:19:26 +0000 (15:19 +0000)
committerDan Brown <redacted>
Sun, 17 Jan 2016 15:19:26 +0000 (15:19 +0000)
app/Exceptions/ImageUploadException.php [new file with mode: 0644]
app/Http/Controllers/ImageController.php
resources/assets/js/directives.js

diff --git a/app/Exceptions/ImageUploadException.php b/app/Exceptions/ImageUploadException.php
new file mode 100644 (file)
index 0000000..205bdd4
--- /dev/null
@@ -0,0 +1,6 @@
+<?php namespace BookStack\Exceptions;
+
+
+use Exception;
+
+class ImageUploadException extends Exception {}
\ No newline at end of file
index 146dd0c05e8ef6988b13cf65ab833a607b24c120..3fff28d3ba493cd31ef4acc06ac32f91ab78ae11 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace BookStack\Http\Controllers;
 
+use BookStack\Exceptions\ImageUploadException;
 use BookStack\Repos\ImageRepo;
 use Illuminate\Filesystem\Filesystem as File;
 use Illuminate\Http\Request;
@@ -69,7 +70,13 @@ class ImageController extends Controller
         ]);
 
         $imageUpload = $request->file('file');
-        $image = $this->imageRepo->saveNew($imageUpload, $type);
+
+        try {
+            $image = $this->imageRepo->saveNew($imageUpload, $type);
+        } catch (ImageUploadException $e) {
+            return response($e->getMessage(), 500);
+        }
+
         return response()->json($image);
     }
 
index 758f16cd2c5fdc75c4481cdf449e53f795c46572..6ccfcf8558cf4c74c9b269c44c33d4ab26b0679e 100644 (file)
@@ -56,6 +56,7 @@ module.exports = function (ngApp) {
                 var usingIds = typeof scope.currentId !== 'undefined' || scope.currentId === 'false';
                 scope.image = scope.currentImage;
                 scope.value = scope.currentImage || '';
+                if (usingIds) scope.value = scope.currentId;
 
                 function setImage(imageModel, imageUrl) {
                     scope.image = imageUrl;