提交 9bad78d5 编写于 作者: J johnniang

Fix unsupported theme media type bug

上级 4b890a16
......@@ -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());
}
......
......@@ -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;
......
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));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册