2023-07-07 06:56:43 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2023-07-07 06:56:43 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Exceptions\SystemError;
|
2023-10-26 04:57:44 +02:00
|
|
|
use Illuminate\Http\Request;
|
2023-07-07 06:56:43 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
class ProtectedDownloadController extends BaseController
|
|
|
|
{
|
2023-11-19 23:04:11 +01:00
|
|
|
public function index(Request $request, string $hash)
|
2023-07-07 06:56:43 +02:00
|
|
|
{
|
2023-10-17 12:28:18 +02:00
|
|
|
/** @var string $hashed_path */
|
2024-03-09 06:42:27 +01:00
|
|
|
$hashed_path = Cache::get($hash);
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-07-07 06:56:43 +02:00
|
|
|
if (!$hashed_path) {
|
|
|
|
throw new SystemError('File no longer available', 404);
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-07-17 04:01:35 +02:00
|
|
|
return response()->streamDownload(function () use ($hashed_path) {
|
|
|
|
echo Storage::get($hashed_path);
|
|
|
|
}, basename($hashed_path), []);
|
2023-07-07 06:56:43 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|