diff --git a/README.md b/README.md index 8193b09c94cc4aca8efeffc652eab66afeccdfc6..c1ff47b823ea322e6bd78edfa03a692d7a0eac29 100644 --- a/README.md +++ b/README.md @@ -158,12 +158,12 @@ curl -X POST -H "X-Resource-Type: folder" -H "Authorization: Bearer valid-token- - créer fichier : ```shell -curl -X POST -H "X-Resource-Type: file" -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" http://localhost:8080/ftps/mon-ftp/dossier/fichier +curl -X POST -H "X-Resource-Type: file" -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" http://localhost:8080/ftps/mon-ftp/fichier ``` - renommer : ```shell -curl -X PUT -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" -H "Content-Type: text/plain" -d "nouveau_nom" http://localhost:8080/ftps/mon-ftp/dossier/rename +curl -X PUT -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" -H "Content-Type: text/plain" -d "nouveau_nom" http://localhost:8080/ftps/mon-ftp/rename/fichier ``` - supprimer dossier/fichier : diff --git a/src/main/java/fil/sr2/flopbox/FTPResource.java b/src/main/java/fil/sr2/flopbox/FTPResource.java index 3f87922f536a997f3e824253c6f578986ae698b5..e3385d65aafee9560791f1a2ceea349be6d0515b 100644 --- a/src/main/java/fil/sr2/flopbox/FTPResource.java +++ b/src/main/java/fil/sr2/flopbox/FTPResource.java @@ -225,7 +225,7 @@ public class FTPResource { } @PUT - @Path("/{alias}/{path: .+}/rename") + @Path("/{alias}/rename/{path: .+}") @Consumes(MediaType.TEXT_PLAIN) public Response renameResource( @PathParam("alias") String alias, diff --git a/src/main/java/fil/sr2/flopbox/FTPService.java b/src/main/java/fil/sr2/flopbox/FTPService.java index 90fe9e08e1f4c7a2fb0d86f3ab939b8c6a48fd9e..8997b02a3764126b36af0d0c6685f7b5c9d6bb58 100644 --- a/src/main/java/fil/sr2/flopbox/FTPService.java +++ b/src/main/java/fil/sr2/flopbox/FTPService.java @@ -279,9 +279,11 @@ public class FTPService { while ((entry = zis.getNextEntry()) != null) { String entryName = entry.getName(); String fullPath = constructPath(targetPath, entryName); - System.out.println("[DEBUG] Traitement entrée: " + entry.getName() - + " → " + fullPath); - + if (fullPath == null) { + zis.closeEntry(); + continue; // Ignorer l'entrée racine + } + System.out.println("[DEBUG] Traitement entrée: " + entry.getName() + " → " + fullPath); if (entry.isDirectory()) { createDirectories(ftp, fullPath); } else { @@ -300,11 +302,20 @@ public class FTPService { private String constructPath(String basePath, String entryPath) { // Ignorer le premier segment du chemin (dossier racine du ZIP) String[] parts = entryPath.split("/"); - if (parts.length > 1) { - String normalizedEntry = String.join("/", Arrays.copyOfRange(parts, 1, parts.length)); - return basePath.isEmpty() ? normalizedEntry : basePath + "/" + normalizedEntry; + List<String> partsList = new ArrayList<>(); + for (String part : parts) { + if (!part.isEmpty()) { + partsList.add(part); + } } - return entryPath; // Cas où l'entrée est déjà à la racine + if (!partsList.isEmpty()) { + partsList.remove(0); // Retirer le premier segment (racine du ZIP) + } + String normalizedEntry = String.join("/", partsList); + if (normalizedEntry.isEmpty()) { + return null; // Indique une entrée de répertoire racine à ignorer + } + return basePath.isEmpty() ? normalizedEntry : basePath + "/" + normalizedEntry; } private void createParentDirectories(FTPClient ftp, String filePath) throws IOException { @@ -342,12 +353,10 @@ public class FTPService { private void uploadFileEntry(FTPClient ftp, String path, InputStream is) throws IOException, FTPException { - // Supprimer URLDecoder.decode() ! - String decodedPath = path; - + String fileName = path.contains("/") ? path.substring(path.lastIndexOf('/') + 1) : path; try (InputStream bais = is) { - if (!ftp.storeFile(decodedPath, bais)) { - throw new FTPException("Échec upload: " + decodedPath, 500); + if (!ftp.storeFile(fileName, bais)) { + throw new FTPException("Échec upload: " + path, 500); } } }