Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

feat(frontend:files): skip conflicting files during copy, move and upload

johaven7c1d3ef5260d
diff --git a/frontend/src/app/applications/files/components/dialogs/files-overwrite-dialog.component.html b/frontend/src/app/applications/files/components/dialogs/files-overwrite-dialog.component.html
index 9c93fcbf..02f13ab9 100755
--- a/frontend/src/app/applications/files/components/dialogs/files-overwrite-dialog.component.html
+++ b/frontend/src/app/applications/files/components/dialogs/files-overwrite-dialog.component.html
@@ -25,6 +25,13 @@
}
</div>
<div class="modal-footer">
- <button (click)="onAction(false)" class="btn btn-secondary" data-dismiss="modal" type="button" l10nTranslate>Cancel</button>
- <button (click)="onAction(true)" [disabled]="submitted" class="btn btn-danger" type="button" l10nTranslate>Confirm</button>
+ <button (click)="onAction('cancel')" [disabled]="submitted" class="btn btn-secondary" data-dismiss="modal" type="button" l10nTranslate>
+ Cancel
+ </button>
+ @if (!renamedTo) {
+ <button (click)="onAction('skip')" [disabled]="submitted" class="btn btn-primary" type="button" l10nTranslate>
+ Skip existing files
+ </button>
+ }
+ <button (click)="onAction('overwrite')" [disabled]="submitted" class="btn btn-danger" type="button" l10nTranslate>Confirm</button>
</div>
diff --git a/frontend/src/app/applications/files/components/dialogs/files-overwrite-dialog.component.ts b/frontend/src/app/applications/files/components/dialogs/files-overwrite-dialog.component.ts
index 1c294339..0e89be15 100644
--- a/frontend/src/app/applications/files/components/dialogs/files-overwrite-dialog.component.ts
+++ b/frontend/src/app/applications/files/components/dialogs/files-overwrite-dialog.component.ts
@@ -5,6 +5,8 @@ import { L10N_LOCALE, L10nLocale, L10nTranslateDirective, L10nTranslatePipe } fr
import { LayoutService } from '../../../../layout/layout.service'
import { FileModel } from '../../models/file.model'
+export type FilesOverwriteAction = 'cancel' | 'skip' | 'overwrite'
+
@Component({
selector: 'app-files-overwrite-dialog',
imports: [FaIconComponent, L10nTranslateDirective, L10nTranslatePipe],
@@ -13,15 +15,15 @@ import { FileModel } from '../../models/file.model'
export class FilesOverwriteDialogComponent {
@Input({ required: true }) files: FileModel[] = []
@Input() renamedTo: string
- public overwrite = output<boolean>()
+ public action = output<FilesOverwriteAction>()
protected readonly locale = inject<L10nLocale>(L10N_LOCALE)
protected layout = inject(LayoutService)
protected readonly icons = { faFileShield }
protected submitted = false
- onAction(overwrite: boolean) {
- this.submitted = overwrite
- this.overwrite.emit(overwrite)
+ onAction(action: FilesOverwriteAction) {
+ this.submitted = true
+ this.action.emit(action)
this.layout.closeDialog()
}
}
diff --git a/frontend/src/app/applications/files/services/files-upload.service.ts b/frontend/src/app/applications/files/services/files-upload.service.ts
index f5d43b14..d1da3d92 100644
--- a/frontend/src/app/applications/files/services/files-upload.service.ts
+++ b/frontend/src/app/applications/files/services/files-upload.service.ts
@@ -42,6 +42,26 @@ export class FilesUploadService {
await Promise.all(taskReqs.map((taskReq: FileUploadTaskRequest) => taskReq.completed))
}
+ async addFilesWithConflictResolution(files: FileUpload[], exist: FileModel[]): Promise<void> {
+ let filesToUpload = files
+ let overwrite = false
+ if (exist.length) {
+ const action = await this.filesService.openOverwriteDialog(exist)
+ if (action === 'cancel') return
+ overwrite = action === 'overwrite'
+ if (action === 'skip') {
+ const existingNames = new Set(exist.map((file) => file.name.normalize().toLowerCase()))
+ filesToUpload = files.filter((file) => {
+ const relativePath = file.relativePath || file.webkitRelativePath
+ const topLevelName = relativePath ? relativePath.split('/')[0] : file.name
+ return !existingNames.has(topLevelName.normalize().toLowerCase())
+ })
+ if (!filesToUpload.length) return
+ }
+ }
+ await this.addFiles(filesToUpload, overwrite)
+ }
+
onDropFiles(ev: any, exist: FileModel[]) {
/*
Important: dataTransfer.items must be accessed synchronously before any async operation; overwrite is handled after all analyses.
@@ -50,7 +70,7 @@ export class FilesUploadService {
if (ev.dataTransfer.items && ev.dataTransfer.items[0]?.webkitGetAsEntry) {
this.webkitReadDataTransfer(ev, exist)
} else {
- this.addFiles(ev.dataTransfer.files, exist.length > 0).catch(console.error)
+ this.addFilesWithConflictResolution([...ev.dataTransfer.files], exist).catch(console.error)
}
}
@@ -279,18 +299,7 @@ export class FilesUploadService {
}
const decrement = () => {
if (--queue == 0) {
- if (exist.length <= 0) {
- this.addFiles(files, false).catch(console.error)
- return
- }
- this.filesService
- .openOverwriteDialog(exist)
- .then((overwrite) => {
- if (overwrite) {
- this.addFiles(files, true).catch(console.error)
- }
- })
- .catch(console.error)
+ this.addFilesWithConflictResolution(files, exist).catch(console.error)
}
}
diff --git a/frontend/src/app/applications/files/services/files.service.ts b/frontend/src/app/applications/files/services/files.service.ts
index 63721fd7..53639c86 100644
--- a/frontend/src/app/applications/files/services/files.service.ts
+++ b/frontend/src/app/applications/files/services/files.service.ts
@@ -46,7 +46,7 @@ import { LayoutService } from '../../../layout/layout.service'
import { StoreService } from '../../../store/store.service'
import { UserService } from '../../users/user.service'
import { FilesLockDialogComponent } from '../components/dialogs/files-lock-dialog.component'
-import { FilesOverwriteDialogComponent } from '../components/dialogs/files-overwrite-dialog.component'
+import { type FilesOverwriteAction, FilesOverwriteDialogComponent } from '../components/dialogs/files-overwrite-dialog.component'
import { FilesViewerDialogComponent } from '../components/dialogs/files-viewer-dialog.component'
import { FilesViewerSelectDialog } from '../components/dialogs/files-viewer-select-dialog.component'
import { fileLockPropsToString } from '../components/utils/file-lock.utils'
@@ -134,14 +134,20 @@ export class FilesService {
async copyMove(files: FileModel[], dstDirectory: string, type: FILE_OPERATION.COPY | FILE_OPERATION.MOVE): Promise<void> {
let overwrite = false
+ let filesToProcess = files
const dstFiles = await this.getTreeNode(dstDirectory, true)
const exist: FileModel[] = files.filter((f: FileModel) => dstFiles.some((x) => x.name.toLowerCase() === f.name.toLowerCase()))
if (exist.length > 0) {
- overwrite = await this.openOverwriteDialog(exist)
- if (!overwrite) return
+ const action = await this.openOverwriteDialog(exist)
+ if (action === 'cancel') return
+ overwrite = action === 'overwrite'
+ if (action === 'skip') {
+ filesToProcess = files.filter((file) => !exist.includes(file))
+ if (!filesToProcess.length) return
+ }
}
const isMove = type === FILE_OPERATION.MOVE
- for (const file of files) {
+ for (const file of filesToProcess) {
if (isMove) file.isBeingDeleted = true
const op: CopyMoveFileDto = { dstDirectory: dstDirectory, overwrite: overwrite }
this.http.request<FileTask>(type, file.taskUrl, { body: op }).subscribe({
@@ -279,26 +285,26 @@ export class FilesService {
})
}
- async openOverwriteDialog(files: File[] | FileModel[], renamedTo?: string): Promise<boolean> {
+ async openOverwriteDialog(files: File[] | FileModel[], renamedTo?: string): Promise<FilesOverwriteAction> {
const modalRef: BsModalRef<FilesOverwriteDialogComponent> = this.layout.openDialog(FilesOverwriteDialogComponent, null, {
initialState: { files, renamedTo } as FilesOverwriteDialogComponent
})
- return new Promise<boolean>((resolve) => {
+ return new Promise<FilesOverwriteAction>((resolve) => {
let resolved = false
- const subOverwrite = modalRef.content!.overwrite.subscribe((value: boolean) => {
+ const subAction = modalRef.content!.action.subscribe((action: FilesOverwriteAction) => {
resolved = true
cleanup()
- resolve(value)
+ resolve(action)
})
// Triggered when the modal is closed (close button, backdrop click, ESC key, or programmatic hide)
const subHidden = modalRef.onHidden?.subscribe(() => {
if (!resolved) {
cleanup()
- resolve(false)
+ resolve('cancel')
}
})
const cleanup = () => {
- subOverwrite.unsubscribe()
+ subAction.unsubscribe()
subHidden?.unsubscribe()
}
})
diff --git a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
index dd2a6297..06cda435 100644
--- a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
+++ b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
@@ -481,8 +481,9 @@ export class SpacesBrowserComponent implements OnInit, AfterViewInit, OnDestroy
let overwrite = false
const fileExists: FileModel = this.files.find((file) => file.name.toLowerCase() === renamedTo.toLowerCase() && file.id !== f.id)
if (fileExists) {
- overwrite = await this.filesService.openOverwriteDialog([f], renamedTo)
- if (!overwrite) return
+ const action = await this.filesService.openOverwriteDialog([f], renamedTo)
+ if (action !== 'overwrite') return
+ overwrite = true
}
this.filesService
.rename(f, renamedTo, overwrite)
@@ -577,25 +578,18 @@ export class SpacesBrowserComponent implements OnInit, AfterViewInit, OnDestroy
}
async onUploadFiles(ev: { files: File[] }, isDirectory = false) {
- let overwrite = false
const selectedFiles = [...ev.files]
+ let exist: FileModel[] = []
if (isDirectory) {
const dirName = selectedFiles[0].webkitRelativePath.split('/')[0].normalize()
const dirExists = this.files.find((f) => f.name.normalize().toLowerCase() === dirName.normalize().toLowerCase())
if (dirExists) {
- overwrite = await this.filesService.openOverwriteDialog([dirExists])
- if (!overwrite) return
+ exist = [dirExists]
}
} else {
- const exist: FileModel[] = this.files.filter((x: FileModel) =>
- selectedFiles.some((f) => f.name.normalize().toLowerCase() === x.name.normalize().toLowerCase())
- )
- if (exist.length > 0) {
- overwrite = await this.filesService.openOverwriteDialog(exist)
- if (!overwrite) return
- }
+ exist = this.files.filter((x: FileModel) => selectedFiles.some((f) => f.name.normalize().toLowerCase() === x.name.normalize().toLowerCase()))
}
- this.filesUpload.addFiles(selectedFiles, overwrite).catch(console.error)
+ this.filesUpload.addFilesWithConflictResolution(selectedFiles, exist).catch(console.error)
}
onDropFiles(ev: { dataTransfer: { files: File[] } }) {
diff --git a/frontend/src/i18n/de.json b/frontend/src/i18n/de.json
index 52038ee2..d23caaff 100644
--- a/frontend/src/i18n/de.json
+++ b/frontend/src/i18n/de.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Vorhandene Datei(en) überschreiben",
"Replace Existing File": "Vorhandene Datei ersetzen",
"Do you want to replace the existing file(s)?": "Möchten Sie die vorhandene(n) Datei(en) ersetzen?",
+ "Skip existing files": "Vorhandene Dateien überspringen",
"RenameFileToExisting": "Möchten Sie <b>{{ old }}</b> in <b>{{ new }}</b> umbenennen?",
"Save": "Speichern",
"Line Wrap": "Zeilenumbruch",
diff --git a/frontend/src/i18n/es.json b/frontend/src/i18n/es.json
index 8950b8e5..9e570faf 100644
--- a/frontend/src/i18n/es.json
+++ b/frontend/src/i18n/es.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Sobrescribir archivo(s) existente(s)",
"Replace Existing File": "Reemplazar archivo existente",
"Do you want to replace the existing file(s)?": "¿Desea reemplazar el/los archivo(s) existente(s)?",
+ "Skip existing files": "Omitir archivos existentes",
"RenameFileToExisting": "¿Desea renombrar <b>{{ old }}</b> a <b>{{ new }}</b>?",
"Save": "Guardar",
"Line Wrap": "Ajuste de línea",
diff --git a/frontend/src/i18n/fr.json b/frontend/src/i18n/fr.json
index a0e4b5a9..d2612a24 100644
--- a/frontend/src/i18n/fr.json
+++ b/frontend/src/i18n/fr.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Écraser le(s) fichier(s) existant(s)",
"Replace Existing File": "Remplacer le fichier existant",
"Do you want to replace the existing file(s)?": "Voulez-vous remplacer le(s) fichier(s) existant(s) ?",
+ "Skip existing files": "Ignorer les fichiers existants",
"RenameFileToExisting": "Souhaitez-vous renommer <b>{{ old }}</b> en <b>{{ new }}</b> ?",
"Save": "Enregistrer",
"Line Wrap": "Retour à la ligne automatique",
diff --git a/frontend/src/i18n/hi.json b/frontend/src/i18n/hi.json
index 8767af4e..b87c48be 100644
--- a/frontend/src/i18n/hi.json
+++ b/frontend/src/i18n/hi.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "मौजूदा फ़ाइल(ों) को अधिलेखित करें",
"Replace Existing File": "मौजूदा फ़ाइल प्रतिस्थापित करें",
"Do you want to replace the existing file(s)?": "क्या आप मौजूदा फ़ाइल(ों) को बदलना चाहते हैं?",
+ "Skip existing files": "मौजूदा फ़ाइलें छोड़ें",
"RenameFileToExisting": "क्या आप <b>{{ old }}</b> का नाम बदलकर <b>{{ new }}</b> करना चाहते हैं?",
"Save": "सहेजें",
"Line Wrap": "लाइन रैप",
diff --git a/frontend/src/i18n/it.json b/frontend/src/i18n/it.json
index c9bc1151..496b50e6 100644
--- a/frontend/src/i18n/it.json
+++ b/frontend/src/i18n/it.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Sovrascrivere il/i file esistente/i",
"Replace Existing File": "Sostituire il file esistente",
"Do you want to replace the existing file(s)?": "Vuoi sostituire il/i file esistente/i?",
+ "Skip existing files": "Ignora i file esistenti",
"RenameFileToExisting": "Vuoi rinominare <b>{{ old }}</b> in <b>{{ new }}</b>?",
"Save": "Salva",
"Line Wrap": "A capo automatico",
diff --git a/frontend/src/i18n/ja.json b/frontend/src/i18n/ja.json
index dc66c906..771d95d8 100644
--- a/frontend/src/i18n/ja.json
+++ b/frontend/src/i18n/ja.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "既存のファイルを上書き",
"Replace Existing File": "既存のファイルを置き換える",
"Do you want to replace the existing file(s)?": "既存のファイルを置き換えますか?",
+ "Skip existing files": "既存のファイルをスキップ",
"RenameFileToExisting": "<b>{{ old }}</b> の名前を <b>{{ new }}</b> に変更しますか?",
"Save": "保存",
"Line Wrap": "折り返し",
diff --git a/frontend/src/i18n/ko.json b/frontend/src/i18n/ko.json
index be39ab86..b9c4c40c 100644
--- a/frontend/src/i18n/ko.json
+++ b/frontend/src/i18n/ko.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "기존 파일 덮어쓰기",
"Replace Existing File": "기존 파일 교체",
"Do you want to replace the existing file(s)?": "기존 파일을 교체하시겠습니까?",
+ "Skip existing files": "기존 파일 건너뛰기",
"RenameFileToExisting": "<b>{{ old }}</b>의 이름을 <b>{{ new }}</b>(으)로 변경하시겠습니까?",
"Save": "저장",
"Line Wrap": "자동 줄 바꿈",
diff --git a/frontend/src/i18n/nl.json b/frontend/src/i18n/nl.json
index 346a22c2..ecfb8d5f 100644
--- a/frontend/src/i18n/nl.json
+++ b/frontend/src/i18n/nl.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Bestaande bestanden overschrijven",
"Replace Existing File": "Bestaand bestand vervangen",
"Do you want to replace the existing file(s)?": "Wilt u bestaande bestanden vervangen?",
+ "Skip existing files": "Bestaande bestanden overslaan",
"RenameFileToExisting": "Wilt u <b>{{ old }}</b> hernoemen tot <b>{{ new }}</b>?",
"Save": "Opslaan",
"Line Wrap": "Regelomslag",
diff --git a/frontend/src/i18n/pl.json b/frontend/src/i18n/pl.json
index baf519f4..5f26b262 100644
--- a/frontend/src/i18n/pl.json
+++ b/frontend/src/i18n/pl.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Nadpisać istniejący(e) plik(i)",
"Replace Existing File": "Zastąpić istniejący plik",
"Do you want to replace the existing file(s)?": "Czy chcesz zastąpić istniejący(e) plik(i)?",
+ "Skip existing files": "Pomiń istniejące pliki",
"RenameFileToExisting": "Czy chcesz zmienić nazwę <b>{{ old }}</b> na <b>{{ new }}</b>?",
"Save": "Zapisz",
"Line Wrap": "Zawijanie wierszy",
diff --git a/frontend/src/i18n/pt-BR.json b/frontend/src/i18n/pt-BR.json
index cf6bd3ff..0d38a127 100644
--- a/frontend/src/i18n/pt-BR.json
+++ b/frontend/src/i18n/pt-BR.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Sobrescrever arquivo(s) existente(s)",
"Replace Existing File": "Substituir o arquivo existente",
"Do you want to replace the existing file(s)?": "Deseja substituir o(s) arquivo(s) existente(s)?",
+ "Skip existing files": "Ignorar arquivos existentes",
"RenameFileToExisting": "Deseja renomear <b>{{ old }}</b> para <b>{{ new }}</b>?",
"Save": "Salvar",
"Line Wrap": "Quebra de linha automática",
diff --git a/frontend/src/i18n/pt.json b/frontend/src/i18n/pt.json
index da5066d2..53109983 100644
--- a/frontend/src/i18n/pt.json
+++ b/frontend/src/i18n/pt.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Sobrescrever arquivo(s) existente(s)",
"Replace Existing File": "Substituir arquivo existente",
"Do you want to replace the existing file(s)?": "Deseja substituir o(s) arquivo(s) existente(s)?",
+ "Skip existing files": "Ignorar ficheiros existentes",
"RenameFileToExisting": "Deseja renomear <b>{{ old }}</b> para <b>{{ new }}</b>?",
"Save": "Salvar",
"Line Wrap": "Quebra de linha automática",
diff --git a/frontend/src/i18n/ru.json b/frontend/src/i18n/ru.json
index 2bb285c9..a6bc8a78 100644
--- a/frontend/src/i18n/ru.json
+++ b/frontend/src/i18n/ru.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Перезаписать существующие файл(ы)",
"Replace Existing File": "Заменить существующий файл",
"Do you want to replace the existing file(s)?": "Вы хотите заменить существующие файл(ы)?",
+ "Skip existing files": "Пропустить существующие файлы",
"RenameFileToExisting": "Переименовать <b>{{ old }}</b> в <b>{{ new }}</b>?",
"Save": "Сохранить",
"Line Wrap": "Перенос строк",
diff --git a/frontend/src/i18n/tr.json b/frontend/src/i18n/tr.json
index 8cfd4944..5ac46cc3 100644
--- a/frontend/src/i18n/tr.json
+++ b/frontend/src/i18n/tr.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "Mevcut dosya(ları) üzerine yaz",
"Replace Existing File": "Mevcut dosyayı değiştir",
"Do you want to replace the existing file(s)?": "Mevcut dosya(ları) değiştirmek istiyor musunuz?",
+ "Skip existing files": "Mevcut dosyaları atla",
"RenameFileToExisting": "<b>{{ old }}</b> dosyasını <b>{{ new }}</b> olarak yeniden adlandırmak istiyor musunuz?",
"Save": "Kaydet",
"Line Wrap": "Satır kaydırma",
diff --git a/frontend/src/i18n/zh.json b/frontend/src/i18n/zh.json
index db1fe80e..1e8de3bf 100644
--- a/frontend/src/i18n/zh.json
+++ b/frontend/src/i18n/zh.json
@@ -612,6 +612,7 @@
"Overwrite Existing File(s)": "覆盖现有文件",
"Replace Existing File": "替换现有文件",
"Do you want to replace the existing file(s)?": "是否要替换现有文件?",
+ "Skip existing files": "跳过现有文件",
"RenameFileToExisting": "您确定要将 <b>{{ old }}</b> 重命名为 <b>{{ new }}</b> 吗?",
"Save": "保存",
"Line Wrap": "自动换行",