Skip to content

Commit

Permalink
refactor(files): Update @nextcloud/files to v3.5.0
Browse files Browse the repository at this point in the history
* Removed now duplicated code

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jun 21, 2024
1 parent da8e1c1 commit c3cd571
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 64 deletions.
3 changes: 1 addition & 2 deletions apps/files/src/actions/moveOrCopyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/actions/openFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const action = new FileAction({
id: 'open-folder',
displayName(files: Node[]) {
// Only works on single node
const displayName = files[0].attributes.displayName || files[0].basename
const displayName = files[0].attributes.displayname || files[0].basename
return t('files', 'Open folder {displayName}', { displayName })
},
iconSvgInline: () => FolderSvg,
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/BreadCrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default defineComponent({
const source: FileSource | undefined = this.getFileSourceFromPath(path)
const node: Node | undefined = source ? this.getNodeFromSource(source) : undefined
return node?.attributes?.displayName || basename(path)
return node?.attributes?.displayname || basename(path)
},
onClick(to) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/DragAndDropPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default Vue.extend({
summary(): string {
if (this.isSingleNode) {
const node = this.nodes[0]
return node.attributes?.displayName || node.basename
return node.attributes?.displayname || node.basename
}
return getSummaryFor(this.nodes)
Expand Down
6 changes: 3 additions & 3 deletions apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/NewNodeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 0 additions & 9 deletions apps/files/src/utils/davUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
35 changes: 0 additions & 35 deletions apps/files/src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 2 additions & 2 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ export default defineComponent({
...(this.userConfig.sort_folders_first ? [v => v.type !== 'folder'] : []),
// 3: Use sorting mode if NOT basename (to be able to use displayName too)
...(this.sortingMode !== 'basename' ? [v => v[this.sortingMode]] : []),
// 4: Use displayName if available, fallback to name
v => v.attributes?.displayName || v.basename,
// 4: Use displayname if available, fallback to name
v => v.attributes?.displayname || v.basename,
// 5: Finally, use basename if all previous sorting methods failed
v => v.basename,
]
Expand Down
35 changes: 27 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c3cd571

Please sign in to comment.