1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/TemplatePreviewController.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2023-10-06 12:07:31 +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-10-06 12:07:31 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers;
2023-10-26 04:57:44 +02:00
use App\Http\Requests\Report\ReportPreviewRequest;
2023-10-06 12:07:31 +02:00
use App\Utils\Traits\MakesHash;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
class TemplatePreviewController extends BaseController
{
use MakesHash;
private string $path_prefix = 'templates/';
private string $path_suffix = '.pdf';
public function __construct()
{
parent::__construct();
}
public function __invoke(ReportPreviewRequest $request, ?string $hash)
{
$report = Storage::disk(config('filesystems.default'))->exists($this->path_prefix.$hash.$this->path_suffix);
if(!$report) {
return response()->json(['message' => 'Still working.....'], 409);
}
2024-01-14 05:05:00 +01:00
2023-10-06 12:07:31 +02:00
Cache::forget($hash);
return response()->streamDownload(function () use ($hash) {
2024-01-14 05:05:00 +01:00
2023-10-06 12:07:31 +02:00
echo Storage::get($this->path_prefix.$hash.$this->path_suffix);
Storage::delete($this->path_prefix.$hash.$this->path_suffix);
}, 'template.pdf', ['Content-Type' => 'application/pdf']);
}
}