Fixed attachment base-url usage and non-existant images
Images now self-delete if the original file does not exist. Prevents simply getting non-fixable errors. Also cleaned some JS.
Showing
5 changed files
with
31 additions
and
24 deletions
| ... | @@ -5,6 +5,7 @@ use BookStack\Image; | ... | @@ -5,6 +5,7 @@ use BookStack\Image; |
| 5 | use BookStack\Page; | 5 | use BookStack\Page; |
| 6 | use BookStack\Services\ImageService; | 6 | use BookStack\Services\ImageService; |
| 7 | use BookStack\Services\PermissionService; | 7 | use BookStack\Services\PermissionService; |
| 8 | +use Illuminate\Contracts\Filesystem\FileNotFoundException; | ||
| 8 | use Setting; | 9 | use Setting; |
| 9 | use Symfony\Component\HttpFoundation\File\UploadedFile; | 10 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
| 10 | 11 | ||
| ... | @@ -191,7 +192,12 @@ class ImageRepo | ... | @@ -191,7 +192,12 @@ class ImageRepo |
| 191 | */ | 192 | */ |
| 192 | public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false) | 193 | public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false) |
| 193 | { | 194 | { |
| 195 | + try { | ||
| 194 | return $this->imageService->getThumbnail($image, $width, $height, $keepRatio); | 196 | return $this->imageService->getThumbnail($image, $width, $height, $keepRatio); |
| 197 | + } catch (FileNotFoundException $exception) { | ||
| 198 | + $image->delete(); | ||
| 199 | + return []; | ||
| 200 | + } | ||
| 195 | } | 201 | } |
| 196 | 202 | ||
| 197 | 203 | ... | ... |
| ... | @@ -60,7 +60,7 @@ class PageRepo extends EntityRepo | ... | @@ -60,7 +60,7 @@ class PageRepo extends EntityRepo |
| 60 | * Get a page identified by the given slug. | 60 | * Get a page identified by the given slug. |
| 61 | * @param $slug | 61 | * @param $slug |
| 62 | * @param $bookId | 62 | * @param $bookId |
| 63 | - * @return mixed | 63 | + * @return Page |
| 64 | * @throws NotFoundException | 64 | * @throws NotFoundException |
| 65 | */ | 65 | */ |
| 66 | public function getBySlug($slug, $bookId) | 66 | public function getBySlug($slug, $bookId) | ... | ... |
| ... | @@ -4,7 +4,7 @@ import moment from 'moment'; | ... | @@ -4,7 +4,7 @@ import moment from 'moment'; |
| 4 | import 'moment/locale/en-gb'; | 4 | import 'moment/locale/en-gb'; |
| 5 | moment.locale('en-gb'); | 5 | moment.locale('en-gb'); |
| 6 | 6 | ||
| 7 | -module.exports = function (ngApp, events) { | 7 | +export default function (ngApp, events) { |
| 8 | 8 | ||
| 9 | ngApp.controller('ImageManagerController', ['$scope', '$attrs', '$http', '$timeout', 'imageManagerService', | 9 | ngApp.controller('ImageManagerController', ['$scope', '$attrs', '$http', '$timeout', 'imageManagerService', |
| 10 | function ($scope, $attrs, $http, $timeout, imageManagerService) { | 10 | function ($scope, $attrs, $http, $timeout, imageManagerService) { |
| ... | @@ -164,7 +164,6 @@ module.exports = function (ngApp, events) { | ... | @@ -164,7 +164,6 @@ module.exports = function (ngApp, events) { |
| 164 | 164 | ||
| 165 | /** | 165 | /** |
| 166 | * Start a search operation | 166 | * Start a search operation |
| 167 | - * @param searchTerm | ||
| 168 | */ | 167 | */ |
| 169 | $scope.searchImages = function() { | 168 | $scope.searchImages = function() { |
| 170 | 169 | ||
| ... | @@ -198,7 +197,7 @@ module.exports = function (ngApp, events) { | ... | @@ -198,7 +197,7 @@ module.exports = function (ngApp, events) { |
| 198 | $scope.view = viewName; | 197 | $scope.view = viewName; |
| 199 | baseUrl = window.baseUrl('/images/' + $scope.imageType + '/' + viewName + '/'); | 198 | baseUrl = window.baseUrl('/images/' + $scope.imageType + '/' + viewName + '/'); |
| 200 | fetchData(); | 199 | fetchData(); |
| 201 | - } | 200 | + }; |
| 202 | 201 | ||
| 203 | /** | 202 | /** |
| 204 | * Save the details of an image. | 203 | * Save the details of an image. |
| ... | @@ -207,7 +206,7 @@ module.exports = function (ngApp, events) { | ... | @@ -207,7 +206,7 @@ module.exports = function (ngApp, events) { |
| 207 | $scope.saveImageDetails = function (event) { | 206 | $scope.saveImageDetails = function (event) { |
| 208 | event.preventDefault(); | 207 | event.preventDefault(); |
| 209 | var url = window.baseUrl('/images/update/' + $scope.selectedImage.id); | 208 | var url = window.baseUrl('/images/update/' + $scope.selectedImage.id); |
| 210 | - $http.put(url, this.selectedImage).then((response) => { | 209 | + $http.put(url, this.selectedImage).then(response => { |
| 211 | events.emit('success', 'Image details updated'); | 210 | events.emit('success', 'Image details updated'); |
| 212 | }, (response) => { | 211 | }, (response) => { |
| 213 | if (response.status === 422) { | 212 | if (response.status === 422) { |
| ... | @@ -306,12 +305,12 @@ module.exports = function (ngApp, events) { | ... | @@ -306,12 +305,12 @@ module.exports = function (ngApp, events) { |
| 306 | $scope.isUpdateDraft = Number($attrs.pageUpdateDraft) === 1; | 305 | $scope.isUpdateDraft = Number($attrs.pageUpdateDraft) === 1; |
| 307 | $scope.isNewPageDraft = Number($attrs.pageNewDraft) === 1; | 306 | $scope.isNewPageDraft = Number($attrs.pageNewDraft) === 1; |
| 308 | 307 | ||
| 309 | - // Set inital header draft text | 308 | + // Set initial header draft text |
| 310 | if ($scope.isUpdateDraft || $scope.isNewPageDraft) { | 309 | if ($scope.isUpdateDraft || $scope.isNewPageDraft) { |
| 311 | $scope.draftText = 'Editing Draft' | 310 | $scope.draftText = 'Editing Draft' |
| 312 | } else { | 311 | } else { |
| 313 | $scope.draftText = 'Editing Page' | 312 | $scope.draftText = 'Editing Page' |
| 314 | - }; | 313 | + } |
| 315 | 314 | ||
| 316 | var autoSave = false; | 315 | var autoSave = false; |
| 317 | 316 | ||
| ... | @@ -571,7 +570,7 @@ module.exports = function (ngApp, events) { | ... | @@ -571,7 +570,7 @@ module.exports = function (ngApp, events) { |
| 571 | if (newOrder === currentOrder) return; | 570 | if (newOrder === currentOrder) return; |
| 572 | 571 | ||
| 573 | currentOrder = newOrder; | 572 | currentOrder = newOrder; |
| 574 | - $http.put(`/files/sort/page/${pageId}`, {files: $scope.files}).then(resp => { | 573 | + $http.put(window.baseUrl(`/files/sort/page/${pageId}`), {files: $scope.files}).then(resp => { |
| 575 | events.emit('success', resp.data.message); | 574 | events.emit('success', resp.data.message); |
| 576 | }, checkError('sort')); | 575 | }, checkError('sort')); |
| 577 | } | 576 | } |
| ... | @@ -637,7 +636,7 @@ module.exports = function (ngApp, events) { | ... | @@ -637,7 +636,7 @@ module.exports = function (ngApp, events) { |
| 637 | file.deleting = true; | 636 | file.deleting = true; |
| 638 | return; | 637 | return; |
| 639 | } | 638 | } |
| 640 | - $http.delete(`/files/${file.id}`).then(resp => { | 639 | + $http.delete(window.baseUrl(`/files/${file.id}`)).then(resp => { |
| 641 | events.emit('success', resp.data.message); | 640 | events.emit('success', resp.data.message); |
| 642 | $scope.files.splice($scope.files.indexOf(file), 1); | 641 | $scope.files.splice($scope.files.indexOf(file), 1); |
| 643 | }, checkError('delete')); | 642 | }, checkError('delete')); |
| ... | @@ -645,12 +644,11 @@ module.exports = function (ngApp, events) { | ... | @@ -645,12 +644,11 @@ module.exports = function (ngApp, events) { |
| 645 | 644 | ||
| 646 | /** | 645 | /** |
| 647 | * Attach a link to a page. | 646 | * Attach a link to a page. |
| 648 | - * @param fileName | 647 | + * @param file |
| 649 | - * @param fileLink | ||
| 650 | */ | 648 | */ |
| 651 | $scope.attachLinkSubmit = function(file) { | 649 | $scope.attachLinkSubmit = function(file) { |
| 652 | file.uploaded_to = pageId; | 650 | file.uploaded_to = pageId; |
| 653 | - $http.post('/files/link', file).then(resp => { | 651 | + $http.post(window.baseUrl('/files/link'), file).then(resp => { |
| 654 | $scope.files.push(resp.data); | 652 | $scope.files.push(resp.data); |
| 655 | events.emit('success', 'Link attached'); | 653 | events.emit('success', 'Link attached'); |
| 656 | $scope.file = getCleanFile(); | 654 | $scope.file = getCleanFile(); |
| ... | @@ -659,10 +657,9 @@ module.exports = function (ngApp, events) { | ... | @@ -659,10 +657,9 @@ module.exports = function (ngApp, events) { |
| 659 | 657 | ||
| 660 | /** | 658 | /** |
| 661 | * Start the edit mode for a file. | 659 | * Start the edit mode for a file. |
| 662 | - * @param fileId | 660 | + * @param file |
| 663 | */ | 661 | */ |
| 664 | $scope.startEdit = function(file) { | 662 | $scope.startEdit = function(file) { |
| 665 | - console.log(file); | ||
| 666 | $scope.editFile = angular.copy(file); | 663 | $scope.editFile = angular.copy(file); |
| 667 | $scope.editFile.link = (file.external) ? file.path : ''; | 664 | $scope.editFile.link = (file.external) ? file.path : ''; |
| 668 | }; | 665 | }; |
| ... | @@ -679,7 +676,7 @@ module.exports = function (ngApp, events) { | ... | @@ -679,7 +676,7 @@ module.exports = function (ngApp, events) { |
| 679 | * @param file | 676 | * @param file |
| 680 | */ | 677 | */ |
| 681 | $scope.updateFile = function(file) { | 678 | $scope.updateFile = function(file) { |
| 682 | - $http.put(`/files/${file.id}`, file).then(resp => { | 679 | + $http.put(window.baseUrl(`/files/${file.id}`), file).then(resp => { |
| 683 | let search = filesIndexOf(resp.data); | 680 | let search = filesIndexOf(resp.data); |
| 684 | if (search !== -1) $scope.files[search] = resp.data; | 681 | if (search !== -1) $scope.files[search] = resp.data; |
| 685 | 682 | ||
| ... | @@ -696,7 +693,7 @@ module.exports = function (ngApp, events) { | ... | @@ -696,7 +693,7 @@ module.exports = function (ngApp, events) { |
| 696 | */ | 693 | */ |
| 697 | $scope.getFileUrl = function(file) { | 694 | $scope.getFileUrl = function(file) { |
| 698 | return window.baseUrl('/files/' + file.id); | 695 | return window.baseUrl('/files/' + file.id); |
| 699 | - } | 696 | + }; |
| 700 | 697 | ||
| 701 | /** | 698 | /** |
| 702 | * Search the local files via another file object. | 699 | * Search the local files via another file object. |
| ... | @@ -713,7 +710,7 @@ module.exports = function (ngApp, events) { | ... | @@ -713,7 +710,7 @@ module.exports = function (ngApp, events) { |
| 713 | 710 | ||
| 714 | /** | 711 | /** |
| 715 | * Check for an error response in a ajax request. | 712 | * Check for an error response in a ajax request. |
| 716 | - * @param response | 713 | + * @param errorGroupName |
| 717 | */ | 714 | */ |
| 718 | function checkError(errorGroupName) { | 715 | function checkError(errorGroupName) { |
| 719 | $scope.errors[errorGroupName] = {}; | 716 | $scope.errors[errorGroupName] = {}; | ... | ... |
| ... | @@ -38,13 +38,17 @@ class EventManager { | ... | @@ -38,13 +38,17 @@ class EventManager { |
| 38 | this.listeners[eventName].push(callback); | 38 | this.listeners[eventName].push(callback); |
| 39 | return this; | 39 | return this; |
| 40 | } | 40 | } |
| 41 | -}; | 41 | +} |
| 42 | -window.Events = new EventManager(); | ||
| 43 | 42 | ||
| 43 | +window.Events = new EventManager(); | ||
| 44 | 44 | ||
| 45 | -var services = require('./services')(ngApp, window.Events); | 45 | +// Load in angular specific items |
| 46 | -var directives = require('./directives')(ngApp, window.Events); | 46 | +import Services from './services'; |
| 47 | -var controllers = require('./controllers')(ngApp, window.Events); | 47 | +import Directives from './directives'; |
| 48 | +import Controllers from './controllers'; | ||
| 49 | +Services(ngApp, window.Events); | ||
| 50 | +Directives(ngApp, window.Events); | ||
| 51 | +Controllers(ngApp, window.Events); | ||
| 48 | 52 | ||
| 49 | //Global jQuery Config & Extensions | 53 | //Global jQuery Config & Extensions |
| 50 | 54 | ... | ... |
| ... | @@ -6,11 +6,11 @@ | ... | @@ -6,11 +6,11 @@ |
| 6 | * @param editor - editor instance | 6 | * @param editor - editor instance |
| 7 | */ | 7 | */ |
| 8 | function editorPaste(e, editor) { | 8 | function editorPaste(e, editor) { |
| 9 | - if (!e.clipboardData) return | 9 | + if (!e.clipboardData) return; |
| 10 | let items = e.clipboardData.items; | 10 | let items = e.clipboardData.items; |
| 11 | if (!items) return; | 11 | if (!items) return; |
| 12 | for (let i = 0; i < items.length; i++) { | 12 | for (let i = 0; i < items.length; i++) { |
| 13 | - if (items[i].type.indexOf("image") === -1) return | 13 | + if (items[i].type.indexOf("image") === -1) return; |
| 14 | 14 | ||
| 15 | let file = items[i].getAsFile(); | 15 | let file = items[i].getAsFile(); |
| 16 | let formData = new FormData(); | 16 | let formData = new FormData(); | ... | ... |
-
Please register or sign in to post a comment