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 17, 2024
1 parent 9872467 commit 7c2c02a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 45 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 @@ -12,7 +12,7 @@ import { AxiosError } from 'axios'
import { basename, join } from 'path'
import { emit } from '@nextcloud/event-bus'
import { FilePickerClosed, getFilePickerBuilder, showError } from '@nextcloud/dialogs'
import { Permission, FileAction, FileType, NodeStatus, davGetClient, davRootPath, davResultToNode, davGetDefaultPropfind } from '@nextcloud/files'
import { Permission, 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 Vue from 'vue'
Expand All @@ -23,7 +23,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/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
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
16 changes: 11 additions & 5 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"@mdi/js": "^7.4.47",
"@mdi/svg": "^7.4.47",
"@nextcloud/auth": "^2.1.0",
"@nextcloud/axios": "^2.3.0",
"@nextcloud/axios": "^2.4.0",
"@nextcloud/browser-storage": "^0.3.0",
"@nextcloud/browserslist-config": "^3.0.1",
"@nextcloud/calendar-availability-vue": "^2.2.0",
"@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.0",
"@nextcloud/initial-state": "^2.0.0",
"@nextcloud/l10n": "^2.1.0",
"@nextcloud/logger": "^3.0.2",
Expand Down

0 comments on commit 7c2c02a

Please sign in to comment.