From ba01b1185759a18911c61bc47ea91ef4265c1d54 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 17 Jun 2024 17:06:53 +0200 Subject: [PATCH] refactor(files): Update `@nextcloud/files` to v3.5.0 * Removed now duplicated code Signed-off-by: Ferdinand Thiessen --- apps/files/src/actions/moveOrCopyAction.ts | 3 +- apps/files/src/components/FileEntryMixin.ts | 6 ++-- apps/files/src/components/NewNodeDialog.vue | 2 +- apps/files/src/utils/davUtils.js | 9 ------ apps/files/src/utils/fileUtils.ts | 35 --------------------- package-lock.json | 35 ++++++++++++++++----- package.json | 2 +- 7 files changed, 33 insertions(+), 59 deletions(-) diff --git a/apps/files/src/actions/moveOrCopyAction.ts b/apps/files/src/actions/moveOrCopyAction.ts index d7c7fa8d0578b..623170d3be6fb 100644 --- a/apps/files/src/actions/moveOrCopyAction.ts +++ b/apps/files/src/actions/moveOrCopyAction.ts @@ -10,7 +10,7 @@ import type { MoveCopyResult } from './moveOrCopyActionUtils' import { isAxiosError } from '@nextcloud/axios' import { FilePickerClosed, getFilePickerBuilder, showError } from '@nextcloud/dialogs' import { emit } from '@nextcloud/event-bus' -import { Permission, FileAction, FileType, NodeStatus, davGetClient, davRootPath, davResultToNode, davGetDefaultPropfind } from '@nextcloud/files' +import { FileAction, FileType, NodeStatus, davGetClient, davRootPath, davResultToNode, davGetDefaultPropfind, getUniqueName } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' import { openConflictPicker, hasConflict } from '@nextcloud/upload' import { basename, join } from 'path' @@ -22,7 +22,6 @@ import FolderMoveSvg from '@mdi/svg/svg/folder-move.svg?raw' import { MoveCopyAction, canCopy, canMove, getQueue } from './moveOrCopyActionUtils' import { getContents } from '../services/Files' import logger from '../logger' -import { getUniqueName } from '../utils/fileUtils' /** * Return the action that is possible for the given nodes diff --git a/apps/files/src/components/FileEntryMixin.ts b/apps/files/src/components/FileEntryMixin.ts index e6accb7861ac0..d7967d9dce81c 100644 --- a/apps/files/src/components/FileEntryMixin.ts +++ b/apps/files/src/components/FileEntryMixin.ts @@ -71,14 +71,14 @@ export default defineComponent({ }, extension() { - if (this.source.attributes?.displayName) { - return extname(this.source.attributes.displayName) + if (this.source.attributes?.displayname) { + return extname(this.source.attributes.displayname) } return this.source.extension || '' }, displayName() { const ext = this.extension - const name = String(this.source.attributes.displayName + const name = String(this.source.attributes.displayname || this.source.basename) // Strip extension from name if defined diff --git a/apps/files/src/components/NewNodeDialog.vue b/apps/files/src/components/NewNodeDialog.vue index a4477408fafb2..1ac65421dfeba 100644 --- a/apps/files/src/components/NewNodeDialog.vue +++ b/apps/files/src/components/NewNodeDialog.vue @@ -30,7 +30,7 @@ import type { PropType } from 'vue' import { defineComponent } from 'vue' import { translate as t } from '@nextcloud/l10n' -import { getUniqueName } from '../utils/fileUtils' +import { getUniqueName } from '@nextcloud/files' import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js' diff --git a/apps/files/src/utils/davUtils.js b/apps/files/src/utils/davUtils.js index a4c9ccac755de..8c28c25c04403 100644 --- a/apps/files/src/utils/davUtils.js +++ b/apps/files/src/utils/davUtils.js @@ -3,17 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { generateRemoteUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' -export const getRootPath = function() { - if (getCurrentUser()) { - return generateRemoteUrl(`dav/files/${getCurrentUser().uid}`) - } else { - return generateRemoteUrl('webdav').replace('/remote.php', '/public.php') - } -} - export const isPublic = function() { return !getCurrentUser() } diff --git a/apps/files/src/utils/fileUtils.ts b/apps/files/src/utils/fileUtils.ts index 2427e33035265..255c106740d7c 100644 --- a/apps/files/src/utils/fileUtils.ts +++ b/apps/files/src/utils/fileUtils.ts @@ -2,44 +2,9 @@ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { basename, extname } from 'path' import { FileType, type Node } from '@nextcloud/files' import { translate as t, translatePlural as n } from '@nextcloud/l10n' -// TODO: move to @nextcloud/files -/** - * Create an unique file name - * @param name The initial name to use - * @param otherNames Other names that are already used - * @param options Optional parameters for tuning the behavior - * @param options.suffix A function that takes an index and returns a suffix to add to the file name, defaults to '(index)' - * @param options.ignoreFileExtension Set to true to ignore the file extension when adding the suffix (when getting a unique directory name) - * @return Either the initial name, if unique, or the name with the suffix so that the name is unique - */ -export const getUniqueName = ( - name: string, - otherNames: string[], - options: { - suffix?: (i: number) => string, - ignoreFileExtension?: boolean, - } = {}, -): string => { - const opts = { - suffix: (n: number) => `(${n})`, - ignoreFileExtension: false, - ...options, - } - - let newName = name - let i = 1 - while (otherNames.includes(newName)) { - const ext = opts.ignoreFileExtension ? '' : extname(name) - const base = basename(name, ext) - newName = `${base} ${opts.suffix(i++)}${ext}` - } - return newName -} - /** * Extract dir and name from file path * diff --git a/package-lock.json b/package-lock.json index ad090f049e25c..9de57f87c6536 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@nextcloud/capabilities": "^1.0.4", "@nextcloud/dialogs": "^5.3.1", "@nextcloud/event-bus": "^3.3.1", - "@nextcloud/files": "^3.4.1", + "@nextcloud/files": "^3.5.1", "@nextcloud/initial-state": "^2.0.0", "@nextcloud/l10n": "^2.1.0", "@nextcloud/logger": "^3.0.2", @@ -4423,17 +4423,19 @@ } }, "node_modules/@nextcloud/files": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/@nextcloud/files/-/files-3.4.1.tgz", - "integrity": "sha512-0riNodzy/epHRpjIR0uuibzu+WO5GEjYqc9HjifR7fGb4Umi7cNykX7vR5o6BoEg64eYEHau0I4wBUtX/vRssQ==", + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/@nextcloud/files/-/files-3.5.1.tgz", + "integrity": "sha512-GkVWUgkBSVt27Carmp/DbnDiqHq03w3VQWt8xszacp/IQSB9G+8/KCvi8zxldac2q7lQ8NpHlB/Bqy8o+OOc0A==", "dependencies": { "@nextcloud/auth": "^2.3.0", "@nextcloud/l10n": "^3.1.0", "@nextcloud/logger": "^3.0.2", "@nextcloud/paths": "^2.1.0", "@nextcloud/router": "^3.0.1", + "@nextcloud/sharing": "^0.2.1", "cancelable-promise": "^4.3.1", "is-svg": "^5.0.1", + "typescript-event-target": "^1.1.1", "webdav": "^5.6.0" }, "engines": { @@ -4459,13 +4461,25 @@ "npm": "^10.0.0" } }, + "node_modules/@nextcloud/files/node_modules/@nextcloud/sharing": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@nextcloud/sharing/-/sharing-0.2.2.tgz", + "integrity": "sha512-ui0ZoVazroA+cF4+homhFSFAddd/P4uRYMfG3rw3QR8o6igrVFe0f0l21kYtUwXU0oC0K4v3k8j93zCTfz6v3g==", + "dependencies": { + "@nextcloud/initial-state": "^2.2.0" + }, + "engines": { + "node": "^20.0.0", + "npm": "^10.0.0" + } + }, "node_modules/@nextcloud/initial-state": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@nextcloud/initial-state/-/initial-state-2.1.0.tgz", - "integrity": "sha512-b92X/GvUPGQJpUQwauyG3D3dHsWowViVLnTtFPSMUc0rXtvYR5CvhkqJRfPC7O7W4VC7+V3q+FWeA+mQWMxN2Q==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@nextcloud/initial-state/-/initial-state-2.2.0.tgz", + "integrity": "sha512-cDW98L5KGGgpS8pzd+05304/p80cyu8U2xSDQGa+kGPTpUFmCbv2qnO5WrwwGTauyjYijCal2bmw82VddSH+Pg==", "engines": { "node": "^20.0.0", - "npm": "^9.0.0" + "npm": "^10.0.0" } }, "node_modules/@nextcloud/l10n": { @@ -26802,6 +26816,11 @@ "node": ">=14.17" } }, + "node_modules/typescript-event-target": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/typescript-event-target/-/typescript-event-target-1.1.1.tgz", + "integrity": "sha512-dFSOFBKV6uwaloBCCUhxlD3Pr/P1a/tJdcmPrTXCHlEFD3faj0mztjcGn6VBAhQ0/Bdy8K3VWrrqwbt/ffsYsg==" + }, "node_modules/ua-parser-js": { "version": "0.7.37", "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.37.tgz", diff --git a/package.json b/package.json index 04ca2ba7da2f5..aaa821a430a94 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@nextcloud/capabilities": "^1.0.4", "@nextcloud/dialogs": "^5.3.1", "@nextcloud/event-bus": "^3.3.1", - "@nextcloud/files": "^3.4.1", + "@nextcloud/files": "^3.5.1", "@nextcloud/initial-state": "^2.0.0", "@nextcloud/l10n": "^2.1.0", "@nextcloud/logger": "^3.0.2",