From 8f9ae747c56a19a511832c7a282df01ef11ce828 Mon Sep 17 00:00:00 2001 From: "Jesus E. Franco Martinez" Date: Tue, 10 Aug 2021 20:15:53 -0500 Subject: [PATCH] Fix upstream #14 image deletion --- dist/js/field.js | 111 ++++++++++++++------------ resources/js/components/FormField.vue | 11 ++- routes/api.php | 3 +- src/FieldController.php | 11 ++- 4 files changed, 77 insertions(+), 59 deletions(-) diff --git a/dist/js/field.js b/dist/js/field.js index 59ed962..796beaa 100644 --- a/dist/js/field.js +++ b/dist/js/field.js @@ -543,9 +543,16 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); }); }, deleteImage: function deleteImage(index) { - axios.delete('/nova-vendor/array-images/delete/' + this.images[index].name); - this.images.splice(index, 1); - this.value = JSON.stringify(this.images); + var image = this.images[index] + var saved_path = image.saved_path + var params = { disk: this.field.disk } + + axios.delete('/nova-vendor/array-images/delete/' + encodeURIComponent(saved_path), { params }) + .then(() => { + this.images.splice(index, 1) + this.value = JSON.stringify(this.images) + }) + .catch(console.warn) }, @@ -3275,28 +3282,28 @@ process.umask = function() { return 0; }; /* 76 */ /***/ (function(module, exports) { -module.exports = function(module) { - if(!module.webpackPolyfill) { - module.deprecate = function() {}; - module.paths = []; - // module.parent = undefined by default - if(!module.children) module.children = []; - Object.defineProperty(module, "loaded", { - enumerable: true, - get: function() { - return module.l; - } - }); - Object.defineProperty(module, "id", { - enumerable: true, - get: function() { - return module.i; - } - }); - module.webpackPolyfill = 1; - } - return module; -}; +module.exports = function(module) { + if(!module.webpackPolyfill) { + module.deprecate = function() {}; + module.paths = []; + // module.parent = undefined by default + if(!module.children) module.children = []; + Object.defineProperty(module, "loaded", { + enumerable: true, + get: function() { + return module.l; + } + }); + Object.defineProperty(module, "id", { + enumerable: true, + get: function() { + return module.i; + } + }); + module.webpackPolyfill = 1; + } + return module; +}; /***/ }), @@ -4471,7 +4478,7 @@ function singularOrPlural(value, suffix) { /** * Javascript inflector - * + * * @author Dida Nurwanda * @since 1.0 */ @@ -4570,7 +4577,7 @@ var _Inflector = { Inflector.pluralize('person') -> 'people' Inflector.pluralize('octopus') -> 'octopi' Inflector.pluralize('Hat') -> 'Hats' - Inflector.pluralize('person', 'guys') -> 'guys' + Inflector.pluralize('person', 'guys') -> 'guys' */ pluralize: function(str, plural) { return this.applyRules( @@ -4591,7 +4598,7 @@ var _Inflector = { return this.applyRules( str, this.singularRules, - this.uncountableWords, + this.uncountableWords, singular ); }, @@ -4615,7 +4622,7 @@ var _Inflector = { } str = str_path.join('::'); - // fix + // fix if (lowFirstLetter === true) { var first = str.charAt(0).toLowerCase(); var last = str.slice(1); @@ -4629,7 +4636,7 @@ var _Inflector = { Inflector.underscore('MessageProperties') -> 'message_properties' Inflector.underscore('messageProperties') -> 'message_properties' */ - underscore: function(str) { + underscore: function(str) { var str_path = str.split('::'); for (var i = 0; i < str_path.length; i++) { @@ -4735,7 +4742,7 @@ var _Inflector = { /* Inflector.foreignKey('MessageBusProperty') -> 'message_bus_property_id' Inflector.foreignKey('MessageBusProperty', true) -> 'message_bus_propertyid' - */ + */ foreignKey: function(str, dropIdUbar) { str = this.underscore(this.demodulize(str)) + ((dropIdUbar) ? ('') : ('_')) + 'id'; return str; @@ -10756,27 +10763,27 @@ if (hadRuntime) { /* 241 */ /***/ (function(module, exports) { -var g; - -// This works in non-strict mode -g = (function() { - return this; -})(); - -try { - // This works if eval is allowed (see CSP) - g = g || Function("return this")() || (1,eval)("this"); -} catch(e) { - // This works if the window reference is available - if(typeof window === "object") - g = window; -} - -// g can still be undefined, but nothing to do about it... -// We return undefined, instead of nothing here, so it's -// easier to handle this case. if(!global) { ...} - -module.exports = g; +var g; + +// This works in non-strict mode +g = (function() { + return this; +})(); + +try { + // This works if eval is allowed (see CSP) + g = g || Function("return this")() || (1,eval)("this"); +} catch(e) { + // This works if the window reference is available + if(typeof window === "object") + g = window; +} + +// g can still be undefined, but nothing to do about it... +// We return undefined, instead of nothing here, so it's +// easier to handle this case. if(!global) { ...} + +module.exports = g; /***/ }) diff --git a/resources/js/components/FormField.vue b/resources/js/components/FormField.vue index ccc763f..481eea0 100755 --- a/resources/js/components/FormField.vue +++ b/resources/js/components/FormField.vue @@ -86,9 +86,14 @@ export default { }, deleteImage(index) { - axios.delete('/nova-vendor/array-images/delete/'+this.images[index].name); - this.images.splice(index, 1); - this.value = JSON.stringify(this.images); + const { saved_path } = this.images[index] + const params = { disk: this.field.disk } + axios.delete('/nova-vendor/array-images/delete/' + encodeURIComponent(saved_path), { params }) + .then(() => { + this.images.splice(index, 1); + this.value = JSON.stringify(this.images); + }) + .catch(console.warn) }, /* diff --git a/routes/api.php b/routes/api.php index bcd5b5e..c873e84 100755 --- a/routes/api.php +++ b/routes/api.php @@ -4,4 +4,5 @@ Route::get('/', 'Halimtuhu\ArrayImages\FieldController@index'); Route::post('/upload', 'Halimtuhu\ArrayImages\FieldController@upload'); -Route::delete('/delete/{image}', 'Halimtuhu\ArrayImages\FieldController@delete'); +Route::delete('/delete/{saved_path}', 'Halimtuhu\ArrayImages\FieldController@delete') + ->where('saved_path', '(.*)'); diff --git a/src/FieldController.php b/src/FieldController.php index 1c48145..1e7ac1c 100755 --- a/src/FieldController.php +++ b/src/FieldController.php @@ -27,6 +27,7 @@ public function upload(Request $request) $data[] = [ 'image' => $savedImage, + 'saved_path' => $savedImage, 'url' => Storage::disk($disk)->url($savedImage), ]; } @@ -34,10 +35,14 @@ public function upload(Request $request) return $data; } - public function delete($image) + public function delete(Request $request, $saved_path) { - Storage::delete($image); + $disk = $request->disk ? $request->disk : 'local'; + + $deleted = Storage::disk($disk)->delete($saved_path); - return "success"; + return $deleted === true + ? 'success' + : response('not deleted', 404); } }