Skip to content

A free open source IT asset/license management system

WIP - this needs refactoring

snipe262eb7947175
diff --git a/app/Http/Controllers/Licenses/LicenseFilesController.php b/app/Http/Controllers/Licenses/LicenseFilesController.php
index 7fe5cc78ef..cfa11609ff 100644
--- a/app/Http/Controllers/Licenses/LicenseFilesController.php
+++ b/app/Http/Controllers/Licenses/LicenseFilesController.php
@@ -38,10 +38,12 @@ class LicenseFilesController extends Controller
$upload_success = false;
foreach ($request->file('file') as $file) {
- $extension = $file->getClientOriginalExtension();
- $file_name = 'license-'.$license->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
- $upload_success = Storage::put('private_uploads/licenses/'.$file_name, $file);
+ $file_name = 'license-'.date('Y-m-d-His').'-'.$file->getBasename().'.'.$file->getClientOriginalExtension();
+
+
+ $upload_success = $file->storeAs('private_uploads/licenses', $file_name);
+ // $upload_success = $file->storeAs('private_uploads/licenses/'.$file_name, $file);
//Log the upload to the log
$license->logUpload($file_name, e($request->input('notes')));
@@ -116,6 +118,7 @@ class LicenseFilesController extends Controller
public function show($licenseId = null, $fileId = null, $download = true)
{
+ \Log::info('Private filesystem is: '.config('filesystems.default') );
$license = License::find($licenseId);
// the license is valid
@@ -128,22 +131,37 @@ class LicenseFilesController extends Controller
}
$file = 'private_uploads/licenses/'.$log->filename;
- \Log::debug('Checking for '.$file);
- if (!Storage::exists($file)) {
- return response('File '.$file.' not found on server', 404)
- ->header('Content-Type', 'text/plain');
- }
- if ($download != 'true') {
- if ($contents = file_get_contents(Storage::url($file))) {
- return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
+ if (Storage::missing($file)) {
+ \Log::debug('NOT EXISTS for '.$file);
+ \Log::debug('NOT EXISTS URL should be '.Storage::url($file));
+ return response('File '.$file.' ('.Storage::url($file).') not found on server', 404)
+ ->header('Content-Type', 'text/plain');
+ } else {
+
+ // We have to override the URL stuff here, since local defaults in Laravel's Flysystem
+ // won't work, as they're not accessible via the web
+ if (config('filesystems.default') == 'local') {
+ \Log::debug('The private filesystem is local');
+ return Response::make(Storage::get($file));
+
+ } else {
+ if ($download != 'true') {
+ if ($contents = file_get_contents(Storage::url($file))) {
+ return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
+ }
+ return JsonResponse::create(["error" => "Failed validation: "], 500);
+ }
+
+ return Storage::download($file);
}
- return JsonResponse::create(["error" => "Failed validation: "], 500);
+
}
- return Storage::download($file);
+
+
}
- return redirect()->route('hardware.index')->with('error', trans('admin/licenses/message.does_not_exist', ['id' => $fileId]));
+ return redirect()->route('license.index')->with('error', trans('admin/licenses/message.does_not_exist', ['id' => $fileId]));
}