Skip to content

Commit

Permalink
Add file download name with timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
clemens-tolboom committed Mar 7, 2024
1 parent 747ab04 commit 03914d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ResponseEntity<Resource> createDownloadFile(String file_id) {
HttpHeaders headers = new HttpHeaders();
headers.add(
HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"" + insightService.getFileName(file_id) + "\"");
"attachment; filename=\"" + insightService.getDownloadName(file_id) + ".txt\"");
headers.add(HttpHeaders.CONTENT_TYPE, "text/text");
return new ResponseEntity<>(inputStreamResource, headers, OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public String getFileName(String file_id) {
return file_id;
}

public String getDownloadName(String file_id) {
String requestTime = getServerTime().replace(" ", "T").replace(":", "").replace("-", "");

InsightServiceFiles c = InsightServiceFiles.getConstantByKey(file_id);
if (!(c == null)) {
return c.getDownloadName() + "-" + requestTime;
}
return file_id;
}

public FileDetails fileDetails(String file_id, int pageNum, int pageSize, String direction) {
InsightServiceFiles insightServiceFiles = InsightServiceFiles.getConstantByKey(file_id);
if (!(insightServiceFiles == null)) {
Expand All @@ -92,17 +102,19 @@ public FileInputStream downloadFile(String file_id) {
}

enum InsightServiceFiles {
AUDIT_FILE("AUDIT_FILE", MediaType.APPLICATION_NDJSON_VALUE, "Audit file"),
LOG_FILE("LOG_FILE", MediaType.TEXT_PLAIN_VALUE, "Log file");
AUDIT_FILE("AUDIT_FILE", MediaType.APPLICATION_NDJSON_VALUE, "Audit file", "armadillo-audit"),
LOG_FILE("LOG_FILE", MediaType.TEXT_PLAIN_VALUE, "Log file", "armadillo-log");

private final String key;
private final String contentType;
private final String displayName;
private final String downloadName;

InsightServiceFiles(String key, String contentType, String displayName) {
InsightServiceFiles(String key, String contentType, String displayName, String downloadName) {
this.key = key;
this.contentType = contentType;
this.displayName = displayName;
this.downloadName = downloadName;
}

public String getKey() {
Expand All @@ -117,6 +129,10 @@ public String getDisplayName() {
return displayName;
}

public String getDownloadName() {
return downloadName;
}

public static boolean hasKey(String key) {
for (InsightServiceFiles constant : InsightServiceFiles.values()) {
if (constant.getKey().equals(key)) {
Expand Down

0 comments on commit 03914d5

Please sign in to comment.