mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 05:32:39 +01:00
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Invoice Ninja (https://invoiceninja.com).
|
||
|
*
|
||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||
|
*
|
||
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||
|
*
|
||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||
|
*/
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Jobs\Util\UnlinkFile;
|
||
|
use App\Exceptions\SystemError;
|
||
|
use Illuminate\Support\Facades\Cache;
|
||
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
||
|
class ProtectedDownloadController extends BaseController
|
||
|
{
|
||
|
|
||
|
public function index(Request $request)
|
||
|
{
|
||
|
|
||
|
$hashed_path = Cache::pull($request->hash);
|
||
|
|
||
|
if (!$hashed_path) {
|
||
|
throw new SystemError('File no longer available', 404);
|
||
|
abort(404, 'File no longer available');
|
||
|
}
|
||
|
|
||
|
UnlinkFile::dispatch(config('filesystems.default'), $hashed_path)->delay(now()->addSeconds(10));
|
||
|
|
||
|
return response()->streamDownload(function () use ($hashed_path) {
|
||
|
echo Storage::get($hashed_path);
|
||
|
}, basename($hashed_path), []);
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|