Skip to content

Commit

Permalink
Merge pull request #13566 from snipe/features/13562_add_inline_file_link
Browse files Browse the repository at this point in the history
Fixed #13562 - Added inline file link
  • Loading branch information
snipe authored Sep 7, 2023
2 parents 7f892bf + 894c34f commit 02c187b
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 77 deletions.
21 changes: 9 additions & 12 deletions app/Http/Controllers/Accessories/AccessoriesFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,19 @@ public function show($accessoryId = null, $fileId = null, $download = true)
->header('Content-Type', 'text/plain');
} else {

// Display the file inline
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}


// 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') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);
} else {
if ($download != 'true') {
\Log::debug('display the file');
if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}

return JsonResponse::create(['error' => 'Failed validation: '], 500);
}

return StorageHelper::downloader($file);

}
}
}
Expand Down
13 changes: 7 additions & 6 deletions app/Http/Controllers/AssetModelsFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function store(AssetFileRequest $request, $modelId = null)
* @return View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($modelId = null, $fileId = null, $download = true)
public function show($modelId = null, $fileId = null)
{
$model = AssetModel::find($modelId);
// the asset is valid
Expand All @@ -99,12 +99,13 @@ public function show($modelId = null, $fileId = null, $download = true)
->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 (request('inline') == 'true') {

$headers = [
'Content-Disposition' => 'inline',
];

return JsonResponse::create(['error' => 'Failed validation: '], 500);
return Storage::download($file, $log->filename, $headers);
}

return StorageHelper::downloader($file);
Expand Down
13 changes: 7 additions & 6 deletions app/Http/Controllers/Assets/AssetFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function store(AssetFileRequest $request, $assetId = null)
* @return View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($assetId = null, $fileId = null, $download = true)
public function show($assetId = null, $fileId = null)
{
$asset = Asset::find($assetId);
// the asset is valid
Expand All @@ -103,12 +103,13 @@ public function show($assetId = null, $fileId = null, $download = true)
->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 (request('inline') == 'true') {

$headers = [
'Content-Disposition' => 'inline',
];

return JsonResponse::create(['error' => 'Failed validation: '], 500);
return Storage::download($file, $log->filename, $headers);
}

return StorageHelper::downloader($file);
Expand Down
24 changes: 10 additions & 14 deletions app/Http/Controllers/Components/ComponentsFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function destroy($componentId = null, $fileId = null)
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($componentId = null, $fileId = null, $download = true)
public function show($componentId = null, $fileId = null)
{
\Log::debug('Private filesystem is: '.config('filesystems.default'));
$component = Component::find($componentId);
Expand All @@ -157,21 +157,17 @@ public function show($componentId = null, $fileId = null, $download = true)
->header('Content-Type', 'text/plain');
} else {

if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);
} else {
if ($download != 'true') {
\Log::debug('display the file');
if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}

return JsonResponse::create(['error' => 'Failed validation: '], 500);
}
// Display the file inline
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}

if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);

}
}
}
}

Expand Down
23 changes: 10 additions & 13 deletions app/Http/Controllers/Consumables/ConsumablesFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function destroy($consumableId = null, $fileId = null)
* @return \Symfony\Consumable\HttpFoundation\Response
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($consumableId = null, $fileId = null, $download = true)
public function show($consumableId = null, $fileId = null)
{
$consumable = Consumable::find($consumableId);

Expand All @@ -155,22 +155,19 @@ public function show($consumableId = null, $fileId = null, $download = true)
->header('Content-Type', 'text/plain');
} else {

// Display the file inline
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}


// 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') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);
} else {
if ($download != 'true') {
\Log::debug('display the file');
if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}

return JsonResponse::create(['error' => 'Failed validation: '], 500);
}

return StorageHelper::downloader($file);

}
}
}
Expand Down
20 changes: 9 additions & 11 deletions app/Http/Controllers/Licenses/LicenseFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,19 @@ public function show($licenseId = null, $fileId = null, $download = true)
->header('Content-Type', 'text/plain');
} else {

if (request('inline') == 'true') {

$headers = [
'Content-Disposition' => 'inline',
];

return Storage::download($file, $log->filename, $headers);
}

// 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') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);
} else {
if ($download != 'true') {
\Log::debug('display the file');
if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}

return JsonResponse::create(['error' => 'Failed validation: '], 500);
}

return StorageHelper::downloader($file);

}
}
Expand Down
20 changes: 14 additions & 6 deletions app/Http/Controllers/Users/UserFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Users;

use App\Helpers\StorageHelper;
use App\Http\Controllers\Controller;
use App\Http\Requests\AssetFileRequest;
use App\Models\Actionlog;
Expand Down Expand Up @@ -139,18 +140,25 @@ public function show($userId = null, $fileId = null)

// the license is valid
if (isset($user->id)) {

$this->authorize('view', $user);

$log = Actionlog::find($fileId);
$file = $log->get_src('users');

return Response::download($file); //FIXME this doesn't use the new StorageHelper yet, but it's complicated...
// Display the file inline
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download('private_uploads/users/'.$log->filename, $log->filename, $headers);
}

return Storage::download('private_uploads/users/'.$log->filename);

}
// Prepare the error message
$error = trans('admin/users/message.user_not_found', ['id' => $userId]);

// Redirect to the licence management page
return redirect()->route('users.index')->with('error', $error);
// Redirect to the user management page if the user doesn't exist
return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', ['id' => $userId]));
}

}
7 changes: 6 additions & 1 deletion resources/views/accessories/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,15 @@ class="table table-striped snipe-table"
</td>
<td>
@if ($file->filename)
<a href="{{ route('show.accessoryfile', [$accessory->id, $file->id, 'download' => 'true']) }}" class="btn btn-default">
<a href="{{ route('show.accessoryfile', [$accessory->id, $file->id]) }}" class="btn btn-sm btn-default">
<i class="fas fa-download" aria-hidden="true"></i>
<span class="sr-only">{{ trans('general.download') }}</span>
</a>

<a href="{{ route('show.accessoryfile', [$accessory->id, $file->id, 'inline' => 'true']) }}" class="btn btn-sm btn-default" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>

@endif
</td>
<td>{{ $file->created_at }}</td>
Expand Down
7 changes: 6 additions & 1 deletion resources/views/components/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,15 @@ class="table table-striped snipe-table"
</td>
<td>
@if ($file->filename)
<a href="{{ route('show.componentfile', [$component->id, $file->id, 'download' => 'true']) }}" class="btn btn-default">
<a href="{{ route('show.componentfile', [$component->id, $file->id]) }}" class="btn btn-sm btn-default">
<i class="fas fa-download" aria-hidden="true"></i>
<span class="sr-only">{{ trans('general.download') }}</span>
</a>

<a href="{{ route('show.componentfile', [$component->id, $file->id, 'inline' => 'true']) }}" class="btn btn-sm btn-default" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>

@endif
</td>
<td>{{ $file->created_at }}</td>
Expand Down
6 changes: 5 additions & 1 deletion resources/views/consumables/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,14 @@ class="table table-striped snipe-table"
</td>
<td>
@if ($file->filename)
<a href="{{ route('show.consumablefile', [$consumable->id, $file->id, 'download' => 'true']) }}" class="btn btn-default">
<a href="{{ route('show.consumablefile', [$consumable->id, $file->id]) }}" class="btn btn-sm btn-default">
<i class="fas fa-download" aria-hidden="true"></i>
<span class="sr-only">{{ trans('general.download') }}</span>
</a>

<a href="{{ route('show.consumablefile', [$consumable->id, $file->id, 'inline' => 'true']) }}" class="btn btn-sm btn-default" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>
@endif
</td>
<td>{{ $file->created_at }}</td>
Expand Down
13 changes: 11 additions & 2 deletions resources/views/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,9 +1266,13 @@ class="table table-striped snipe-table"
</td>
<td>
@if (($file->filename) && (Storage::exists('private_uploads/assets/'.$file->filename)))
<a href="{{ route('show/assetfile', [$asset->id, $file->id]) }}" class="btn btn-default">
<a href="{{ route('show/assetfile', [$asset->id, $file->id, 'download'=>'true']) }}" class="btn btn-sm btn-default">
<i class="fas fa-download" aria-hidden="true"></i>
</a>

<a href="{{ route('show/assetfile', [$asset->id, $file->id, 'inline'=>'true']) }}" class="btn btn-sm btn-default" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>
@endif
</td>
<td>
Expand Down Expand Up @@ -1363,9 +1367,14 @@ class="table table-striped snipe-table"
</td>
<td>
@if (($file->filename) && (Storage::exists('private_uploads/assetmodels/'.$file->filename)))
<a href="{{ route('show/modelfile', [$asset->model->id, $file->id]) }}" class="btn btn-default">
<a href="{{ route('show/modelfile', [$asset->model->id, $file->id]) }}" class="btn btn-sm btn-default">
<i class="fas fa-download" aria-hidden="true"></i>
</a>

<a href="{{ route('show/modelfile', [$asset->model->id, $file->id, 'inline'=>'true']) }}" class="btn btn-sm btn-default" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>

@endif
</td>
<td>
Expand Down
7 changes: 6 additions & 1 deletion resources/views/licenses/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,15 @@ class="table table-striped snipe-table"
</td>
<td>
@if ($file->filename)
<a href="{{ route('show.licensefile', [$license->id, $file->id, 'download' => 'true']) }}" class="btn btn-default">
<a href="{{ route('show.licensefile', [$license->id, $file->id]) }}" class="btn btn-sm btn-default">
<i class="fas fa-download" aria-hidden="true"></i>
<span class="sr-only">{{ trans('general.download') }}</span>
</a>

<a href="{{ route('show.licensefile', [$license->id, $file->id, 'inline' => 'true']) }}" class="btn btn-sm btn-default" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>

@endif
</td>
<td>{{ $file->created_at }}</td>
Expand Down
7 changes: 6 additions & 1 deletion resources/views/models/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,14 @@ class="table table-striped snipe-table"
</td>
<td>
@if (($file->filename) && (Storage::exists('private_uploads/assetmodels/'.$file->filename)))
<a href="{{ route('show/modelfile', [$model->id, $file->id]) }}" class="btn btn-default">
<a href="{{ route('show/modelfile', [$model->id, $file->id]) }}" class="btn btn-sm btn-default">
<i class="fas fa-download" aria-hidden="true"></i>
</a>

<a href="{{ route('show/modelfile', [$model->id, $file->id, 'inline'=>'true']) }}" class="btn btn-sm btn-default" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
</a>

@endif
</td>
<td>
Expand Down
Loading

0 comments on commit 02c187b

Please sign in to comment.