Skip to content

Commit

Permalink
fix(templates): throw NotFoundException if no file returned by id
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Aug 15, 2024
1 parent 16102a2 commit a60c060
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/Service/TemplateFieldService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OCA\Richdocuments\AppConfig;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\Template\Field;
use OCP\Files\Template\FieldType;
use OCP\Http\Client\IClientService;
Expand Down Expand Up @@ -38,18 +39,22 @@ public function extractFields(Node|int $file) {
$file = $this->rootFolder->getFirstNodeById($file);
}

$collaboraUrl = $this->appConfig->getCollaboraUrlInternal();
$httpClient = $this->clientService->newClient();
try {
if (!$file) {
throw new NotFoundException();
}

$form = RemoteOptionsService::getDefaultOptions();
$form['query'] = ['limit' => 'content-control'];
$form['multipart'] = [[
'name' => 'data',
'contents' => $file->getStorage()->fopen($file->getInternalPath(), 'r'),
'headers' => ['Content-Type' => 'multipart/form-data'],
]];
$collaboraUrl = $this->appConfig->getCollaboraUrlInternal();
$httpClient = $this->clientService->newClient();

$form = RemoteOptionsService::getDefaultOptions();
$form['query'] = ['limit' => 'content-control'];
$form['multipart'] = [[
'name' => 'data',
'contents' => $file->getStorage()->fopen($file->getInternalPath(), 'r'),
'headers' => ['Content-Type' => 'multipart/form-data'],
]];

try {
$response = $httpClient->post(
$collaboraUrl . "/cool/extract-document-structure",
$form
Expand Down Expand Up @@ -95,6 +100,13 @@ public function fillFields(Node|int $file, array $fields = []) {

if (is_int($file)) {
$file = $this->rootFolder->getFirstNodeById($file);

if (!$file) {
$e = new NotFoundException();
$this->logger->error($e->getMessage());

throw $e;
}
}

$collaboraUrl = $this->appConfig->getCollaboraUrlInternal();
Expand Down

0 comments on commit a60c060

Please sign in to comment.