mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Change to streaming downloads
This commit is contained in:
parent
1a48eb7ac2
commit
8ed382a0b7
@ -137,7 +137,10 @@ class InvoiceController extends Controller
|
||||
|
||||
//if only 1 pdf, output to buffer for download
|
||||
if ($invoices->count() == 1) {
|
||||
return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($invoices->first()->pdf_file_path()));
|
||||
return response()->streamDownload(function () use($invoices) {
|
||||
echo file_get_contents($invoices->first()->pdf_file_path());
|
||||
}, basename($invoices->first()->pdf_file_path()));
|
||||
//return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($invoices->first()->pdf_file_path()));
|
||||
}
|
||||
|
||||
# enable output of HTTP headers
|
||||
|
@ -74,7 +74,10 @@ class QuoteController extends Controller
|
||||
}
|
||||
|
||||
if ($quotes->count() == 1) {
|
||||
return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($quotes->first()->pdf_file_path()));
|
||||
return response()->streamDownload(function () use($invoices) {
|
||||
echo file_get_contents($invoices->first()->pdf_file_path());
|
||||
}, basename($invoices->first()->pdf_file_path()));
|
||||
//return response()->download(TempFile::path($invoices->first()->pdf_file_path()), basename($quotes->first()->pdf_file_path()));
|
||||
}
|
||||
|
||||
# enable output of HTTP headers
|
||||
|
@ -527,7 +527,10 @@ class CreditController extends BaseController
|
||||
}
|
||||
break;
|
||||
case 'download':
|
||||
return response()->download(TempFile::path($credit->pdf_file_path()), basename($credit->pdf_file_path()));
|
||||
return response()->streamDownload(function () use($credit) {
|
||||
echo file_get_contents($credit->pdf_file_path());
|
||||
}, basename($credit->pdf_file_path()));
|
||||
//return response()->download(TempFile::path($credit->pdf_file_path()), basename($credit->pdf_file_path()));
|
||||
break;
|
||||
case 'archive':
|
||||
$this->credit_repository->archive($credit);
|
||||
|
@ -2,9 +2,14 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\Document\EditDocumentRequest;
|
||||
use App\Http\Requests\Document\ShowDocumentRequest;
|
||||
use App\Http\Requests\Document\StoreDocumentRequest;
|
||||
use App\Http\Requests\Document\UpdateDocumentRequest;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DocumentController extends Controller
|
||||
class DocumentController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@ -32,7 +37,7 @@ class DocumentController extends Controller
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(StoreDocumentRequest $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
@ -43,9 +48,13 @@ class DocumentController extends Controller
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
public function show(ShowDocumentRequest $request, Document $document)
|
||||
{
|
||||
//
|
||||
return response()->streamDownload(function () use($document) {
|
||||
echo file_get_contents($document->generateUrl());
|
||||
}, basename($document->generateUrl()));
|
||||
|
||||
//return response()->download($document->generateUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +63,7 @@ class DocumentController extends Controller
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(EditDocumentRegquest $request, Document $document)
|
||||
{
|
||||
//
|
||||
}
|
||||
@ -66,7 +75,7 @@ class DocumentController extends Controller
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(UpdateDocumentRequest $request, Document $document)
|
||||
{
|
||||
//
|
||||
}
|
||||
@ -77,7 +86,7 @@ class DocumentController extends Controller
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(DestroyDocumentRequest $request, Document $document)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@ -660,7 +660,10 @@ class InvoiceController extends BaseController
|
||||
}
|
||||
break;
|
||||
case 'download':
|
||||
return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path()));
|
||||
return response()->streamDownload(function () use($invoice) {
|
||||
echo file_get_contents($invoice->pdf_file_path());
|
||||
}, basename($invoice->pdf_file_path()));
|
||||
//return response()->download(TempFile::path($invoice->pdf_file_path()), basename($invoice->pdf_file_path()));
|
||||
break;
|
||||
case 'restore':
|
||||
$this->invoice_repo->restore($invoice);
|
||||
|
@ -661,7 +661,10 @@ class QuoteController extends BaseController
|
||||
# code...
|
||||
break;
|
||||
case 'download':
|
||||
return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path()));
|
||||
return response()->streamDownload(function () use($quote) {
|
||||
echo file_get_contents($quote->pdf_file_path());
|
||||
}, basename($quote->pdf_file_path()));
|
||||
//return response()->download(TempFile::path($quote->pdf_file_path()), basename($quote->pdf_file_path()));
|
||||
break;
|
||||
case 'archive':
|
||||
$this->invoice_repo->archive($quote);
|
||||
|
@ -134,6 +134,11 @@ class Company extends BaseModel
|
||||
self::ENTITY_RECURRING_QUOTE => 2048,
|
||||
];
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->morphMany(Document::class, 'documentable');
|
||||
}
|
||||
|
||||
public function getEntityType()
|
||||
{
|
||||
return Company::class;
|
||||
|
@ -112,4 +112,11 @@ class Document extends BaseModel
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function generateRoute($absolute = false)
|
||||
{
|
||||
return route('api.documents.show', ['document' => $this->hashed_id]);
|
||||
|
||||
//return route('document.show', ['document' => $this->hashed_id]);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class DocumentTransformer extends EntityTransformer
|
||||
'assigned_user_id' => $this->encodePrimaryKey($document->assigned_user_id),
|
||||
'project_id' => $this->encodePrimaryKey($document->project_id),
|
||||
'vendor_id' => $this->encodePrimaryKey($document->vendor_id),
|
||||
'url' => (string) $document->generateUrl() ?: '',
|
||||
'url' => (string) $document->generateRoute() ?: '',
|
||||
'preview' => (string) $document->preview ?: '',
|
||||
'name' => (string) $document->name,
|
||||
'type' => (string) $document->type,
|
||||
|
Loading…
Reference in New Issue
Block a user