From 4d10ab0184d3e9beb36aba0dd07489d3c8a910fd Mon Sep 17 00:00:00 2001 From: Leonardo Date: Tue, 24 Sep 2024 21:07:42 -0300 Subject: [PATCH] fix: paths --- .../ifsp/tickets/domain/shared/file/FileContextType.java | 6 +++--- .../com/ifsp/tickets/infra/shared/LocalFileStorage.java | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/domain/src/main/java/br/com/ifsp/tickets/domain/shared/file/FileContextType.java b/domain/src/main/java/br/com/ifsp/tickets/domain/shared/file/FileContextType.java index d0c5b82..7fa39b1 100644 --- a/domain/src/main/java/br/com/ifsp/tickets/domain/shared/file/FileContextType.java +++ b/domain/src/main/java/br/com/ifsp/tickets/domain/shared/file/FileContextType.java @@ -5,9 +5,9 @@ @Getter public enum FileContextType { - EVENT("/events"), - USER("/users"), - EMAIL("/emails"); + EVENT("events/"), + USER("users/"), + EMAIL("emails/"); private final String path; diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/shared/LocalFileStorage.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/shared/LocalFileStorage.java index 550ef3c..d465351 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/shared/LocalFileStorage.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/shared/LocalFileStorage.java @@ -7,12 +7,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import java.io.File; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Optional; @Component @@ -24,7 +22,7 @@ public class LocalFileStorage implements IFileStorage { private String uploadDir; private Path getUploadDir() { - final Path path = Paths.get(rootPath + File.separator + uploadDir); + final Path path = rootPath.resolve(uploadDir); if (Files.notExists(path)) { try { Files.createDirectories(path); @@ -32,12 +30,13 @@ private Path getUploadDir() { log.error("Não foi possível criar o diretório de upload de arquivos", e); } } - return path; + return path.toAbsolutePath(); } public boolean uploadFile(FileContextType contextType, String filename, byte[] aContent, String... extraPath) { try { - final Path path = extraPath.length > 0 ? this.getUploadDir().resolve(contextType.getPath()).resolve(String.join("/", extraPath)) : this.getUploadDir().resolve(contextType.getPath()); + final Path dir = this.getUploadDir(); + final Path path = extraPath.length > 0 ? dir.resolve(contextType.getPath()).resolve(String.join("/", extraPath)) : dir.resolve(contextType.getPath()); if (Files.notExists(path)) Files.createDirectories(path); Files.write(path.resolve(filename), aContent); return true;