Fix unsupported theme media type bug

pull/151/head
johnniang 2019-05-09 22:24:54 +08:00
parent 4b890a1627
commit 9bad78d552
3 changed files with 14 additions and 1 deletions

View File

@ -353,7 +353,7 @@ public class ThemeServiceImpl implements ThemeService {
public ThemeProperty upload(MultipartFile file) {
Assert.notNull(file, "Multipart file must not be null");
if (!HaloMediaType.isZipType(file.getContentType())) {
if (!StringUtils.endsWithIgnoreCase(file.getOriginalFilename(), ".zip")) {
throw new UnsupportedMediaTypeException("Unsupported theme media type: " + file.getContentType()).setErrorData(file.getOriginalFilename());
}

View File

@ -70,6 +70,7 @@ public class HaloMediaType extends MediaType {
* @param mediaType media type
* @return true if the given media type is zip type; false otherwise
*/
@Deprecated
public static boolean isZipType(MediaType mediaType) {
if (mediaType == null) {
return false;
@ -84,6 +85,7 @@ public class HaloMediaType extends MediaType {
* @param contentType content type
* @return true if the given content type is zip type; false otherwise
*/
@Deprecated
public static boolean isZipType(String contentType) {
if (StringUtils.isBlank(contentType)) {
return false;

View File

@ -1,7 +1,9 @@
package run.halo.app.model;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.http.MediaType;
import run.halo.app.service.support.HaloMediaType;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
@ -10,6 +12,7 @@ import static org.junit.Assert.*;
* @author johnniang
* @date 3/26/19
*/
@Slf4j
public class MediaTypeTest {
@Test
@ -42,4 +45,12 @@ public class MediaTypeTest {
isInclude = mediaType.includes(MediaType.TEXT_HTML);
assertFalse(isInclude);
}
@Test
public void zipTest() {
MediaType mediaType = MediaType.valueOf("application/x-zip-compressed");
log.debug("Zip type: [{}]", mediaType);
assertFalse(HaloMediaType.isZipType(mediaType));
}
}