Skip to content

Commit

Permalink
#6385: fix for mime-type detection in ConfigController (#6397)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Jan 15, 2021
1 parent ab8db43 commit 5b85724
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
28 changes: 19 additions & 9 deletions .travis.yml
Expand Up @@ -2,15 +2,25 @@ dist: xenial
language: node_js
node_js:
- 12.13.0
script:
- npm run travis
addons:
firefox: latest
before_install:
# Fixes an issue where the max file watch count is exceeded, triggering ENOSPC
- echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- node -v
- npm -v

jobs:
include:
- language: node_js
node_js: 12.13.0
script:
- npm run travis
addons:
firefox: latest
before_install:
# Fixes an issue where the max file watch count is exceeded, triggering ENOSPC
- echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- node -v
- npm -v

- language: java
jdk: openjdk8
script:
- mvn clean install
branches:
only:
- master
Expand Down
7 changes: 7 additions & 0 deletions backend/pom.xml
Expand Up @@ -21,6 +21,13 @@
<version>2.1</version>
</dependency>

<!-- Mime-Util -->
<dependency>
<groupId>eu.medsea.mimeutil</groupId>
<artifactId>mime-util</artifactId>
<version>2.1.3</version>
</dependency>

<!-- Spring -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
Expand Down
Expand Up @@ -47,6 +47,8 @@
import com.github.fge.jsonpatch.JsonPatch;
import com.github.fge.jsonpatch.JsonPatchException;

import eu.medsea.mimeutil.MimeType;
import eu.medsea.mimeutil.MimeUtil;
import it.geosolutions.mapstore.utils.ResourceUtils;

/**
Expand All @@ -71,6 +73,10 @@ public class Resource {
String type;
File file;
}

static {
MimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.ExtensionMimeDetector");
}

private ObjectMapper jsonMapper = new ObjectMapper();

Expand Down Expand Up @@ -168,7 +174,9 @@ private Resource readResource(String resourceName, boolean applyOverrides, Strin
private Resource readResourceFromFile(File file, boolean applyOverrides, Optional<File> patch) throws IOException {
Resource resource = new Resource();
resource.file = file;
resource.type = Files.probeContentType(Paths.get(file.getAbsolutePath()));

MimeType type = MimeUtil.getMostSpecificMimeType(MimeUtil.getMimeTypes(file));
resource.type = type != null ? type.toString() : null;
try (Stream<String> stream =
Files.lines( Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8); ) {
Properties props = readOverrides();
Expand Down
13 changes: 13 additions & 0 deletions backend/src/main/resources/mime-types.properties
@@ -0,0 +1,13 @@
css=text/css
gif=image/gif
html=text/html
htm=text/html
jpe=image/jpeg
jpeg=image/jpeg
jpg=image/jpeg
js=application/javascript
json=application/json
png=image/png
svg=image/svg+xml
txt=text/plain

0 comments on commit 5b85724

Please sign in to comment.