diff options
author | Julien Veyssier <eneiluj@posteo.net> | 2022-05-04 12:19:00 +0300 |
---|---|---|
committer | Julien Veyssier <eneiluj@posteo.net> | 2022-05-04 12:19:00 +0300 |
commit | cd7d967b453b8d3fd0c27eeb2e843a10c43b6b11 (patch) | |
tree | 6da4e3bf4ddabc4f22377b2a2a8e4ccba00676ca | |
parent | 129de1815dbc2f03751de3b4a4a1b1a914a02ca2 (diff) |
adjust backend font stuff after reviewfeature/1885/extra-fonts
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
-rw-r--r-- | lib/Controller/SettingsController.php | 14 | ||||
-rw-r--r-- | lib/Service/FontService.php | 7 |
2 files changed, 11 insertions, 10 deletions
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index c785a4e9..9d9a789d 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -25,6 +25,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\NotFoundResponse; use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\ILogger; use \OCP\IRequest; @@ -337,7 +338,7 @@ class SettingsController extends Controller{ public function getJsonFontList() { $files = $this->fontService->getFontFiles(); $etags = array_map( - function (ISimpleFile $f) { + static function (ISimpleFile $f) { return $f->getETag(); }, $files @@ -427,14 +428,14 @@ class SettingsController extends Controller{ } $newFileResource = fopen($file['tmp_name'], 'rb'); if ($newFileResource === false) { - throw new Exception('Could not read file'); + throw new UploadException('Could not read file'); } $newFileName = $file['name']; $uploadResult = $this->fontService->uploadFontFile($newFileName, $newFileResource); return new JSONResponse($uploadResult); } return new JSONResponse(['error' => 'No uploaded file'], Http::STATUS_BAD_REQUEST); - } catch (Exception $e) { + } catch (UploadException | NotPermittedException $e) { $this->logger->error('Upload error', ['exception' => $e]); return new JSONResponse(['error' => 'Upload error'], Http::STATUS_BAD_REQUEST); } @@ -460,13 +461,10 @@ class SettingsController extends Controller{ ]; if (empty($file)) { - $error = $this->l10n->t('No file uploaded or file size exceeds maximum of %s', [Util::humanFileSize(Util::uploadLimit())]); + throw new UploadException($this->l10n->t('No file uploaded or file size exceeds maximum of %s', [Util::humanFileSize(Util::uploadLimit())])); } if (!empty($file) && array_key_exists('error', $file) && $file['error'] !== UPLOAD_ERR_OK) { - $error = $phpFileUploadErrors[$file['error']]; - } - if ($error !== null) { - throw new UploadException($error); + throw new UploadException($phpFileUploadErrors[$file['error']]); } return $file; } diff --git a/lib/Service/FontService.php b/lib/Service/FontService.php index 8cd76342..eeaa6c68 100644 --- a/lib/Service/FontService.php +++ b/lib/Service/FontService.php @@ -110,7 +110,7 @@ class FontService { if ($cachedNames === null) { $files = $this->getFontFiles(); $cachedNames = array_map( - function (ISimpleFile $f) { + static function (ISimpleFile $f) { return $f->getName(); }, $files @@ -130,7 +130,7 @@ class FontService { public function getFontList(array $fontFiles): array { $url = $this->url; $list = array_map( - function (ISimpleFile $f) use ($url) { + static function (ISimpleFile $f) use ($url) { return [ 'uri' => $url->linkToRouteAbsolute(Application::APPNAME . '.settings.getFontFile', ['name' => $f->getName()]), 'stamp' => $f->getETag(), @@ -238,6 +238,9 @@ class FontService { imagedestroy($im); } } catch (\Exception | \Throwable $e) { + // do nothing if there was any kind of error during overview generation + // the /apps/richdocuments/settings/fonts/FILE_NAME/overview request will fail with 404 + // in the UI and display a fallback message } } } |