Skip to content
Snippets Groups Projects
Commit 7775930f authored by Fabio Vandewaeter's avatar Fabio Vandewaeter
Browse files

fix commande tree

parent 97c35c7d
Branches
No related tags found
No related merge requests found
...@@ -331,6 +331,8 @@ public class CommandLineInterface { ...@@ -331,6 +331,8 @@ public class CommandLineInterface {
try { try {
JsonNode tree = client.fetchFtpTree(alias, path); JsonNode tree = client.fetchFtpTree(alias, path);
// System.out.println(objectMapper.readTree(response.body()));
System.out.println(tree + "\n");
displayTree(tree, 0); displayTree(tree, 0);
System.out.println("Arborescence récupérée avec succès."); System.out.println("Arborescence récupérée avec succès.");
} catch (Exception e) { } catch (Exception e) {
...@@ -348,28 +350,25 @@ public class CommandLineInterface { ...@@ -348,28 +350,25 @@ public class CommandLineInterface {
private void displayTree(JsonNode node, int level) { private void displayTree(JsonNode node, int level) {
String indent = " ".repeat(level); String indent = " ".repeat(level);
// Affichage des dossiers // Affichage des éléments dans 'children'
if (node.has("directories") && node.get("directories").isArray()) { if (node.has("children") && node.get("children").isArray()) {
for (JsonNode dir : node.get("directories")) { for (JsonNode child : node.get("children")) {
String dirName = dir.get("name").asText(); String childName = child.get("name").asText();
System.out.println(indent + "📁 " + dirName); boolean isDirectory = child.get("isDirectory").asBoolean();
// Si on a des informations sur le contenu du dossier if (isDirectory) {
if (dir.has("content")) { System.out.println(indent + "📁 " + childName);
displayTree(dir.get("content"), level + 1); // Si le répertoire a des enfants, on les affiche aussi
if (child.has("children")) {
displayTree(child, level + 1);
}
} else {
// Si c'est un fichier
long fileSize = 0; // Si le size est disponible, vous pouvez l'ajouter
System.out.println(indent + "📄 " + childName + " (" + formatSize(fileSize) + ")");
} }
} }
} }
// Affichage des fichiers
if (node.has("files") && node.get("files").isArray()) {
for (JsonNode file : node.get("files")) {
String fileName = file.get("name").asText();
long fileSize = file.has("size") ? file.get("size").asLong() : 0;
System.out.println(indent + "📄 " + fileName + " (" + formatSize(fileSize) + ")");
}
}
} }
/** /**
......
...@@ -205,7 +205,7 @@ public class FlopBoxClient { ...@@ -205,7 +205,7 @@ public class FlopBoxClient {
String encodedPath = path.isEmpty() ? "" : "/" + path; String encodedPath = path.isEmpty() ? "" : "/" + path;
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(flopboxUrl + "/ftps/list/" + alias + encodedPath + "/")) .uri(URI.create(flopboxUrl + "/ftps/list/" + alias + encodedPath))
.header("Authorization", "Bearer " + authToken) .header("Authorization", "Bearer " + authToken)
.header("X-FTP-User", ftpUser) .header("X-FTP-User", ftpUser)
.header("X-FTP-Pass", ftpPassword) .header("X-FTP-Pass", ftpPassword)
...@@ -214,9 +214,7 @@ public class FlopBoxClient { ...@@ -214,9 +214,7 @@ public class FlopBoxClient {
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(URI.create(flopboxUrl + "/ftps/list/" + alias + encodedPath + "/")); System.out.println(URI.create(flopboxUrl + "/ftps/list/" + alias + encodedPath));
System.out.println(response);
System.out.println(objectMapper.readTree(response.body()));
if (response.statusCode() != 200) { if (response.statusCode() != 200) {
throw new IOException("Erreur lors de la récupération de l'arborescence: " + response.statusCode()); throw new IOException("Erreur lors de la récupération de l'arborescence: " + response.statusCode());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment