mirror of https://github.com/halo-dev/halo
Fix unsupported theme media type bug
parent
4b890a1627
commit
9bad78d552
|
@ -353,7 +353,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
public ThemeProperty upload(MultipartFile file) {
|
public ThemeProperty upload(MultipartFile file) {
|
||||||
Assert.notNull(file, "Multipart file must not be null");
|
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());
|
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
|
* @param mediaType media type
|
||||||
* @return true if the given media type is zip type; false otherwise
|
* @return true if the given media type is zip type; false otherwise
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean isZipType(MediaType mediaType) {
|
public static boolean isZipType(MediaType mediaType) {
|
||||||
if (mediaType == null) {
|
if (mediaType == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -84,6 +85,7 @@ public class HaloMediaType extends MediaType {
|
||||||
* @param contentType content type
|
* @param contentType content type
|
||||||
* @return true if the given content type is zip type; false otherwise
|
* @return true if the given content type is zip type; false otherwise
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean isZipType(String contentType) {
|
public static boolean isZipType(String contentType) {
|
||||||
if (StringUtils.isBlank(contentType)) {
|
if (StringUtils.isBlank(contentType)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package run.halo.app.model;
|
package run.halo.app.model;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
import run.halo.app.service.support.HaloMediaType;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -10,6 +12,7 @@ import static org.junit.Assert.*;
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 3/26/19
|
* @date 3/26/19
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class MediaTypeTest {
|
public class MediaTypeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -42,4 +45,12 @@ public class MediaTypeTest {
|
||||||
isInclude = mediaType.includes(MediaType.TEXT_HTML);
|
isInclude = mediaType.includes(MediaType.TEXT_HTML);
|
||||||
assertFalse(isInclude);
|
assertFalse(isInclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void zipTest() {
|
||||||
|
MediaType mediaType = MediaType.valueOf("application/x-zip-compressed");
|
||||||
|
log.debug("Zip type: [{}]", mediaType);
|
||||||
|
|
||||||
|
assertFalse(HaloMediaType.isZipType(mediaType));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue