diff --git a/lib/Controller/ImageController.php b/lib/Controller/ImageController.php index 99a2e7e4..e02bc464 100644 --- a/lib/Controller/ImageController.php +++ b/lib/Controller/ImageController.php @@ -204,12 +204,11 @@ class ImageController extends GenericApiController // Allow these ony for logged in users $user = $this->userSession->getUser(); if (null !== $user) { - { // Get the path of the file if in current user's files - $path = $file->getPath(); - $parts = explode('/', $path); - if (\count($parts) > 3 && $parts[1] === $user->getUID()) { - $info['filename'] = $path; - } + // Get the path of the file relative to current user + // "/admin/files/Photos/Camera/20230821_135017.jpg" => "/Photos/..." + $parts = explode('/', $file->getPath()); + if (\count($parts) > 3 && 'files' === $parts[2] && $parts[1] === $user->getUID()) { + $info['filename'] = '/'.implode('/', \array_slice($parts, 3)); } // Get list of tags for this file diff --git a/src/components/Metadata.vue b/src/components/Metadata.vue index 3f305197..b3e6d799 100644 --- a/src/components/Metadata.vue +++ b/src/components/Metadata.vue @@ -299,7 +299,7 @@ export default defineComponent({ /** Image info */ imageInfoTitle(): string | null { if (this.config.sidebar_filepath && this.filepath) { - return this.filepath; + return this.filepath.replace(/^\//, ''); // remove leading slash } return this.baseInfo.basename; @@ -307,12 +307,7 @@ export default defineComponent({ /** Path to file excluding user directory */ filepath(): string | null { - if (utils.truthy(this.baseInfo, 'filename')) { - // "/admin/files/Photos/Camera/20230821_135017.jpg" => "Photos/..." - return this.baseInfo.filename.split('/').slice(3).join('/'); - } - - return null; + return this.baseInfo?.filename ?? null; }, imageInfoSub(): string[] {