From a88fd4e2fee8b8333f924c1e7ae62401f23589c3 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sun, 18 Jun 2023 00:37:08 +0200 Subject: [PATCH] fix getFileInfo --- lib/Controller/PageController.php | 9 +++++++-- lib/Utility/Time.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index e91ff0a..8293bfb 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -17,6 +17,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\TemplateResponse; use OCP\Files\FileInfo; use OCP\Files\Folder; +use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IRequest; @@ -141,6 +142,8 @@ class PageController extends Controller { parse_str(parse_url($path, PHP_URL_QUERY), $query); if (isset($query['path']) && is_string($query['path'])) { $node = $node->get($query['path']); + } elseif (isset($query['files']) && is_string($query['files'])) { + $node = $node->get($query['files']); } else { throw new NotFoundException('Shared file path or name not set'); } @@ -154,12 +157,14 @@ class PageController extends Controller { ->getId(); } - /** @var string[] $pathInfo */ $pathInfo = pathInfo($filePath); + if (!is_array($pathInfo)) { + throw new InvalidPathException("Can not get info for $filePath"); + } return [ 'fileName' => $pathInfo['filename'], - 'fileType' => strtolower($pathInfo['extension']), + 'fileType' => strtolower($pathInfo['extension'] ?? ''), 'fileId' => $fileId ]; } diff --git a/lib/Utility/Time.php b/lib/Utility/Time.php index b4cbf7f..fecbaf7 100644 --- a/lib/Utility/Time.php +++ b/lib/Utility/Time.php @@ -20,7 +20,7 @@ class Time { * @return int the current unix time in miliseconds */ public function getMicroTime(): int { - list($millisecs, $secs) = explode(" ", microtime()); + list($millisecs, $secs) = explode(' ', microtime()); return (int) ($secs . substr($millisecs, 2, 6)); } }