mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fixes for #2753
This commit is contained in:
parent
0135ae425f
commit
516ef79130
@ -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);
|
||||
|
@ -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)) {
|
||||
|
@ -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
2
public/v1/js/app.js
vendored
File diff suppressed because one or more lines are too long
@ -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;
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user