diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-04-04 13:02:51 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-04-16 23:52:09 +0200 |
commit | e545eee21072eed69ccb1ada74414da00f441a50 (patch) | |
tree | ce99758bf948ef00702cf6fe01ee62dbfb0e17a9 /apps/files | |
parent | d9a1a9b01cfb7825ec533a2e3d744ed9b3259994 (diff) | |
download | nextcloud-server-e545eee21072eed69ccb1ada74414da00f441a50.tar.gz nextcloud-server-e545eee21072eed69ccb1ada74414da00f441a50.zip |
fix(files): Do not show files from hidden folders in "Recent"-view if hidden files are disabled by user
Needed to adjust the store creation to be able to inject pinia before the vue app is initialized.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/src/main.ts | 6 | ||||
-rw-r--r-- | apps/files/src/services/Recent.ts | 24 | ||||
-rw-r--r-- | apps/files/src/store/index.ts | 25 | ||||
-rw-r--r-- | apps/files/src/views/FilesList.vue | 8 | ||||
-rw-r--r-- | apps/files/src/views/recent.ts | 2 |
5 files changed, 59 insertions, 6 deletions
diff --git a/apps/files/src/main.ts b/apps/files/src/main.ts index 7b25c88a697..97b3b2f9651 100644 --- a/apps/files/src/main.ts +++ b/apps/files/src/main.ts @@ -1,8 +1,9 @@ -import Vue from 'vue' -import { createPinia, PiniaVuePlugin } from 'pinia' +import { PiniaVuePlugin } from 'pinia' import { getNavigation } from '@nextcloud/files' import { getRequestToken } from '@nextcloud/auth' +import Vue from 'vue' +import { pinia } from './store/index.ts' import router from './router/router' import RouterService from './services/RouterService' import SettingsModel from './models/Setting.js' @@ -30,7 +31,6 @@ Object.assign(window.OCP.Files, { Router }) // Init Pinia store Vue.use(PiniaVuePlugin) -const pinia = createPinia() // Init Navigation Service // This only works with Vue 2 - with Vue 3 this will not modify the source but return just a oberserver diff --git a/apps/files/src/services/Recent.ts b/apps/files/src/services/Recent.ts index 26c4babb5a2..47f31466dd2 100644 --- a/apps/files/src/services/Recent.ts +++ b/apps/files/src/services/Recent.ts @@ -20,17 +20,37 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -import type { ContentsWithRoot } from '@nextcloud/files' +import type { ContentsWithRoot, Node } from '@nextcloud/files' import type { FileStat, ResponseDataDetailed } from 'webdav' import { getCurrentUser } from '@nextcloud/auth' import { Folder, Permission, davGetRecentSearch, davGetClient, davResultToNode, davRootPath, davRemoteURL } from '@nextcloud/files' +import { useUserConfigStore } from '../store/userconfig.ts' +import { pinia } from '../store/index.ts' const client = davGetClient() const lastTwoWeeksTimestamp = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 14)) +/** + * Get recently changed nodes + * + * This takes the users preference about hidden files into account. + * If hidden files are not shown, then also recently changed files *in* hidden directories are filtered. + * + * @param path Path to search for recent changes + */ export const getContents = async (path = '/'): Promise<ContentsWithRoot> => { + const store = useUserConfigStore(pinia) + /** + * Filter function that returns only the visible nodes - or hidden if explicitly configured + * @param node The node to check + */ + const filterHidden = (node: Node) => + path !== '/' // We need to hide files from hidden directories in the root if not configured to show + || store.userConfig.show_hidden // If configured to show hidden files we can early return + || !node.dirname.split('/').some((dir) => dir.startsWith('.')) // otherwise only include the file if non of the parent directories is hidden + const contentsResponse = await client.getDirectoryContents(path, { details: true, data: davGetRecentSearch(lastTwoWeeksTimestamp), @@ -53,6 +73,6 @@ export const getContents = async (path = '/'): Promise<ContentsWithRoot> => { owner: getCurrentUser()?.uid || null, permissions: Permission.READ, }), - contents: contents.map((r) => davResultToNode(r)), + contents: contents.map((r) => davResultToNode(r)).filter(filterHidden), } } diff --git a/apps/files/src/store/index.ts b/apps/files/src/store/index.ts new file mode 100644 index 00000000000..c97a09122ec --- /dev/null +++ b/apps/files/src/store/index.ts @@ -0,0 +1,25 @@ +/** + * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de> + * + * @author Ferdinand Thiessen <opensource@fthiessen.de> + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +import { createPinia } from 'pinia' + +export const pinia = createPinia() diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index 382be3153a0..d4649e5eb95 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -214,6 +214,8 @@ export default defineComponent({ loading: true, promise: null, Type, + + _unsubscribeStore: () => {}, } }, @@ -452,10 +454,16 @@ export default defineComponent({ subscribe('files:node:updated', this.onUpdatedNode) subscribe('nextcloud:unified-search.search', this.onSearch) subscribe('nextcloud:unified-search.reset', this.onSearch) + + // reload on settings change + this._unsubscribeStore = this.userConfigStore.$subscribe(() => this.fetchContent(), { deep: true }) }, unmounted() { unsubscribe('files:node:updated', this.onUpdatedNode) + unsubscribe('nextcloud:unified-search.search', this.onSearch) + unsubscribe('nextcloud:unified-search.reset', this.onSearch) + this._unsubscribeStore() }, methods: { diff --git a/apps/files/src/views/recent.ts b/apps/files/src/views/recent.ts index bb536674ec1..257aaf30dfd 100644 --- a/apps/files/src/views/recent.ts +++ b/apps/files/src/views/recent.ts @@ -19,11 +19,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ +import { View, getNavigation } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import HistorySvg from '@mdi/svg/svg/history.svg?raw' import { getContents } from '../services/Recent' -import { View, getNavigation } from '@nextcloud/files' export default () => { const Navigation = getNavigation() |