reparation drag and drop zip

This commit is contained in:
Alexandre_BRAVO
2024-11-21 15:04:28 +01:00
parent 8961cdb2a0
commit 091453e0e5
5 changed files with 303 additions and 300 deletions

View File

@ -212,34 +212,17 @@ export default {
event.preventDefault();
try {
const moveFilesOfFolder = async (folder) => {
await this.createFolder(folder);
for (const child of folder.children) {
if (child.isDirectory) {
await moveFilesOfFolder(child);
} else {
if (child.content && typeof child.content.arrayBuffer === 'function') {
child.content = await child.content.arrayBuffer();
}
await this.moveFileToTarget(child);
}
}
};
this.isTransfering = true;
const file = this.file;
if (!file) return;
console.log('Fichier déposé :', file);
if (file.isDirectory) {
await moveFilesOfFolder(file);
await this.moveFilesOfFolder(file,'');
} else {
if (file.content && typeof file.content.arrayBuffer === 'function') {
file.content = await file.content.arrayBuffer();
}
await this.moveFileToTarget(file);
await this.moveFileToTarget(file, '');
}
this.isTransfering = false;
@ -249,12 +232,26 @@ export default {
this.isTransfering = false;
}
},
async moveFileToTarget(file) {
async moveFilesOfFolder(folder, parentPath) {
await this.createFolder(folder, parentPath);
for (const child of folder.children) {
if (child.isDirectory) {
await this.moveFilesOfFolder(child, parentPath + child.parentPath + '/');
} else {
if (child.content && typeof child.content.arrayBuffer === 'function') {
child.content = await child.content.arrayBuffer();
}
await this.moveFileToTarget(child, parentPath + child.parentPath + '/');
}
}
},
async moveFileToTarget(file, parentPath) {
try {
const client = getClient();
// Assurez-vous que le chemin parent est correctement formaté
const parentPath = file.parentPath ? `${file.parentPath}/` : '';
const fullPath = `${this.root_path}${this.current_dir}${parentPath}${file.name}`;
if (ArrayBuffer.isView(file.content)) {
@ -270,13 +267,11 @@ export default {
console.error('Erreur lors du déplacement du fichier:', error);
}
},
async createFolder(folder) {
async createFolder(folder, parentPath) {
try {
const client = getClient();
// Assurez-vous que le chemin parent est correctement formaté
const parentPath = folder.parentPath ? `${folder.parentPath}/` : '';
const fullPath = `${this.root_path}${this.current_dir}${parentPath}${folder.name}/`;
const fullPath = `${this.root_path}${this.current_dir}${parentPath}/${folder.name}/`;
await client.createDirectory(fullPath);
await this.fetchFiles();

View File

@ -163,7 +163,7 @@ export default {
content: isDirectory ? null : '', // Initialiser 'content' pour les fichiers
children: isDirectory ? [] : null,
//remove the name of the file from the path
parentPath: pathParts.slice(0, i).join('/'),
parentPath: i > 0 ? pathParts[i - 1] : '',
unzip: promise
};
currentLevel.push(existing);
@ -208,7 +208,6 @@ export default {
this.$set(this.folderMap, file.fullPath, !currentState);
},
async onDragStart(file) {
console.log('Drag start', file);
const getFilesFromFolder = (folder) => {
const files = [];