From 3575c0b166c6e971226ef00b43705798ac0a6570 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 19 Oct 2023 22:32:34 -0700 Subject: [PATCH] folder-share: tweaks Signed-off-by: Varun Patil --- lib/Controller/PublicAlbumController.php | 1 + lib/Controller/PublicController.php | 9 ++++++--- lib/Db/FsManager.php | 18 ++++++++++++++---- src/components/frame/Folder.vue | 8 ++++---- src/components/top-matter/DynamicTopMatter.vue | 13 ++++++++----- src/components/top-matter/FolderTopMatter.vue | 18 ++++++++++++------ src/components/top-matter/PublicShareHeader.ts | 7 +++++-- src/services/utils/const.ts | 1 + 8 files changed, 51 insertions(+), 24 deletions(-) diff --git a/lib/Controller/PublicAlbumController.php b/lib/Controller/PublicAlbumController.php index 805cd071..06cef037 100644 --- a/lib/Controller/PublicAlbumController.php +++ b/lib/Controller/PublicAlbumController.php @@ -81,6 +81,7 @@ class PublicAlbumController extends Controller // Share info $this->initialState->provideInitialState('share_title', $album['name']); + $this->initialState->provideInitialState('share_type', 'album'); // Render main template $response = new PublicTemplateResponse(Application::APPNAME, 'main', PageController::getMainParams()); diff --git a/lib/Controller/PublicController.php b/lib/Controller/PublicController.php index 3ba4660d..f5f9bbb6 100644 --- a/lib/Controller/PublicController.php +++ b/lib/Controller/PublicController.php @@ -98,15 +98,18 @@ class PublicController extends AuthPublicShareController // Scripts \OCP\Util::addScript(Application::APPNAME, 'memories-main'); + // Get share node + $node = $share->getNode(); + // Share info $this->initialState->provideInitialState('no_download', $share->getHideDownload()); + $this->initialState->provideInitialState('share_title', $node->getName()); - // Share file id only if not a folder - $node = $share->getNode(); if ($node instanceof \OCP\Files\File) { $this->initialState->provideInitialState('single_item', $this->getSingleItemInitialState($node)); + $this->initialState->provideInitialState('share_type', 'file'); } elseif ($node instanceof \OCP\Files\Folder) { - $this->initialState->provideInitialState('share_title', $node->getName()); + $this->initialState->provideInitialState('share_type', 'folder'); } else { throw new NotFoundException(); } diff --git a/lib/Db/FsManager.php b/lib/Db/FsManager.php index 91865397..2cff95ac 100644 --- a/lib/Db/FsManager.php +++ b/lib/Db/FsManager.php @@ -84,17 +84,24 @@ class FsManager throw new \Exception('Share is not a folder'); } + // Folder inside shared folder if ($path = $this->getRequestFolder()) { + $sanitized = Util::sanitizePath($path); + if (null === $sanitized) { + throw new \Exception("Invalid parameter path: {$path}"); + } + + // Get subnode from share try { - $node = $share->get(Util::sanitizePath($path)); + $share = $share->get($sanitized); } catch (\OCP\Files\NotFoundException $e) { throw new \Exception("Folder not found: {$e->getMessage()}"); } - $root->addFolder($node); - } else { - $root->addFolder($share); } + // This internally checks if the node is a folder + $root->addFolder($share); + return $root; } @@ -331,6 +338,9 @@ class FsManager return $share; } + /** + * Get the share node from the request. + */ public function getShareNode(): ?Node { $share = $this->getShareObject(); diff --git a/src/components/frame/Folder.vue b/src/components/frame/Folder.vue index a7d4b834..8ec7b3b9 100644 --- a/src/components/frame/Folder.vue +++ b/src/components/frame/Folder.vue @@ -58,15 +58,15 @@ export default defineComponent({ computed: { /** Open folder */ target() { - let currentPath: string[] | string = this.$route.params.path || []; - if (typeof currentPath === 'string') { - currentPath = currentPath.split('/'); + let path: string[] | string = this.$route.params.path || []; + if (typeof path === 'string') { + path = path.split('/'); } return { name: this.$route.name, params: { - path: [...currentPath, this.data.name], + path: [...path, this.data.name], }, }; }, diff --git a/src/components/top-matter/DynamicTopMatter.vue b/src/components/top-matter/DynamicTopMatter.vue index 2a2a90e2..a61b3030 100644 --- a/src/components/top-matter/DynamicTopMatter.vue +++ b/src/components/top-matter/DynamicTopMatter.vue @@ -15,9 +15,11 @@ import FolderDynamicTopMatter from './FolderDynamicTopMatter.vue'; import PlacesDynamicTopMatterVue from './PlacesDynamicTopMatter.vue'; import OnThisDay from './OnThisDay.vue'; -import * as PublicShareHeader from './PublicShareHeader'; import * as strings from '../../services/strings'; +// Auto-hide top header on public shares if redundant +import './PublicShareHeader'; + export default defineComponent({ name: 'DynamicTopMatter', @@ -50,17 +52,18 @@ export default defineComponent({ viewName(): string { // Show album name for album view if (this.routeIsAlbums) { - return this.$route.params.name || ''; + return this.$route.params.name || String(); } - // Show share name for public shares, except for folder share, because the name is already present in the breadcrumbs + // Show share name for public shares, except for folder share, + // because the name is already present in the breadcrumbs if (this.routeIsPublic && !this.routeIsFolderShare) { - return PublicShareHeader.title; + return this.initstate.shareTitle; } // Only static top matter for these routes if (this.routeIsTags || this.routeIsPeople || this.routeIsPlaces) { - return ''; + return String(); } return strings.viewName(this.$route.name!); diff --git a/src/components/top-matter/FolderTopMatter.vue b/src/components/top-matter/FolderTopMatter.vue index d1895a40..3404ecce 100644 --- a/src/components/top-matter/FolderTopMatter.vue +++ b/src/components/top-matter/FolderTopMatter.vue @@ -2,9 +2,14 @@
-