mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
chore(v0.11): 全路径纳入版本库与走查整改
- .gitignore:显式放行全部 maven-*、scripts、dev-support、frontend、反1、artifacts、历史导出目录 - 新增跟踪:device-manager/device-sdk/legacy-public、davinci-manager、cwos-*、cwos-resource 等源码与附属资源 - davinci FileStorageManagerImpl:Feign Response 关闭、绝对 URL 拉流 SSRF 校验(协议/主机/解析地址) - davinci OuterCallFeignClient:补充契约说明 - cwos-common-aks AksConstant:final 类 + 私有构造防误实例化 - device-manager DeviceConstant:沿用 DEFAULT_APPLICATIONID 拼写修正 Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.cloudwalk.intelligent</groupId>
|
||||
<artifactId>cloudwalk-intelligent-davinci-manager</artifactId>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>davinci-manager-common</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>davinci-manager-common</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package cn.cloudwalk.intelligent.davinci.common.exception;
|
||||
|
||||
public class DavinciServiceException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String code;
|
||||
|
||||
public DavinciServiceException(String code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package cn.cloudwalk.intelligent.davinci.common.result;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DavinciResult<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private boolean success;
|
||||
private String code;
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.cloudwalk.intelligent</groupId>
|
||||
<artifactId>cloudwalk-intelligent-davinci-manager</artifactId>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>davinci-manager-storage</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>davinci-manager-storage</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.cloudwalk.intelligent</groupId>
|
||||
<artifactId>davinci-manager-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign.form</groupId>
|
||||
<artifactId>feign-form</artifactId>
|
||||
<version>${feign-form.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign.form</groupId>
|
||||
<artifactId>feign-form-spring</artifactId>
|
||||
<version>${feign-form.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.bean.file.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class FileRemoveDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5375408551667275621L;
|
||||
|
||||
private List<String> fileList;
|
||||
|
||||
public List<String> getFileList() {
|
||||
return fileList;
|
||||
}
|
||||
|
||||
public void setFileList(List<String> fileList) {
|
||||
this.fileList = fileList;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.bean.part.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PartFinishDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6084049403163053112L;
|
||||
|
||||
private String uploadId;
|
||||
private Long fileSize;
|
||||
private String filePath;
|
||||
private Integer returnType = Integer.valueOf(0);
|
||||
|
||||
public String getUploadId() {
|
||||
return uploadId;
|
||||
}
|
||||
|
||||
public void setUploadId(String uploadId) {
|
||||
this.uploadId = uploadId;
|
||||
}
|
||||
|
||||
public Long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
public void setFileSize(Long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public Integer getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
public void setReturnType(Integer returnType) {
|
||||
this.returnType = returnType;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.bean.part.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PartInitDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5411973046504674893L;
|
||||
|
||||
private String fileName;
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.bean.part.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PartInitResultDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4514634072455987454L;
|
||||
|
||||
private String filePath;
|
||||
private String uploadId;
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getUploadId() {
|
||||
return uploadId;
|
||||
}
|
||||
|
||||
public void setUploadId(String uploadId) {
|
||||
this.uploadId = uploadId;
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.feign;
|
||||
|
||||
import cn.cloudwalk.intelligent.davinci.common.result.DavinciResult;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.file.dto.FileRemoveDTO;
|
||||
import feign.Response;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface FileManagerFeign {
|
||||
|
||||
String DEFAULT_MODULE_CATEGORY = "default";
|
||||
|
||||
@RequestMapping(value = {"/default/fileUpload"}, method = {RequestMethod.POST}, consumes = {"multipart/form-data"})
|
||||
DavinciResult<String> fileUpload(@RequestPart("file") MultipartFile file);
|
||||
|
||||
@RequestMapping(value = {"/{moduleCategory}/fileUpload"}, method = {RequestMethod.POST}, consumes = {"multipart/form-data"})
|
||||
DavinciResult<String> fileUpload(
|
||||
@PathVariable("moduleCategory") String moduleCategory, @RequestPart("file") MultipartFile file);
|
||||
|
||||
@RequestMapping(value = {"/default/bigFileUpload"}, method = {RequestMethod.POST}, consumes = {"multipart/form-data"})
|
||||
DavinciResult<String> bigFileUpload(@RequestPart("file") MultipartFile file);
|
||||
|
||||
@RequestMapping(value = {"/{moduleCategory}/bigFileUpload"}, method = {RequestMethod.POST}, consumes = {"multipart/form-data"})
|
||||
DavinciResult<String> bigFileUpload(
|
||||
@PathVariable("moduleCategory") String moduleCategory, @RequestPart("file") MultipartFile file);
|
||||
|
||||
@RequestMapping(value = {"/imgByPath"}, method = {RequestMethod.GET})
|
||||
Response fileDownload(@RequestParam("path") String path);
|
||||
|
||||
@RequestMapping(value = {"/default/getFileData"}, method = {RequestMethod.POST})
|
||||
DavinciResult<String> getFileData(@RequestParam("path") String path);
|
||||
|
||||
@RequestMapping(value = {"/remove/images"}, method = {RequestMethod.POST})
|
||||
DavinciResult<List<String>> remove(@RequestBody FileRemoveDTO dto);
|
||||
|
||||
@Component
|
||||
class FileManagerFeignClientFallback implements FileManagerFeign {
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> fileUpload(MultipartFile file) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,模块文件上传接口异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> fileUpload(String moduleCategory, MultipartFile file) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,模块文件上传接口异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> bigFileUpload(MultipartFile file) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,大文件上传接口异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> bigFileUpload(String moduleCategory, MultipartFile file) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,大文件上传接口异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response fileDownload(String path) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,获取文件流接口异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> getFileData(String path) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,获取获取文件Base64内容接口异常");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<List<String>> remove(FileRemoveDTO dto) {
|
||||
throw new RuntimeException("调用Davinci-portal服务,删除文件接口异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.feign;
|
||||
|
||||
import cn.cloudwalk.intelligent.davinci.common.result.DavinciResult;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartFinishDTO;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartInitDTO;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartInitResultDTO;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface FilePartFeign {
|
||||
|
||||
@RequestMapping(value = {"/init"}, method = {RequestMethod.POST})
|
||||
DavinciResult<PartInitResultDTO> init(@RequestBody PartInitDTO paramPartInitDTO);
|
||||
|
||||
@RequestMapping(
|
||||
value = {"/append"},
|
||||
method = {RequestMethod.POST},
|
||||
consumes = {"multipart/form-data"})
|
||||
DavinciResult<PartInitResultDTO> append(
|
||||
@RequestParam("filePath") String paramString1,
|
||||
@RequestParam("partNumber") Integer paramInteger,
|
||||
@RequestParam("uploadId") String paramString2,
|
||||
@RequestPart("file") MultipartFile paramMultipartFile);
|
||||
|
||||
@RequestMapping(value = {"/finish"}, method = {RequestMethod.POST})
|
||||
DavinciResult<String> finish(@RequestBody PartFinishDTO paramPartFinishDTO);
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.feign;
|
||||
|
||||
import feign.RequestLine;
|
||||
import feign.Response;
|
||||
|
||||
public interface OuterCallFeignClient {
|
||||
|
||||
/** 与动态 {@code target(…, url)} 组合;{@code url} 须为完整可 GET 的资源地址(由上层做 SSRF 校验)。 */
|
||||
@RequestLine("GET ")
|
||||
Response downLoad();
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.manager;
|
||||
|
||||
import cn.cloudwalk.intelligent.davinci.common.exception.DavinciServiceException;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartFinishDTO;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartInitDTO;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartInitResultDTO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface FilePartManager {
|
||||
|
||||
PartInitResultDTO init(PartInitDTO paramPartInitDTO) throws DavinciServiceException;
|
||||
|
||||
PartInitResultDTO append(
|
||||
String paramString1, Integer paramInteger, String paramString2, MultipartFile paramMultipartFile)
|
||||
throws DavinciServiceException;
|
||||
|
||||
String finish(PartFinishDTO paramPartFinishDTO) throws DavinciServiceException;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.manager;
|
||||
|
||||
import cn.cloudwalk.intelligent.davinci.common.exception.DavinciServiceException;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.file.dto.FileRemoveDTO;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface FileStorageManager {
|
||||
|
||||
String fileUpload(MultipartFile paramMultipartFile) throws DavinciServiceException;
|
||||
|
||||
String fileUpload(String paramString, MultipartFile paramMultipartFile) throws DavinciServiceException;
|
||||
|
||||
String bigFileUpload(MultipartFile paramMultipartFile) throws DavinciServiceException;
|
||||
|
||||
String bigFileUpload(String paramString, MultipartFile paramMultipartFile) throws DavinciServiceException;
|
||||
|
||||
byte[] fileDownload(String paramString) throws DavinciServiceException;
|
||||
|
||||
String getFileBase64(String paramString) throws DavinciServiceException;
|
||||
|
||||
List<String> remove(FileRemoveDTO paramFileRemoveDTO) throws DavinciServiceException;
|
||||
|
||||
InputStream fileDownloadStream(String paramString) throws DavinciServiceException;
|
||||
|
||||
InputStream fileDownLoadWithAbsoluteUrl(String paramString) throws DavinciServiceException;
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.manager.impl;
|
||||
|
||||
import cn.cloudwalk.intelligent.davinci.common.exception.DavinciServiceException;
|
||||
import cn.cloudwalk.intelligent.davinci.common.result.DavinciResult;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartFinishDTO;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartInitDTO;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartInitResultDTO;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.feign.FilePartFeign;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.manager.FilePartManager;
|
||||
import feign.Client;
|
||||
import feign.Feign;
|
||||
import feign.codec.Decoder;
|
||||
import feign.codec.Encoder;
|
||||
import feign.form.spring.SpringFormEncoder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
|
||||
import org.springframework.cloud.openfeign.support.SpringMvcContract;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Component
|
||||
@Import({FeignClientsConfiguration.class})
|
||||
public class FilePartManagerImpl implements FilePartManager {
|
||||
|
||||
private FilePartFeign filePartFeign;
|
||||
private FilePartFeign filePartRestFeign;
|
||||
|
||||
@Autowired
|
||||
public FilePartManagerImpl(
|
||||
@Value("${feign.davinci-portal.name:davinci-portal}") String serviceName,
|
||||
Decoder decoder,
|
||||
Encoder encoder,
|
||||
Client client) {
|
||||
String url = "http://" + serviceName + "/portal/file/part";
|
||||
|
||||
this.filePartFeign =
|
||||
Feign.builder()
|
||||
.client(client)
|
||||
.decode404()
|
||||
.encoder(new SpringFormEncoder())
|
||||
.decoder(decoder)
|
||||
.contract(new SpringMvcContract())
|
||||
.target(FilePartFeign.class, url);
|
||||
|
||||
this.filePartRestFeign =
|
||||
Feign.builder()
|
||||
.client(client)
|
||||
.decode404()
|
||||
.encoder(encoder)
|
||||
.decoder(decoder)
|
||||
.contract(new SpringMvcContract())
|
||||
.target(FilePartFeign.class, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartInitResultDTO init(PartInitDTO dto) throws DavinciServiceException {
|
||||
DavinciResult<PartInitResultDTO> result = this.filePartRestFeign.init(dto);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartInitResultDTO append(
|
||||
String filePath, Integer partNumber, String uploadId, MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<PartInitResultDTO> result = this.filePartFeign.append(filePath, partNumber, uploadId, file);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String finish(PartFinishDTO dto) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.filePartRestFeign.finish(dto);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
}
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
package cn.cloudwalk.intelligent.davinci.storage.manager.impl;
|
||||
|
||||
import cn.cloudwalk.intelligent.davinci.common.exception.DavinciServiceException;
|
||||
import cn.cloudwalk.intelligent.davinci.common.result.DavinciResult;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.bean.file.dto.FileRemoveDTO;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.feign.FileManagerFeign;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.feign.OuterCallFeignClient;
|
||||
import cn.cloudwalk.intelligent.davinci.storage.manager.FileStorageManager;
|
||||
import feign.Client;
|
||||
import feign.Feign;
|
||||
import feign.Response;
|
||||
import feign.codec.Decoder;
|
||||
import feign.codec.Encoder;
|
||||
import feign.form.spring.SpringFormEncoder;
|
||||
import feign.okhttp.OkHttpClient;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
|
||||
import org.springframework.cloud.openfeign.support.SpringMvcContract;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Component
|
||||
@Import({FeignClientsConfiguration.class})
|
||||
public class FileStorageManagerImpl implements FileStorageManager {
|
||||
|
||||
private FileManagerFeign fileManagerFeign;
|
||||
private FileManagerFeign fileManagerRestFeign;
|
||||
|
||||
@Autowired
|
||||
public FileStorageManagerImpl(
|
||||
@Value("${feign.davinci-portal.name:davinci-portal}") String serviceName,
|
||||
Decoder decoder,
|
||||
Encoder encoder,
|
||||
Client client) {
|
||||
String url = "http://" + serviceName + "/portal/fileManager";
|
||||
|
||||
this.fileManagerFeign =
|
||||
Feign.builder()
|
||||
.client(client)
|
||||
.decode404()
|
||||
.encoder(new SpringFormEncoder())
|
||||
.decoder(decoder)
|
||||
.contract(new SpringMvcContract())
|
||||
.target(FileManagerFeign.class, url);
|
||||
|
||||
this.fileManagerRestFeign =
|
||||
Feign.builder()
|
||||
.client(client)
|
||||
.decode404()
|
||||
.encoder(encoder)
|
||||
.decoder(decoder)
|
||||
.contract(new SpringMvcContract())
|
||||
.target(FileManagerFeign.class, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 限制通过「绝对 URL」拉流时的 SSRF:仅 http(s),且解析后不得为回环、链路本地、站点本地及常见元数据地址。
|
||||
*/
|
||||
static void assertSafeHttpUrl(String urlString) throws DavinciServiceException {
|
||||
if (StringUtils.isEmpty(urlString)) {
|
||||
throw new DavinciServiceException("INVALID_URL", "URL 为空");
|
||||
}
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(urlString);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new DavinciServiceException("INVALID_URL", "URL 非法");
|
||||
}
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme == null || (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme))) {
|
||||
throw new DavinciServiceException("INVALID_URL", "仅允许 http 或 https 协议");
|
||||
}
|
||||
String host = uri.getHost();
|
||||
if (StringUtils.isEmpty(host)) {
|
||||
throw new DavinciServiceException("INVALID_URL", "缺少主机名");
|
||||
}
|
||||
String lowerHost = host.toLowerCase(Locale.ROOT);
|
||||
if ("localhost".equals(lowerHost) || lowerHost.endsWith(".local")) {
|
||||
throw new DavinciServiceException("INVALID_URL", "禁止访问该主机");
|
||||
}
|
||||
if ("metadata.google.internal".equalsIgnoreCase(host)) {
|
||||
throw new DavinciServiceException("INVALID_URL", "禁止访问该主机");
|
||||
}
|
||||
try {
|
||||
InetAddress[] all = InetAddress.getAllByName(host);
|
||||
for (InetAddress addr : all) {
|
||||
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress() || addr.isLinkLocalAddress()
|
||||
|| addr.isSiteLocalAddress() || addr.isMulticastAddress()) {
|
||||
throw new DavinciServiceException("INVALID_URL", "禁止访问内网或保留地址");
|
||||
}
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
throw new DavinciServiceException("INVALID_URL", "无法解析主机");
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream attachResponseClose(InputStream bodyStream, Response response) {
|
||||
return new FilterInputStream(bodyStream) {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
try {
|
||||
super.close();
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fileUpload(MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.fileManagerFeign.fileUpload(file);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fileUpload(String moduleCategory, MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.fileManagerFeign.fileUpload(moduleCategory, file);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String bigFileUpload(MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.fileManagerFeign.bigFileUpload(file);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String bigFileUpload(String moduleCategory, MultipartFile file) throws DavinciServiceException {
|
||||
DavinciResult<String> result = this.fileManagerFeign.bigFileUpload(moduleCategory, file);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] fileDownload(String path) throws DavinciServiceException {
|
||||
try (Response response = this.fileManagerFeign.fileDownload(path)) {
|
||||
if (response.body() == null) {
|
||||
return null;
|
||||
}
|
||||
try (InputStream inputStream = response.body().asInputStream()) {
|
||||
return IOUtils.toByteArray(inputStream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new DavinciServiceException("FILE_DOWNLOAD_IO", "调用Davinci-portal服务,获取文件流接口异常");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream fileDownloadStream(String path) throws DavinciServiceException {
|
||||
Response response = this.fileManagerFeign.fileDownload(path);
|
||||
try {
|
||||
if (response.body() == null) {
|
||||
response.close();
|
||||
return null;
|
||||
}
|
||||
return attachResponseClose(response.body().asInputStream(), response);
|
||||
} catch (IOException e) {
|
||||
response.close();
|
||||
throw new DavinciServiceException("FILE_DOWNLOAD_IO", "调用Davinci-portal服务,获取文件流接口异常");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileBase64(String path) throws DavinciServiceException {
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
return "";
|
||||
}
|
||||
DavinciResult<String> result = this.fileManagerFeign.getFileData(path);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> remove(FileRemoveDTO dto) throws DavinciServiceException {
|
||||
DavinciResult<List<String>> result = this.fileManagerRestFeign.remove(dto);
|
||||
if (result.isSuccess()) {
|
||||
return result.getData();
|
||||
}
|
||||
throw new DavinciServiceException(result.getCode(), result.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream fileDownLoadWithAbsoluteUrl(String url) throws DavinciServiceException {
|
||||
assertSafeHttpUrl(url);
|
||||
OuterCallFeignClient feignClient =
|
||||
Feign.builder().client(new OkHttpClient()).target(OuterCallFeignClient.class, url);
|
||||
Response response;
|
||||
try {
|
||||
response = feignClient.downLoad();
|
||||
} catch (RuntimeException e) {
|
||||
throw new DavinciServiceException("OUTER_DOWNLOAD", "拉取远程文件失败");
|
||||
}
|
||||
try {
|
||||
if (response.body() == null) {
|
||||
response.close();
|
||||
return null;
|
||||
}
|
||||
return attachResponseClose(response.body().asInputStream(), response);
|
||||
} catch (IOException e) {
|
||||
response.close();
|
||||
throw new DavinciServiceException("OUTER_DOWNLOAD", "读取远程文件流失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.18.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>cn.cloudwalk.intelligent</groupId>
|
||||
<artifactId>cloudwalk-intelligent-davinci-manager</artifactId>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>cloudwalk-intelligent-davinci-manager (Maven reactor)</name>
|
||||
<description>补齐私服缺失的 cloudwalk-intelligent-davinci-manager 父 POM 与 davinci-manager-common / davinci-manager-storage;源码基底来自 1.1.5 反编译 zip,与 V1 运行包 lib 中 1.1.7-SNAPSHOT 坐标一致;Feign 集成与 Greenwich 对齐(OpenFeign)。</description>
|
||||
|
||||
<modules>
|
||||
<module>davinci-manager-common</module>
|
||||
<module>davinci-manager-storage</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud.version>Greenwich.SR6</spring-cloud.version>
|
||||
<feign-form.version>3.0.3</feign-form.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<nexus.baseUrl>http://192.168.3.12</nexus.baseUrl>
|
||||
<nexus.public.repo>${nexus.baseUrl}/repository/maven-public/</nexus.public.repo>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nexus-public</id>
|
||||
<url>${nexus.public.repo}</url>
|
||||
<releases><enabled>true</enabled></releases>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-jdk8</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireJavaVersion>
|
||||
<version>[1.8,1.9)</version>
|
||||
</requireJavaVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
Reference in New Issue
Block a user