Skip to content

Commit

Permalink
tentative route recuperation fichier.bad
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelQuetin committed Nov 8, 2024
1 parent aa37fa1 commit f17cb66
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/fr/abes/logskbart/controller/LogsController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package fr.abes.logskbart.controller;

import fr.abes.logskbart.dto.LigneLogDto;
import fr.abes.logskbart.dto.LogWebDto;
import fr.abes.logskbart.entity.LogKbart;
import fr.abes.logskbart.exception.EmptyFileException;
import fr.abes.logskbart.service.LogsService;
import fr.abes.logskbart.utils.UtilsMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -21,10 +20,11 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Tag(name = "Logskbart-api localhost", description = "Logskbart localhost managements APIs")
@RestController
Expand Down Expand Up @@ -66,4 +66,16 @@ public ResponseEntity<InputStreamResource> getLogsFromPackageAndDate(@PathVariab
.body(new InputStreamResource(fs));

}

@GetMapping(value = "/file/{filename}")
public ResponseEntity<Resource> downloadFile(@PathVariable("filename") String filename) throws FileNotFoundException, MalformedURLException {
Path pathOf = Path.of("tempLog" + File.separator + filename);
Resource resource = new UrlResource(pathOf.toUri());
if (resource.exists() && resource.isReadable()) {
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=\"" + resource.getFilename() + "\"")
.body(resource);
} else {
throw new FileNotFoundException("Le fichier est introuvable :"+ filename);
}}
}

0 comments on commit f17cb66

Please sign in to comment.