diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index b3c91cafc1..71741bb6ad 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -9,10 +9,12 @@ use App\Notifications\MailTest; use App\Services\LdapAd; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; use GuzzleHttp\Client; +use Illuminate\Support\Facades\Storage; class SettingsController extends Controller { @@ -143,6 +145,51 @@ class SettingsController extends Controller } + + /** + * Delete server-cached barcodes + * + * @author [A. Gianotto] [] + * @since [v5.0.0] + * @return Response + */ + public function purgeBarcodes() + { + + $file_count = 0; + $files = Storage::disk('public')->files('barcodes'); + + foreach ($files as $file) { // iterate files + + $file_parts = explode(".", $file); + $extension = end($file_parts); + \Log::debug($extension); + + // Only generated barcodes would have a .png file extension + if ($extension =='png') { + + \Log::debug('Deleting: '.$file); + + + try { + Storage::disk('public')->delete($file); + \Log::debug('Deleting: '.$file); + $file_count++; + } catch (\Exception $e) { + \Log::debug($e); + } + } + + } + + return response()->json(['message' => 'Deleted '.$file_count.' barcodes'], 200); + + } + + + + + /** * Get a list of login attempts * diff --git a/resources/views/settings/barcodes.blade.php b/resources/views/settings/barcodes.blade.php index 9bd6be17d0..892389574f 100644 --- a/resources/views/settings/barcodes.blade.php +++ b/resources/views/settings/barcodes.blade.php @@ -58,7 +58,7 @@ {{ Form::label('barcode_type', trans('admin/settings/general.barcode_type')) }}
- {!! Form::barcode_types('barcode_type', old('barcode_type', $setting->barcode_type), 'select2') !!} + {!! Form::barcode_types('barcode_type', old('barcode_type', $setting->barcode_type), 'select2 col-md-4') !!} {!! $errors->first('barcode_type', '') !!}
@@ -80,13 +80,13 @@ {{ Form::label('alt_barcode', trans('admin/settings/general.alt_barcode_type')) }}
- {!! Form::alt_barcode_types('alt_barcode', old('alt_barcode', $setting->alt_barcode), 'select2') !!} + {!! Form::alt_barcode_types('alt_barcode', old('alt_barcode', $setting->alt_barcode), 'select2 col-md-4') !!} {!! $errors->first('barcode_type', '') !!}
@else - {{ trans('admin/settings/general.php_gd_warning') }} + {{ trans('admin/settings/general.php_gd_warning') }}
{{ trans('admin/settings/general.php_gd_info') }}
@@ -112,6 +112,27 @@ + +
+
+ {{ Form::label('purge_barcodes', 'Purge Barcodes') }} +
+ +
+
+
+
+

This will attempt to delete cached barcodes. This would typically only be used if your barcode dettings have changed, or if your Snipe-IT URL has changed. Barcodes will be re-generated when accessed next.

+
+ +
+ @@ -132,3 +153,61 @@ {{Form::close()}} @stop + +@push('js') + + + +@endpush diff --git a/routes/api.php b/routes/api.php index ee5fe63191..e631b98352 100644 --- a/routes/api.php +++ b/routes/api.php @@ -635,6 +635,11 @@ Route::group(['prefix' => 'v1','namespace' => 'Api', 'middleware' => 'auth:api'] 'uses' => 'SettingsController@ldapAdSettingsTest' ]); + Route::post('settings/purge_barcodes', [ + 'as' => 'api.settings.purgebarcodes', + 'uses' => 'SettingsController@purgeBarcodes' + ]); + Route::get('settings/login-attempts', [ 'middleware' => ['auth', 'authorize:superuser'], 'as' => 'api.settings.login_attempts',