1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Don't store PDFs

This commit is contained in:
David Bomba 2021-05-14 21:15:11 +10:00
parent 5b78717de4
commit 7756ca7436
5 changed files with 40 additions and 37 deletions

View File

@ -795,7 +795,11 @@ class InvoiceController extends BaseController
$file_path = $invoice->service()->getInvoicePdf($contact);
return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache']);
return response()->streamDownload(function () use ($file_path) {
echo file_get_contents($file_path);
}, basename($file_path), ['Cache-Control:' => 'no-cache']);
//return response()->download(Storage::url($file_path), basename($file_path), ['Cache-Control:' => 'no-cache']);
}
/**
@ -844,12 +848,15 @@ class InvoiceController extends BaseController
*/
public function deliveryNote(ShowInvoiceRequest $request, Invoice $invoice)
{
$file_path = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact);
$file = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact);
try {
$file = public_path("storage/{$file_path}");
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache']);
return response()->streamDownload(function () use ($file) {
echo file_get_contents($file);
}, basename($file), ['Cache-Control:' => 'no-cache']);
// return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache']);
} catch (\Exception $e) {
return response(['message' => 'Oops, something went wrong. Make sure you have symlink to storage/ in public/ directory.'], 500);
}

View File

@ -30,6 +30,7 @@ use App\Utils\HostedPDF\NinjaPdf;
use App\Utils\HtmlEngine;
use App\Utils\Ninja;
use App\Utils\PhantomJS\Phantom;
use App\Utils\TempFile;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\NumberFormatter;
@ -187,22 +188,23 @@ class CreateEntityPdf implements ShouldQueue
}
if ($pdf) {
// if ($pdf) {
try{
// try{
Storage::disk($this->disk)->put($file_path, $pdf);
// // Storage::disk($this->disk)->put($file_path, $pdf);
}
catch(\Exception $e)
{
// }
// catch(\Exception $e)
// {
throw new FilePermissionsFailure('Could not write the PDF, permission issues!');
// throw new FilePermissionsFailure('Could not write the PDF, permission issues!');
}
}
// }
// }
// // nlog("entity says path = {$file_path}");
return TempFile::filePath($pdf, $this->entity->numberFormatter().'.pdf');
return $file_path;
}
public function failed($e)

View File

@ -39,8 +39,6 @@ class UnlinkFile implements ShouldQueue
*/
public function handle()
{
// nlog("deleting");
// nlog($this->file_path);
Storage::disk($this->disk)->delete($this->file_path);
}
}

View File

@ -59,7 +59,7 @@ class GenerateDeliveryNote
? $this->invoice->design_id
: $this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id'));
$file_path = sprintf('%s%s_delivery_note.pdf', $this->invoice->client->invoice_filepath(), $this->invoice->number);
$filename = sprintf('%s_delivery_note.pdf', $this->invoice->number);
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom)->generate($this->invoice->invitations->first());
@ -91,8 +91,6 @@ class GenerateDeliveryNote
->design($template)
->build();
// Storage::makeDirectory($this->invoice->client->invoice_filepath(), 0775);
if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
}
@ -104,12 +102,8 @@ class GenerateDeliveryNote
info($maker->getCompiledHTML());
}
Storage::disk($this->disk)->put($file_path, $pdf);
/* Copy from remote disk to local when using cloud file storage. */
if(config('filesystems.default') == 's3')
return TempFile::path(Storage::disk($this->disk)->url($file_path));
return $file_path;
return TempFile::filePath($pdf, $filename);
// Storage::disk($this->disk)->put($file_path, $pdf);
// return $file_path;
}
}

View File

@ -35,24 +35,26 @@ class GetInvoicePdf extends AbstractService
$invitation = $this->invoice->invitations->where('client_contact_id', $this->contact->id)->first();
$path = $this->invoice->client->invoice_filepath();
// $path = $this->invoice->client->invoice_filepath();
$file_path = $path.$this->invoice->numberFormatter().'.pdf';
// $file_path = $path.$this->invoice->numberFormatter().'.pdf';
$disk = config('filesystems.default');
// $disk = config('filesystems.default');
$file = Storage::disk($disk)->exists($file_path);
// $file = Storage::disk($disk)->exists($file_path);
if (! $file) {
$file_path = CreateEntityPdf::dispatchNow($invitation);
}
// if (! $file) {
return CreateEntityPdf::dispatchNow($invitation);
// }
// return TempFile::filePath($pdf, $file_path);
// return $file_path;
/* Copy from remote disk to local when using cloud file storage. */
if(config('filesystems.default') == 's3')
return TempFile::path(Storage::disk($disk)->url($file_path));
// if(config('filesystems.default') == 's3')
// return TempFile::path(Storage::disk($disk)->url($file_path));
// return Storage::disk($disk)->url($file_path);
return Storage::disk($disk)->path($file_path);
// // return Storage::disk($disk)->url($file_path);
// return Storage::disk($disk)->path($file_path);
}
}