|
@@ -1,7 +1,6 @@
|
|
|
package cn.newfeifan.mall.module.infra.controller.app.file;
|
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
-import cn.hutool.core.io.resource.InputStreamResource;
|
|
|
import cn.newfeifan.mall.framework.common.pojo.CommonResult;
|
|
|
import cn.newfeifan.mall.module.infra.controller.app.file.vo.AppFileUploadReqVO;
|
|
|
import cn.newfeifan.mall.module.infra.service.file.FileService;
|
|
@@ -10,7 +9,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.util.StreamUtils;
|
|
@@ -21,11 +19,12 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;
|
|
|
+import static cn.newfeifan.mall.module.infra.enums.AppFileConstants.DOMAIN_LIST;
|
|
|
+import static cn.newfeifan.mall.module.infra.enums.ErrorCodeConstants.URL_DOMAIN_NOT_EXISTS;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLConnection;
|
|
|
|
|
@@ -54,6 +53,11 @@ public class AppFileController {
|
|
|
@GetMapping("/downloadByUrl")
|
|
|
@Operation(summary = "通过链接下载文件流")
|
|
|
public ResponseEntity<ByteArrayResource> downloadByUrl(@RequestParam("fileUrl") String fileUrl) throws Exception {
|
|
|
+
|
|
|
+ if(!checkPrefix(fileUrl)){
|
|
|
+ throw exception(URL_DOMAIN_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
URL url = new URL(fileUrl);
|
|
|
URLConnection connection = url.openConnection();
|
|
@@ -86,6 +90,17 @@ public class AppFileController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean checkPrefix(String fileUrl) {
|
|
|
+ // 遍历DOMAIN_LIST中的每个域名
|
|
|
+ for (String domain : DOMAIN_LIST) {
|
|
|
+ // 检查传入的字符串是否以当前域名为前缀
|
|
|
+ if (fileUrl.startsWith(domain)) {
|
|
|
+ return true; // 如果找到匹配的前缀,返回true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false; // 如果没有找到匹配的前缀,返回false
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|