fix des // dans les chemins, check si le dossier existe avant de drop, check si le dossier existe avant d'en creer un nouveau (bouton nouveau)
This commit is contained in:
commit
0fb612c9a5
@ -1,5 +1,4 @@
|
|||||||
<template>
|
<template>
|
||||||
|
|
||||||
<div class="flex flex-col h-full w-full border">
|
<div class="flex flex-col h-full w-full border">
|
||||||
<!-- Breadcrumb -->
|
<!-- Breadcrumb -->
|
||||||
<div class="flex flex-row mt-1 ml-3 items-start container">
|
<div class="flex flex-row mt-1 ml-3 items-start container">
|
||||||
@ -148,7 +147,7 @@ export default {
|
|||||||
NcProgressBar,
|
NcProgressBar,
|
||||||
Delete,
|
Delete,
|
||||||
Pencil,
|
Pencil,
|
||||||
EditFileName
|
EditFileName,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
file: {
|
file: {
|
||||||
@ -230,16 +229,30 @@ export default {
|
|||||||
},
|
},
|
||||||
async createNewFile() {
|
async createNewFile() {
|
||||||
if (!this.newFileName) return;
|
if (!this.newFileName) return;
|
||||||
try {
|
|
||||||
const client = getClient();
|
try {
|
||||||
const filePath = `${this.root_path}${this.current_dir}/${this.newFileName}`;
|
const client = getClient();
|
||||||
await client.createDirectory(filePath, '');
|
let filePath = '';
|
||||||
this.newFileName = '';
|
console.log(this.newFileName)
|
||||||
this.isAddFilePopupVisible = false;
|
if(this.current_dir[this.current_dir.length - 1] === '/') {
|
||||||
await this.fetchFiles();
|
filePath = `${this.root_path}${this.current_dir}${this.newFileName}`;
|
||||||
} catch (error) {
|
}
|
||||||
console.error('Erreur lors de la création du fichier :', error);
|
else{
|
||||||
}
|
filePath = `${this.root_path}${this.current_dir}/${this.newFileName}`;
|
||||||
|
}
|
||||||
|
const alreadyExists = await this.elemtAlreadyExists(filePath);
|
||||||
|
if (!alreadyExists) {
|
||||||
|
await client.createDirectory(filePath, '');
|
||||||
|
this.newFileName = '';
|
||||||
|
this.isAddFilePopupVisible = false;
|
||||||
|
await this.fetchFiles();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
alert(`Vous ne pouvez pas creer le dossier : ${this.newFileName} car un autre dossier porte deja le meme nom.`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur lors de la création du fichier :', error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
toggleAddFilePopup() {
|
toggleAddFilePopup() {
|
||||||
this.isAddFilePopupVisible = !this.isAddFilePopupVisible;
|
this.isAddFilePopupVisible = !this.isAddFilePopupVisible;
|
||||||
@ -290,9 +303,17 @@ export default {
|
|||||||
},
|
},
|
||||||
async moveFilesOfFolder(folder, parentPath) {
|
async moveFilesOfFolder(folder, parentPath) {
|
||||||
await this.createFolder(folder, parentPath);
|
await this.createFolder(folder, parentPath);
|
||||||
|
const checkChildrenInChildren = (folder) => {
|
||||||
|
let total = folder.children.length;
|
||||||
|
for (const child of folder.children) {
|
||||||
|
if (child.isDirectory) {
|
||||||
|
total += checkChildrenInChildren(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
};
|
||||||
|
|
||||||
const fileProgress = 100 / folder.children.length
|
const progressSteps = Math.floor(100 / checkChildrenInChildren(folder));
|
||||||
const progressSteps = Math.floor(fileProgress);
|
|
||||||
|
|
||||||
for (const child of folder.children) {
|
for (const child of folder.children) {
|
||||||
this.transferProgress += progressSteps;
|
this.transferProgress += progressSteps;
|
||||||
@ -311,17 +332,29 @@ export default {
|
|||||||
const client = getClient();
|
const client = getClient();
|
||||||
// Assurez-vous que le chemin parent est correctement formaté
|
// Assurez-vous que le chemin parent est correctement formaté
|
||||||
|
|
||||||
const fullPath = `${this.root_path}${this.current_dir}${parentPath}/${file.name}`;
|
let fullPath = '';
|
||||||
|
if(parentPath[parentPath.length - 1] === '/') {
|
||||||
|
fullPath = `${this.root_path}${this.current_dir}${parentPath}${file.name}`;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
fullPath = `${this.root_path}${this.current_dir}${parentPath}/${file.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (ArrayBuffer.isView(file.content)) {
|
if (ArrayBuffer.isView(file.content)) {
|
||||||
file.content = Buffer.from(file.content);
|
file.content = Buffer.from(file.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const alreadyExists = await this.elemtAlreadyExists(fullPath);
|
||||||
|
if(!alreadyExists) {
|
||||||
|
// Évitez les chemins incorrects en utilisant `path.normalize` si disponible
|
||||||
|
await client.putFileContents(fullPath, file.content);
|
||||||
|
|
||||||
// Évitez les chemins incorrects en utilisant `path.normalize` si disponible
|
// Recharge les fichiers après l'opération
|
||||||
await client.putFileContents(fullPath, file.content);
|
await this.fetchFiles();
|
||||||
|
}
|
||||||
// Recharge les fichiers après l'opération
|
else{
|
||||||
await this.fetchFiles();
|
alert(`Vous ne pouvez pas deposer le fichier : ${file.name} car un autre fichier porte deja le meme nom.`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur lors du déplacement du fichier:', error);
|
console.error('Erreur lors du déplacement du fichier:', error);
|
||||||
}
|
}
|
||||||
@ -329,11 +362,22 @@ export default {
|
|||||||
async createFolder(folder, parentPath) {
|
async createFolder(folder, parentPath) {
|
||||||
try {
|
try {
|
||||||
const client = getClient();
|
const client = getClient();
|
||||||
|
let fullPath = '';
|
||||||
const fullPath = `${this.root_path}${this.current_dir}${parentPath}/${folder.name}/`;
|
if(parentPath[parentPath.length - 1] === '/') {
|
||||||
|
fullPath = `${this.root_path}${this.current_dir}${parentPath}${folder.name}`;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
fullPath = `${this.root_path}${this.current_dir}${parentPath}/${folder.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
await client.createDirectory(fullPath);
|
const alreadyExists = await this.elemtAlreadyExists(fullPath);
|
||||||
await this.fetchFiles();
|
if(!alreadyExists) {
|
||||||
|
await client.createDirectory(fullPath);
|
||||||
|
await this.fetchFiles();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
alert(`Vous ne pouvez pas deposer le dossier : ${folder.name} car un autre dossier porte deja le meme nom.`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur lors de la création du dossier :', error);
|
console.error('Erreur lors de la création du dossier :', error);
|
||||||
}
|
}
|
||||||
@ -395,9 +439,13 @@ export default {
|
|||||||
await this.fetchFiles();
|
await this.fetchFiles();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async elemtAlreadyExists(name){
|
/**
|
||||||
|
* Check si un fichier ou un dossier existe deja sur le serveur
|
||||||
|
* @param path le chemin du fichier/dossier
|
||||||
|
*/
|
||||||
|
async elemtAlreadyExists(path){
|
||||||
const client = getClient();
|
const client = getClient();
|
||||||
let exists = await client.exists(name);
|
let exists = await client.exists(path);
|
||||||
|
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user