Skip to content

Commit 410409b

Browse files
committed
Remove options from roda-wui.properties to disable opening an HTML file when the mime type is not defined
1 parent afd3bcc commit 410409b

4 files changed

Lines changed: 34 additions & 25 deletions

File tree

roda-ui/roda-wui/src/main/java/org/roda/wui/api/v2/controller/FilesController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,22 @@ public class FilesController implements FileRestService, Exportable {
102102
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(schema = @Schema(implementation = ErrorResponseMessage.class)))})
103103
public ResponseEntity<StreamingResponseBody> previewBinary(
104104
@Parameter(description = "The UUID of the existing file", required = true) @PathVariable(name = "uuid") String fileUUID,
105+
@Parameter(description = "Use to set the content disposition inline") @RequestParam(name = "inline", defaultValue = "true", required = false) boolean inline,
105106
@RequestHeader HttpHeaders headers) {
106107
return requestHandler.processRequest(new RequestHandler.RequestProcessor<ResponseEntity<StreamingResponseBody>>() {
107108
@Override
108109
public ResponseEntity<StreamingResponseBody> process(RequestContext requestContext,
109110
RequestControllerAssistant controllerAssistant) throws RODAException, RESTException {
110-
controllerAssistant.setRelatedObjectId(fileUUID);
111111
controllerAssistant.setParameters(RodaConstants.CONTROLLER_FILE_UUID_PARAM, fileUUID);
112112
List<String> fileFields = new ArrayList<>(RodaConstants.FILE_FIELDS_TO_RETURN);
113113
fileFields.add(RodaConstants.FILE_ISDIRECTORY);
114114
IndexedFile file = indexService.retrieve(IndexedFile.class, fileUUID, fileFields);
115+
controllerAssistant.setRelatedObjectId(file.getAipId());
115116
controllerAssistant.checkObjectPermissions(requestContext.getUser(), file);
116117

117118
RangeConsumesOutputStream stream = filesService.retrieveAIPRepresentationRangeStream(requestContext, file);
118119

119-
return ApiUtils.rangeResponse(headers, stream);
120+
return ApiUtils.rangeResponse(headers, stream, inline);
120121
}
121122
});
122123
}
@@ -136,7 +137,8 @@ public ResponseEntity<StreamingResponseBody> process(RequestContext requestConte
136137
fileFields.add(RodaConstants.FILE_ISDIRECTORY);
137138
IndexedFile file = indexService.retrieve(IndexedFile.class, fileUUID, fileFields);
138139
controllerAssistant.setRelatedObjectId(file.getAipId());
139-
controllerAssistant.setParameters(RodaConstants.CONTROLLER_FILE_UUID_PARAM, fileUUID, RodaConstants.CONTROLLER_FILE_ID_PARAM, file.getId());
140+
controllerAssistant.setParameters(RodaConstants.CONTROLLER_FILE_UUID_PARAM, fileUUID,
141+
RodaConstants.CONTROLLER_FILE_ID_PARAM, file.getId());
140142

141143
controllerAssistant.checkObjectPermissions(requestContext.getUser(), file);
142144

roda-ui/roda-wui/src/main/java/org/roda/wui/api/v2/utils/ApiUtils.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ public static ResponseEntity<StreamingResponseBody> okResponse(StreamResponse st
6464
}
6565

6666
public static ResponseEntity<StreamingResponseBody> rangeResponse(HttpHeaders headers,
67-
RangeConsumesOutputStream consumesOutputStream) {
67+
RangeConsumesOutputStream consumesOutputStream, boolean inline) {
6868
final HttpHeaders responseHeaders = new HttpHeaders();
6969
StreamingResponseBody responseStream;
7070

7171
if (headers.getRange().isEmpty()) {
7272
responseStream = consumesOutputStream::consumeOutputStream;
7373
responseHeaders.add("Content-Type", consumesOutputStream.getMediaType());
74-
responseHeaders.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""
75-
+ URLEncoder.encode(consumesOutputStream.getFileName(), StandardCharsets.UTF_8) + "\"");
74+
responseHeaders.add(HttpHeaders.CONTENT_DISPOSITION, inline ? "inline; " : "attachment; " + "filename=\""
75+
+ URLEncoder.encode(consumesOutputStream.getFileName(), StandardCharsets.UTF_8) + "\"");
7676
responseHeaders.add("Content-Length", String.valueOf(consumesOutputStream.getSize()));
7777

7878
return ResponseEntity.ok().headers(responseHeaders).body(responseStream);
@@ -86,10 +86,10 @@ public static ResponseEntity<StreamingResponseBody> rangeResponse(HttpHeaders he
8686
responseHeaders.add(HttpHeaders.CONTENT_TYPE, consumesOutputStream.getMediaType());
8787
responseHeaders.add(HttpHeaders.CONTENT_LENGTH, contentLength);
8888
responseHeaders.add(HttpHeaders.CONTENT_DISPOSITION,
89-
"inline; filename=\"" + URLEncoder.encode(consumesOutputStream.getFileName(), StandardCharsets.UTF_8) + "\"");
89+
"inline; filename=\"" + URLEncoder.encode(consumesOutputStream.getFileName(), StandardCharsets.UTF_8) + "\"");
9090
responseHeaders.add(HttpHeaders.ACCEPT_RANGES, "bytes");
9191
responseHeaders.add(HttpHeaders.CONTENT_RANGE,
92-
"bytes" + " " + start + "-" + end + "/" + consumesOutputStream.getSize());
92+
"bytes" + " " + start + "-" + end + "/" + consumesOutputStream.getSize());
9393

9494
responseStream = os -> (consumesOutputStream).consumeOutputStream(os, start, end);
9595

@@ -104,6 +104,11 @@ public static ResponseEntity<StreamingResponseBody> rangeResponse(HttpHeaders he
104104
return new ResponseEntity<>(responseStream, responseHeaders, HttpStatus.PARTIAL_CONTENT);
105105
}
106106

107+
public static ResponseEntity<StreamingResponseBody> rangeResponse(HttpHeaders headers,
108+
RangeConsumesOutputStream consumesOutputStream) {
109+
return rangeResponse(headers, consumesOutputStream, false);
110+
}
111+
107112
public static StreamResponse download(RequestContext requestContext, IsRODAObject object, String... pathPartials)
108113
throws GenericException, RequestNotValidException, NotFoundException, AuthorizationDeniedException {
109114
return download(requestContext, object, null, false, pathPartials);

roda-ui/roda-wui/src/main/java/org/roda/wui/common/client/tools/RestUtils.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public static SafeUri createRepresentationDownloadUri(String aipId, String repre
6060
// api/v2/{aip_id}/representations/{representation_id}/binary
6161
StringBuilder b = new StringBuilder();
6262
// base uri
63-
b.append(RodaConstants.API_REST_V2_AIPS).append(URL.encodeQueryString(aipId))
64-
.append(RodaConstants.API_SEP).append(RodaConstants.AIP_REPRESENTATIONS).append(RodaConstants.API_SEP)
63+
b.append(RodaConstants.API_REST_V2_AIPS).append(URL.encodeQueryString(aipId)).append(RodaConstants.API_SEP)
64+
.append(RodaConstants.AIP_REPRESENTATIONS).append(RodaConstants.API_SEP)
6565
.append(URL.encodeQueryString(representationId)).append(RodaConstants.API_REST_V2_DOWNLOAD_HANDLER);
6666

6767
return UriUtils.fromSafeConstant(b.toString());
@@ -72,8 +72,8 @@ public static SafeUri createRepresentationOtherMetadataDownloadUri(String aipId,
7272
// api/v2/aip/{aip_id}/representations/{representation_id}/other-metadata/binary
7373
StringBuilder b = new StringBuilder();
7474
// base uri
75-
b.append(RodaConstants.API_REST_V2_AIPS).append(URL.encodeQueryString(aipId))
76-
.append(RodaConstants.API_SEP).append(RodaConstants.AIP_REPRESENTATIONS).append(RodaConstants.API_SEP)
75+
b.append(RodaConstants.API_REST_V2_AIPS).append(URL.encodeQueryString(aipId)).append(RodaConstants.API_SEP)
76+
.append(RodaConstants.AIP_REPRESENTATIONS).append(RodaConstants.API_SEP)
7777
.append(URL.encodeQueryString(representationId)).append(RodaConstants.API_REST_V2_REPRESENTATION_OTHER_METADATA)
7878
.append(RodaConstants.API_REST_V2_REPRESENTATION_BINARY);
7979

@@ -84,20 +84,22 @@ public static SafeUri createRepresentationOtherMetadataDownloadUri(String aipId,
8484
return UriUtils.fromSafeConstant(b.toString());
8585
}
8686

87-
public static SafeUri createRepresentationFilePreviewUri(String fileUuid, boolean contentDispositionInline) {
87+
public static SafeUri createRepresentationFilePreviewUri(String fileUuid, boolean contentDispositionInline) {
8888
// api/v2/files/{file_uuid}/preview
8989
String b = RodaConstants.API_REST_V2_FILES + URL.encodeQueryString(fileUuid)
90-
+ RodaConstants.API_REST_V2_PREVIEW_HANDLER;
90+
+ RodaConstants.API_REST_V2_PREVIEW_HANDLER + RodaConstants.API_QUERY_START + RodaConstants.API_QUERY_PARAM_INLINE
91+
+ RodaConstants.API_QUERY_ASSIGN_SYMBOL + contentDispositionInline;
9192

9293
return UriUtils.fromSafeConstant(b);
9394
}
9495

95-
public static SafeUri createRepresentationFileDownloadUri(String fileUuid){
96-
// api/v2/files/{file_uuid}/download
97-
StringBuilder b = new StringBuilder();
98-
b.append(RodaConstants.API_REST_V2_FILES).append(URL.encodeQueryString(fileUuid)).append(RodaConstants.API_REST_V2_DOWNLOAD_HANDLER);
96+
public static SafeUri createRepresentationFileDownloadUri(String fileUuid) {
97+
// api/v2/files/{file_uuid}/download
98+
StringBuilder b = new StringBuilder();
99+
b.append(RodaConstants.API_REST_V2_FILES).append(URL.encodeQueryString(fileUuid))
100+
.append(RodaConstants.API_REST_V2_DOWNLOAD_HANDLER);
99101

100-
return UriUtils.fromSafeConstant(b.toString());
102+
return UriUtils.fromSafeConstant(b.toString());
101103
}
102104

103105
public static SafeUri createDipDownloadUri(String dipUUID) {
@@ -120,7 +122,7 @@ public static SafeUri createDipFilePreviewUri(String dipFileUUID, boolean conten
120122
return UriUtils.fromSafeConstant(b.toString());
121123
}
122124

123-
public static SafeUri createDipFileDownloadUri(String dipFileUUID){
125+
public static SafeUri createDipFileDownloadUri(String dipFileUUID) {
124126
// api/v2/dip-files/{file_uuid}/download
125127
StringBuilder b = new StringBuilder();
126128
b.append(RodaConstants.API_REST_V2_DIPFILES).append(URL.encodeQueryString(dipFileUUID))

roda-ui/roda-wui/src/main/resources/config/roda-wui.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ ui.viewers.image.extensions =.gif
23622362

23632363
## Windows Bitmap
23642364
ui.viewers.image.mimetypes = image/bpm
2365-
ui.viewers.image.mimetypes = image/xbpm
2365+
ui.viewers.image.mimetypes = image/x?bpm
23662366
ui.viewers.image.extensions =.bmp
23672367

23682368
## Windows ICO
@@ -2433,10 +2433,10 @@ ui.viewers.text.pronoms = x-fmt/62
24332433

24342434
# HTML
24352435
ui.viewers.html.mimetypes = text/html
2436-
ui.viewers.html.extensions = .html
2437-
ui.viewers.html.pronoms = fmt/99
2438-
ui.viewers.html.pronoms = fmt/100
2439-
ui.viewers.html.pronoms = fmt/471
2436+
#ui.viewers.html.extensions = .html
2437+
#ui.viewers.html.pronoms = fmt/99
2438+
#ui.viewers.html.pronoms = fmt/100
2439+
#ui.viewers.html.pronoms = fmt/471
24402440

24412441
# PDF
24422442

0 commit comments

Comments
 (0)