Skip to content

Commit

Permalink
fix: solved detection of old doc/xls in multiple mimetypes...
Browse files Browse the repository at this point in the history
  • Loading branch information
melistik committed Aug 1, 2023
1 parent e7d853d commit da12f4e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public enum AssetType {
GZIP("gzip", "application/gzip"),
_7z("7z", "application/x-7z-compressed"),
// microsoft office
XLS("xls", "application/msexcel"),
XLS("xls", List.of("application/msexcel", "application/vnd.ms-excel")),
XLSX("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
DOC("doc", "application/msword"),
DOC("doc", List.of("application/msword", "application/vnd.ms-word")),
DOCX("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
PPT("ppt", "application/vnd.ms-powerpoint"),
PPTX("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"),
Expand Down Expand Up @@ -78,7 +78,7 @@ public String getValue() {
}

@Getter
private final String contentType;
private final List<String> contentTypes;

@Getter
private final String fileExtension;
Expand All @@ -87,12 +87,22 @@ public String getValue() {
this(value, contentType, null);
}

AssetType(String value, List<String> contentTypes) {
this.value = value;
this.contentTypes = contentTypes;
this.fileExtension = null;
}

AssetType(String value, String contentType, String fileExtension) {
this.value = value;
this.contentType = contentType;
this.contentTypes = List.of(contentType);
this.fileExtension = fileExtension;
}

public String getContentType() {
return contentTypes.get(0);
}

public static Set<String> getSupportedContentTypes() {
Set<String> result = new HashSet<>();
for (AssetType type : values()) {
Expand All @@ -108,7 +118,7 @@ public static List<AssetType> getAllType() {
public static AssetType findByContentType(String contentType) {
if (contentType != null) {
for (AssetType type : values()) {
if (contentType.equalsIgnoreCase(type.getContentType())) {
if (type.getContentTypes().contains(contentType.toLowerCase())) {
return type;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,44 @@ public void testUploadAvif() {
assertThat(result.getDownload(), startsWith(baseUrl));
}

@SneakyThrows
@Test
public void testUploadXls() {
// given
AssetResource assetResource = new AssetResource(baseUrl);

// when
File uploadFile = resourceLoader.getResource("classpath:assets/sample.xls").getFile();
AssetRead result = assetResource.uploadFile(new FileInputStream(uploadFile), uploadFile.getName());

// then
assertThat(result, notNullValue());
assertThat(result.getType(), equalTo(AssetType.XLS));
assertThat(result.getMeta().getFileSize(), equalTo(25600L));
assertThat(result.getMeta().getResolution(), nullValue());
assertThat(result.getMeta().getOriginalFilename(), equalTo(uploadFile.getName()));
assertThat(result.getDownload(), startsWith(baseUrl));
}

@SneakyThrows
@Test
public void testUploadDoc() {
// given
AssetResource assetResource = new AssetResource(baseUrl);

// when
File uploadFile = resourceLoader.getResource("classpath:assets/sample.doc").getFile();
AssetRead result = assetResource.uploadFile(new FileInputStream(uploadFile), uploadFile.getName());

// then
assertThat(result, notNullValue());
assertThat(result.getType(), equalTo(AssetType.DOC));
assertThat(result.getMeta().getFileSize(), equalTo(22528L));
assertThat(result.getMeta().getResolution(), nullValue());
assertThat(result.getMeta().getOriginalFilename(), equalTo(uploadFile.getName()));
assertThat(result.getDownload(), startsWith(baseUrl));
}

@SneakyThrows
@Test
public void testUploadGlb() {
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ SOFTWARE.
<maven.compiler.target>11</maven.compiler.target>
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>

<spring-boot.version>2.7.9</spring-boot.version>
<spring-boot.version>2.7.13</spring-boot.version>

<commons-rest.version>2.5.4</commons-rest.version>
<guava.version>31.1-jre</guava.version>
<guava.version>32.1.1-jre</guava.version>
<commons-fileupload.version>1.4</commons-fileupload.version>
<commons-io.version>2.11.0</commons-io.version>
<tika-core.version>2.7.0</tika-core.version>
<tika-core.version>2.8.0</tika-core.version>
<thumbnailator.version>0.4.19</thumbnailator.version>
<jacoco.version>0.8.7</jacoco.version>
<colors.version>0.6.0</colors.version>
Expand Down

0 comments on commit da12f4e

Please sign in to comment.