From 7766299eb7586b72b9a3370e23509523cc0be0c3 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Mon, 11 Mar 2024 17:03:33 +0100 Subject: [PATCH] correction anthoniesque --- .../b97fdd51-c4a7-4c13-b70c-4b91eb0b3179.png | Bin 11586 -> 0 bytes .../Clyde/EndPoints/StorageController.java | 8 ++-- .../Clyde/Services/StorageService.java | 42 +++++------------- .../ovh/herisson/Clyde/Tables/FileType.java | 8 ++++ .../herisson/Clyde/Tables/StorageFile.java | 14 +++++- .../java/ovh/herisson/Clyde/Tables/User.java | 3 +- 6 files changed, 38 insertions(+), 37 deletions(-) delete mode 100644 backend/cdn/b97fdd51-c4a7-4c13-b70c-4b91eb0b3179.png create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/FileType.java diff --git a/backend/cdn/b97fdd51-c4a7-4c13-b70c-4b91eb0b3179.png b/backend/cdn/b97fdd51-c4a7-4c13-b70c-4b91eb0b3179.png deleted file mode 100644 index 0ad7d033c5618af21cd4e6c19c36845a03aafb81..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11586 zcmeHMi9gi&|No%vvXY2$w%Q_Lk`A}N<%l-cu}GMfMeZ}?8g@I}YOQoIO02a^SV@u@ z6=sW!SoalT$T5Z)#*EDO^;Y})6Mm1!@A0EN#>{+<_xp7`pU>CxllZ-bsmNC8tr&)h zn4LDV#;~shF-)+1^G5jOtSq4cUiP@1wmyqtk^3+#?iUPO=ELhGhFv;@VIMDGn9gks zlM471-(UjAZgf3kYJ~C8zx%a?8Su%Lz|-eKFicn+{R&`rvv*;bYOI;je{3UqX9muv zWG|iLFzGq3S|VvRi;<%<xT`K?JAM?^5 zZ86BDWfp`EQ7=E+Tgx5KS+X}WIu47&;+#o8eTDug<86sYuQ%ehZ$__MHm|>3kH&g2 ztoOn?6s#lRIuib0MM9zb%3IF>h{YoDb{mo`w)7w{DG8cDW>zNTl0$?! zQeHwr!sO&6r*?=}%UPitD%i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U{8`MsETrMnsUSE6d=pHBzZ=G@`z)#{A2nOAteVT7?0#=bUJSc(%!}S_qL~N#B+Ks2jloYC=dJ71iRV0@%|Ch*@0tMAYaHMYg?{e=QyGXGG_) zsX@b&FNN_pYv(@XDsKdr^j`_J?;uiCaRZiL9;LzA@N@da`djp@aXlLA#jxHBpP#$0 z_riKFtoOotFZ^%P;;KUE>(&d^IAKlby&a*(4)EX1M8`7N%iTZp$55{Te@x?w!!!fF i-RACK=5h8crUHL&hF|p4W|M(l%#1CJ9-X}K^M3(`gwB8f diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/StorageController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/StorageController.java index 21fabcc..2a36657 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/StorageController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/StorageController.java @@ -7,8 +7,10 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import ovh.herisson.Clyde.Services.StorageService; import org.springframework.core.io.Resource; +import ovh.herisson.Clyde.Tables.FileType; @RestController +@CrossOrigin(origins = "http://localhost:5173") public class StorageController { private final StorageService storageServ; @@ -18,10 +20,10 @@ public class StorageController { } - @PostMapping("/upload") - public ResponseEntity handleFileUpload(@RequestParam("file") MultipartFile file) { + @PostMapping("/upload/{fileType}") + public ResponseEntity handleFileUpload(@RequestParam("file") MultipartFile file, @PathVariable FileType fileType) { - String path = storageServ.store(file); + String path = storageServ.store(file,fileType); if (path == null) return new ResponseEntity<>("issue with the file storage", HttpStatus.BAD_REQUEST); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java index 1fc9b65..77dff70 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/StorageService.java @@ -4,6 +4,7 @@ import org.springframework.core.io.UrlResource; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import ovh.herisson.Clyde.Repositories.FileRepository; +import ovh.herisson.Clyde.Tables.FileType; import ovh.herisson.Clyde.Tables.StorageFile; import java.io.IOException; import org.springframework.core.io.Resource; @@ -26,53 +27,30 @@ public class StorageService { } - public String store(MultipartFile file) { - UUID uuid = UUID.randomUUID(); - String stringUuid = uuid.toString() + "." + file.getContentType().split("/",2)[1]; + public String store(MultipartFile file, FileType fileType) { + if (file.getOriginalFilename().isEmpty()){return null;} + + UUID uuid = UUID.randomUUID(); + String stringUuid = uuid + "." + file.getOriginalFilename().split("\\.",2)[1]; try { if (file.isEmpty()) { return null; } - Path destinationFile = this.rootLocation.resolve(Paths.get(stringUuid)).toAbsolutePath(); - - if (!destinationFile.getParent().equals(this.rootLocation.toAbsolutePath())) { - return null;} + Path destinationFile = this.rootLocation.resolve(Paths.get(stringUuid)); Files.copy(file.getInputStream(), destinationFile,StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { - e.printStackTrace(); return null; } String url = this.rootLocation.resolve(Paths.get(Objects.requireNonNull(stringUuid))) - .normalize().toAbsolutePath().toString(); - System.out.println(url); - fileRepo.save(new StorageFile(file.getName(),url)); + .normalize().toString(); + + fileRepo.save(new StorageFile(file.getName(),url, fileType)); return url; } - - public Path load(String filename) { - return rootLocation.resolve(filename); - } - - public Resource loadAsResource(String filename) { - try { - Path file = load(filename); - Resource resource = new UrlResource(file.toUri()); - if (resource.exists() || resource.isReadable()) { - return resource; - } - else {return null; - } - } - catch (Exception e) { - e.printStackTrace(); - return null; - } - } - } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/FileType.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/FileType.java new file mode 100644 index 0000000..18ce1be --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/FileType.java @@ -0,0 +1,8 @@ +package ovh.herisson.Clyde.Tables; + +public enum FileType { + + ProfilePicture, + + EducationCertificate +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/StorageFile.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/StorageFile.java index 97c1d30..a96d0ec 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/StorageFile.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/StorageFile.java @@ -17,9 +17,13 @@ public class StorageFile { private String url; - public StorageFile(String name, String url){ + private FileType fileType; + + + public StorageFile(String name, String url, FileType fileType){ this.name = name; this.url = url; + this.fileType = fileType; } public StorageFile(){} @@ -48,4 +52,12 @@ public class StorageFile { public void setUrl(String url) { this.url = url; } + + public FileType getFileType() { + return fileType; + } + + public void setFileType(FileType fileType) { + this.fileType = fileType; + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java index 0752014..101ec9e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -24,7 +24,8 @@ public class User { private ovh.herisson.Clyde.Tables.Role role; private String password; public User(String lastName, String firstName, String email, String address, - String country, Date birthDate, String profilePictureUrl, Role role, String password){ + String country, Date birthDate, String profilePictureUrl, Role role, String password) + { this.lastName = lastName; this.firstName = firstName; this.email = email;