This commit is contained in:
James Cole 2019-10-20 16:17:43 +02:00
parent 0135ae425f
commit 516ef79130
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 42 additions and 2 deletions

View File

@ -38,6 +38,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
use Log;
use function strlen;
/**
@ -99,8 +100,14 @@ class AttachmentController extends Controller
if (false === $attachment->uploaded) {
throw new FireflyException('No file has been uploaded for this attachment (yet).');
}
if (0 === $attachment->size) {
throw new FireflyException('No file has been uploaded for this attachment (yet).');
}
if ($this->repository->exists($attachment)) {
$content = $this->repository->getContent($attachment);
if ('' === $content) {
throw new FireflyException('No file has been uploaded for this attachment (yet).');
}
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
/** @var LaravelResponse $response */
@ -233,6 +240,11 @@ class AttachmentController extends Controller
/** @var AttachmentHelperInterface $helper */
$helper = app(AttachmentHelperInterface::class);
$body = $request->getContent();
if ('' === $body) {
Log::error('Body of attachment is empty.');
return response()->json([], 422);
}
$helper->saveAttachmentFromApi($attachment, $body);
return response()->json([], 204);

View File

@ -162,6 +162,13 @@ class AttachmentHelper implements AttachmentHelperInterface
return false;
// @codeCoverageIgnoreEnd
}
if ('' === $content) {
Log::error('Cannot upload empty file.');
return false;
}
$path = stream_get_meta_data($resource)['uri'];
fwrite($resource, $content);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
@ -199,6 +206,7 @@ class AttachmentHelper implements AttachmentHelperInterface
if (!($model instanceof Model)) {
return false; // @codeCoverageIgnore
}
Log::debug(sprintf('Now in saveAttachmentsForModel for model %s', get_class($model)));
if (is_array($files)) {
Log::debug('$files is an array.');
@ -362,6 +370,11 @@ class AttachmentHelper implements AttachmentHelperInterface
if (!$this->validMime($file)) {
$result = false;
}
if (0 === $file->getSize()) {
Log::error('Cannot upload empty file.');
$result = false;
}
// @codeCoverageIgnoreStart
// can't seem to reach this point.
if (true === $result && !$this->validSize($file)) {

View File

@ -97,6 +97,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
$journals = $group->transactionJournals->pluck('id')->toArray();
$set = Attachment::whereIn('attachable_id', $journals)
->where('attachable_type', TransactionJournal::class)
->where('uploaded', 1)
->whereNull('deleted_at')->get();
$result = [];

2
public/v1/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@ -515,6 +515,14 @@
}).catch(error => {
console.error('Could not upload');
console.error(error);
// console.log('Uploaded attachment #' + key);
uploads++;
if (uploads === count) {
// finally we can redirect the user onwards.
// console.log('FINAL UPLOAD');
this.redirectUser(groupId);
}
// console.log('Upload complete!');
return false;
});
});

View File

@ -736,7 +736,13 @@
// console.log('Upload complete!');
return true;
}).catch(error => {
// console.error('Could not upload');
console.error('Could not upload file.');
console.error(error);
uploads++;
this.error_message = 'Could not upload attachment: ' + error;
if (uploads === count) {
this.redirectUser(groupId);
}
// console.error(error);
return false;
});