mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 21:52:35 +01:00
b233aa0744
Conflicts: .travis.yml CONTRIBUTING.md README.md app/Http/Controllers/AccountController.php app/Http/Controllers/AppController.php app/Http/Controllers/BaseAPIController.php app/Http/Controllers/CreditController.php app/Http/Controllers/DashboardController.php app/Http/Controllers/DocumentController.php app/Http/Controllers/PaymentController.php app/Http/Controllers/QuoteApiController.php app/Http/Requests/EntityRequest.php app/Http/routes.php app/Listeners/AnalyticsListener.php app/Models/Account.php app/Models/Credit.php app/Models/Document.php app/Models/EntityModel.php app/Models/Expense.php app/Models/Invoice.php app/Models/Task.php app/Models/VendorContact.php app/Ninja/Notifications/PushFactory.php app/Ninja/Repositories/DocumentRepository.php app/Ninja/Repositories/ExpenseRepository.php app/Ninja/Repositories/InvoiceRepository.php app/Services/PushService.php composer.json composer.lock database/migrations/2014_05_17_175626_add_quotes.php database/seeds/UserTableSeeder.php resources/lang/en/texts.php resources/views/accounts/customize_design.blade.php resources/views/accounts/invoice_design.blade.php resources/views/accounts/management.blade.php resources/views/expenses/edit.blade.php resources/views/header.blade.php resources/views/invoices/edit.blade.php resources/views/master.blade.php resources/views/payments/payment.blade.php resources/views/users/edit.blade.php
125 lines
3.5 KiB
PHP
125 lines
3.5 KiB
PHP
<?php namespace App\Http\Controllers;
|
|
|
|
use Redirect;
|
|
use View;
|
|
use Response;
|
|
use App\Models\Document;
|
|
use App\Ninja\Repositories\DocumentRepository;
|
|
use App\Http\Requests\DocumentRequest;
|
|
use App\Http\Requests\CreateDocumentRequest;
|
|
use App\Http\Requests\UpdateDocumentRequest;
|
|
|
|
class DocumentController extends BaseController
|
|
{
|
|
protected $documentRepo;
|
|
protected $entityType = ENTITY_DOCUMENT;
|
|
|
|
public function __construct(DocumentRepository $documentRepo)
|
|
{
|
|
// parent::__construct();
|
|
|
|
$this->documentRepo = $documentRepo;
|
|
}
|
|
|
|
public function get(DocumentRequest $request)
|
|
{
|
|
return static::getDownloadResponse($request->entity());
|
|
}
|
|
|
|
public static function getDownloadResponse($document){
|
|
$direct_url = $document->getDirectUrl();
|
|
if($direct_url){
|
|
return redirect($direct_url);
|
|
}
|
|
|
|
$stream = $document->getStream();
|
|
|
|
if($stream){
|
|
$headers = [
|
|
'Content-Type' => Document::$types[$document->type]['mime'],
|
|
'Content-Length' => $document->size,
|
|
];
|
|
|
|
$response = Response::stream(function() use ($stream) {
|
|
fpassthru($stream);
|
|
}, 200, $headers);
|
|
}
|
|
else{
|
|
$response = Response::make($document->getRaw(), 200);
|
|
$response->header('content-type', Document::$types[$document->type]['mime']);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function getPreview(DocumentRequest $request)
|
|
{
|
|
$document = $request->entity();
|
|
|
|
if(empty($document->preview)){
|
|
return Response::view('error', ['error'=>'Preview does not exist!'], 404);
|
|
}
|
|
|
|
$direct_url = $document->getDirectPreviewUrl();
|
|
if($direct_url){
|
|
return redirect($direct_url);
|
|
}
|
|
|
|
$previewType = pathinfo($document->preview, PATHINFO_EXTENSION);
|
|
$response = Response::make($document->getRawPreview(), 200);
|
|
$response->header('content-type', Document::$types[$previewType]['mime']);
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function getVFSJS(DocumentRequest $request, $publicId, $name)
|
|
{
|
|
$document = $request->entity();
|
|
|
|
if(substr($name, -3)=='.js'){
|
|
$name = substr($name, 0, -3);
|
|
}
|
|
|
|
if(!$document->isPDFEmbeddable()){
|
|
return Response::view('error', ['error'=>'Image does not exist!'], 404);
|
|
}
|
|
|
|
$content = $document->preview?$document->getRawPreview():$document->getRaw();
|
|
$content = 'ninjaAddVFSDoc('.json_encode(intval($publicId).'/'.strval($name)).',"'.base64_encode($content).'")';
|
|
$response = Response::make($content, 200);
|
|
$response->header('content-type', 'text/javascript');
|
|
$response->header('cache-control', 'max-age=31536000');
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function postUpload(CreateDocumentRequest $request)
|
|
{
|
|
if (!Utils::hasFeature(FEATURE_DOCUMENTS)) {
|
|
return;
|
|
}
|
|
|
|
$result = $this->documentRepo->upload($request->all(), $doc_array);
|
|
|
|
if(is_string($result)){
|
|
return Response::json([
|
|
'error' => $result,
|
|
'code' => 400
|
|
], 400);
|
|
} else {
|
|
return Response::json([
|
|
'error' => false,
|
|
'document' => $doc_array,
|
|
'code' => 200
|
|
], 200);
|
|
}
|
|
}
|
|
|
|
public function delete(UpdateDocumentRequest $request)
|
|
{
|
|
$request->entity()->delete();
|
|
|
|
return RESULT_SUCCESS;
|
|
}
|
|
}
|