Skip to content

Commit a47ad15

Browse files
committed
fix: name conflict generation
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 884cbda commit a47ad15

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

lib/components/ConflictPicker.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,22 @@
7171
</template>
7272

7373
<script lang="ts">
74+
import type { ConflictResolutionResult } from '../index.ts'
75+
76+
import { basename, extname } from 'path'
7477
import { Node } from '@nextcloud/files'
7578
import { showError } from '@nextcloud/dialogs'
79+
import Vue from 'vue'
80+
7681
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
7782
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
7883
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
79-
import Vue from 'vue'
80-
8184
import ArrowRight from 'vue-material-design-icons/ArrowRight.vue'
8285
import Close from 'vue-material-design-icons/Close.vue'
8386
8487
import { n, t } from '../utils/l10n.ts'
8588
import logger from '../utils/logger.ts'
8689
import NodesPicker from './NodesPicker.vue'
87-
import { basename, extname } from 'path'
8890
8991
export default Vue.extend({
9092
name: 'ConflictPicker',
@@ -105,11 +107,18 @@ export default Vue.extend({
105107
default: '',
106108
},
107109
110+
/** All the existing files in the current directory */
111+
content: {
112+
type: Array as () => Node[],
113+
required: true,
114+
},
115+
108116
/** Existing files to be replaced */
109117
conflicts: {
110118
type: Array as () => Node[],
111119
required: true,
112120
},
121+
113122
/** New files being moved/uploaded */
114123
files: {
115124
type: Array as () => (Node|File)[],
@@ -222,7 +231,7 @@ export default Vue.extend({
222231
this.$emit('submit', {
223232
selected: [],
224233
renamed: [],
225-
})
234+
} as ConflictResolutionResult)
226235
},
227236
228237
onSubmit() {
@@ -237,7 +246,7 @@ export default Vue.extend({
237246
}
238247
239248
const selectedOldNames = this.oldSelected.map((node: Node) => node.basename) as string[]
240-
const directoryContent = this.conflicts.map((node: Node) => node.basename) as string[]
249+
const directoryContent = this.content.map((node: Node) => node.basename) as string[]
241250
242251
// Files that got selected twice (new and old) gets renamed
243252
const renamed = [] as (File|Node)[]
@@ -273,7 +282,7 @@ export default Vue.extend({
273282
this.$emit('submit', {
274283
selected,
275284
renamed,
276-
})
285+
} as ConflictResolutionResult)
277286
},
278287
279288
/**

lib/components/UploadPicker.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export default Vue.extend({
248248
249249
try {
250250
// Let the user choose what to do with the conflicting files
251-
const { selected, renamed } = await openConflictPicker(this.destination.dirname, compareFiles, conflicts)
251+
const { selected, renamed } = await openConflictPicker(this.destination.dirname, compareFiles, conflicts, this.content)
252252
files = [...uploads, ...selected, ...renamed]
253253
} catch (error) {
254254
// User cancelled

lib/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export { Upload, Status as UploadStatus } from './upload'
1010
let _uploader: Uploader | null = null
1111

1212
export type ConflictResolutionResult = {
13-
selected: File[],
14-
renamed: File[],
13+
selected: (File|Node)[],
14+
renamed: (File|Node)[],
1515
}
1616
/**
1717
* Get an Uploader instance
@@ -46,17 +46,19 @@ export function upload(destinationPath: string, file: File): Uploader {
4646
* Open the conflict resolver
4747
* @param {string} dirname the directory name
4848
* @param {(File|Node)[]} files the incoming files
49-
* @param {Node[]} conflicts the existing files
49+
* @param {Node[]} conflicts the conflicting files that already exists in the directory
50+
* @param {Node[]} content all the existing files in the directory
5051
* @return {Promise<ConflictResolutionResult>} the selected and renamed files
5152
*/
52-
export async function openConflictPicker(dirname: string, files: (File|Node)[], conflicts: Node[]): Promise<ConflictResolutionResult> {
53+
export async function openConflictPicker(dirname: string, files: (File|Node)[], conflicts: Node[], content: Node[] = conflicts): Promise<ConflictResolutionResult> {
5354
const { default: ConflictPicker } = await import('./components/ConflictPicker.vue')
5455
return new Promise((resolve, reject) => {
5556
const picker = new ConflictPicker({
5657
propsData: {
5758
dirname,
5859
files,
5960
conflicts,
61+
content,
6062
},
6163
})
6264

0 commit comments

Comments
 (0)