Misc fixes for flysystem paths

This commit is contained in:
snipe 2020-06-16 16:06:25 -07:00
parent 1267c68f28
commit a7eb89f6b6
No known key found for this signature in database
GPG key ID: 10BFFDA3ED34B5AC
7 changed files with 22 additions and 15 deletions

View file

@ -79,7 +79,7 @@ class AccessoriesController extends Controller
$accessory->user_id = Auth::user()->id;
$accessory->supplier_id = request('supplier_id');
$accessory = $request->handleImages($accessory);
$accessory = $request->handleImages($accessory, 500, 'image', 'public/uploads');
// Was the accessory created?
if ($accessory->save()) {

View file

@ -107,6 +107,8 @@ class AssetsController extends Controller
// differently
$asset_tags = $request->input('asset_tags');
$settings = Setting::getSettings();
$success = false;
$serials = $request->input('serials');

View file

@ -45,11 +45,12 @@ class ImageUploadRequest extends Request
*/
public function handleImages($item, $w = 550, $fieldname = 'image', $path = null)
{
\Log::debug('Handle file upload');
$type = strtolower(class_basename(get_class($item)));
if (is_null($path)) {
$path = str_plural($type);
$path = 'public/uploads/'.str_plural($type);
\Log::info('Path is: '.$path);
}
\Log::debug('Image path is: '.$path);
@ -62,22 +63,26 @@ class ImageUploadRequest extends Request
if (!config('app.lock_passwords')) {
if (!Storage::disk('public')->exists($path)) Storage::disk('public')->makeDirectory($path, 775);
if (!Storage::disk('public')->exists($path))
{
\Log::debug($path);
// Storage::disk('public')->makeDirectory($path, 775);
}
if (!is_dir($path)) {
\Log::debug($path.' does not exist');
mkdir($path);
\Log::info($path.' does not exist');
//mkdir($path);
}
$image = $this->file($fieldname);
$ext = $image->getClientOriginalExtension();
$file_name = $type.'-'.str_random(18).'.'.$ext;
\Log::debug('File name will be: '.$file_name);
\Log::info('File name will be: '.$file_name);
if ($image->getClientOriginalExtension()!=='svg') {
\Log::debug('Not an SVG - resize');
\Log::debug('Trying to upload to: '.$path.'/'.$file_name);
\Log::info('Not an SVG - resize');
\Log::info('Trying to upload to: '.$path.'/'.$file_name);
$upload = Image::make($image->getRealPath())->resize(null, $w, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
@ -88,13 +93,13 @@ class ImageUploadRequest extends Request
// If the file is an SVG, we need to clean it and NOT encode it
} else {
\Log::debug('This is an SVG');
\Log::info('This is an SVG');
$sanitizer = new Sanitizer();
$dirtySVG = file_get_contents($image->getRealPath());
$cleanSVG = $sanitizer->sanitize($dirtySVG);
try {
\Log::debug('Trying to upload to: '.$path.'/'.$file_name);
\Log::info('Trying to upload to: '.$path.'/'.$file_name);
Storage::disk('public')->put($path.'/'.$file_name, $cleanSVG);
} catch (\Exception $e) {
\Log::debug($e);

View file

@ -24,7 +24,7 @@ class AccessoriesTransformer
$array = [
'id' => $accessory->id,
'name' => e($accessory->name),
'image' => ($accessory->image) ? Storage::disk('public')->url('accessories/'.e($accessory->image)) : null,
'image' => ($accessory->image) ? Storage::disk('public')->url('uploads/accessories/'.e($accessory->image)) : null,
'company' => ($accessory->company) ? ['id' => $accessory->company->id,'name'=> e($accessory->company->name)] : null,
'manufacturer' => ($accessory->manufacturer) ? ['id' => $accessory->manufacturer->id,'name'=> e($accessory->manufacturer->name)] : null,
'supplier' => ($accessory->supplier) ? ['id' => $accessory->supplier->id,'name'=> e($accessory->supplier->name)] : null,

View file

@ -45,7 +45,7 @@ class SettingsServiceProvider extends ServiceProvider
});
\App::singleton('accessories_upload_path', function() {
return 'accessories/';
return 'public/uploads/accessories/';
});
\App::singleton('models_upload_path', function(){

View file

@ -35,7 +35,7 @@ class AssetSeeder extends Seeder
factory(Asset::class, 10)->states('ultrasharp')->create();
$del_files = Storage::files('companies');
$del_files = Storage::files('assets');
foreach($del_files as $del_file){ // iterate files
\Log::debug('Deleting: '.$del_files);
try {

View file

@ -29,7 +29,7 @@
<label class="col-md-3 control-label" for="image_delete">{{ trans('general.image_delete') }}</label>
<div class="col-md-5">
{{ Form::checkbox('image_delete') }}
<img src="{{ Storage::disk('public')->url(app('accessories_upload_path').e($item->image)) }}" class="img-responsive" />
<img src="{{ Storage::disk('public')->url('uploads/accessories/'.e($item->image)) }}" class="img-responsive" />
{!! $errors->first('image_delete', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div>