|
@@ -2,12 +2,15 @@ package org.hswebframework.web.file;
|
|
|
|
|
|
import lombok.Getter;
|
|
import lombok.Getter;
|
|
import lombok.Setter;
|
|
import lombok.Setter;
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
import org.hswebframework.utils.time.DateFormatter;
|
|
import org.hswebframework.utils.time.DateFormatter;
|
|
import org.hswebframework.web.id.IDGenerator;
|
|
import org.hswebframework.web.id.IDGenerator;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
@Getter
|
|
@Getter
|
|
@Setter
|
|
@Setter
|
|
@@ -18,6 +21,47 @@ public class FileUploadProperties {
|
|
|
|
|
|
private String staticLocation = "/static";
|
|
private String staticLocation = "/static";
|
|
|
|
|
|
|
|
+ private Set<String> allowFiles;
|
|
|
|
+
|
|
|
|
+ private Set<String> denyFiles;
|
|
|
|
+
|
|
|
|
+ private Set<String> allowMediaType;
|
|
|
|
+
|
|
|
|
+ private Set<String> denyMediaType;
|
|
|
|
+
|
|
|
|
+ public boolean denied(String name, MediaType mediaType) {
|
|
|
|
+ String suffix = name.contains(".") ? name.substring(name.lastIndexOf(".") + 1) : "";
|
|
|
|
+ boolean defaultDeny = false;
|
|
|
|
+ if (CollectionUtils.isNotEmpty(denyFiles)) {
|
|
|
|
+ if (denyFiles.contains(suffix)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ defaultDeny = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(allowFiles)) {
|
|
|
|
+ if (allowFiles.contains(suffix)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ defaultDeny = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(denyMediaType)) {
|
|
|
|
+ if (denyMediaType.contains(mediaType.toString())) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ defaultDeny = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(allowMediaType)) {
|
|
|
|
+ if (allowMediaType.contains(mediaType.toString())) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ defaultDeny = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return defaultDeny;
|
|
|
|
+ }
|
|
|
|
|
|
public StaticFileInfo createStaticSavePath(String name) {
|
|
public StaticFileInfo createStaticSavePath(String name) {
|
|
String fileName = IDGenerator.SNOW_FLAKE_STRING.generate();
|
|
String fileName = IDGenerator.SNOW_FLAKE_STRING.generate();
|
|
@@ -38,7 +82,7 @@ public class FileUploadProperties {
|
|
|
|
|
|
@Getter
|
|
@Getter
|
|
@Setter
|
|
@Setter
|
|
- public class StaticFileInfo {
|
|
|
|
|
|
+ public static class StaticFileInfo {
|
|
private String savePath;
|
|
private String savePath;
|
|
|
|
|
|
private String location;
|
|
private String location;
|