mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
Initial commit: reorganized source tree
- backend/: 13 Maven modules (cw-elevator-application, cloudwalk-cloud, intelligent-cwoscomponent, ninca-crk, etc.) - frontend/: 4 Vue projects (elevator-front, cwos-portal, alarm-front, front_acs) + decompiled + scripts - scripts/: build, test-env, tools (Docker Compose, service templates, API parity) - docs/: AGENTS.md, superpowers specs, architecture docs - .gitignore: standard Java/Maven exclusions Moved from legacy maven-*/ root layout to backend/ organized structure.
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;
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/** Feign 降级或本地失败路径使用的结构化失败体(不走异常控制流)。 */
|
||||
public static <T> DavinciResult<T> fail(String code, String message) {
|
||||
DavinciResult<T> r = new DavinciResult<>();
|
||||
r.setSuccess(false);
|
||||
r.setCode(code);
|
||||
r.setMessage(message);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static <T> DavinciResult<T> success(T data) {
|
||||
DavinciResult<T> r = new DavinciResult<>();
|
||||
r.setSuccess(true);
|
||||
r.setCode("0");
|
||||
r.setMessage("ok");
|
||||
r.setData(data);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
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.Request;
|
||||
import feign.Response;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
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 {
|
||||
|
||||
private static final String FEIGN_DOWN = "DAVINCI_FEIGN_DOWN";
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> fileUpload(MultipartFile file) {
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,模块文件上传接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> fileUpload(String moduleCategory, MultipartFile file) {
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,模块文件上传接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> bigFileUpload(MultipartFile file) {
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,大文件上传接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> bigFileUpload(String moduleCategory, MultipartFile file) {
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,大文件上传接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response fileDownload(String path) {
|
||||
return Response
|
||||
.builder().status(503).reason("Feign fallback").request(Request.create(Request.HttpMethod.GET, "/",
|
||||
Collections.emptyMap(), null, StandardCharsets.UTF_8))
|
||||
.body("{}", StandardCharsets.UTF_8).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<String> getFileData(String path) {
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,获取文件Base64内容接口降级");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DavinciResult<List<String>> remove(FileRemoveDTO dto) {
|
||||
return DavinciResult.fail(FEIGN_DOWN, "调用Davinci-portal服务,删除文件接口降级");
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
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 feign.Response;
|
||||
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 = { "/part/init" }, method = { RequestMethod.POST })
|
||||
DavinciResult<PartInitResultDTO> init(@RequestBody PartInitDTO paramPartInitDTO);
|
||||
|
||||
@RequestMapping(value = { "/part/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 = { "/part/finish" }, method = { RequestMethod.POST })
|
||||
DavinciResult<String> finish(@RequestBody PartFinishDTO paramPartFinishDTO);
|
||||
|
||||
@RequestMapping(value = { "/download" }, method = { RequestMethod.GET })
|
||||
Response bigFileDownload(@RequestParam("path") String path);
|
||||
}
|
||||
+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();
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
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 java.io.InputStream;
|
||||
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;
|
||||
|
||||
InputStream bigFileDownload(String paramString) 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;
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
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.Response;
|
||||
import feign.codec.Decoder;
|
||||
import feign.codec.Encoder;
|
||||
import feign.form.spring.SpringFormEncoder;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.springframework.cloud.openfeign.support.SpringMvcContract;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public class FilePartManagerImpl implements FilePartManager {
|
||||
|
||||
private FilePartFeign filePartFeign;
|
||||
private FilePartFeign filePartRestFeign;
|
||||
|
||||
public FilePartManagerImpl(String serviceName, Decoder decoder, Encoder encoder, Client client) {
|
||||
String url = "http://" + serviceName + "/portal/file";
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream bigFileDownload(String path) throws DavinciServiceException {
|
||||
try {
|
||||
Response response = this.filePartFeign.bigFileDownload(path);
|
||||
if (response.body() == null) {
|
||||
return null;
|
||||
}
|
||||
return response.body().asInputStream();
|
||||
} catch (IOException e) {
|
||||
throw new DavinciServiceException("", "调用Davinci-portal服务,获取大文件流接口异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
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.support.SpringMvcContract;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Component
|
||||
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 void requireDavinciResult(DavinciResult<?> result, String op) throws DavinciServiceException {
|
||||
if (result == null) {
|
||||
throw new DavinciServiceException("NULL_RESULT", "Davinci-portal 返回空结果: " + op);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
requireDavinciResult(result, "fileUpload");
|
||||
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);
|
||||
requireDavinciResult(result, "fileUpload(module)");
|
||||
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);
|
||||
requireDavinciResult(result, "bigFileUpload");
|
||||
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);
|
||||
requireDavinciResult(result, "bigFileUpload(module)");
|
||||
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 == null) {
|
||||
return null;
|
||||
}
|
||||
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 == null) {
|
||||
return null;
|
||||
}
|
||||
if (response.body() == null) {
|
||||
response.close();
|
||||
return null;
|
||||
}
|
||||
return attachResponseClose(response.body().asInputStream(), response);
|
||||
} catch (IOException e) {
|
||||
if (response != null) {
|
||||
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);
|
||||
requireDavinciResult(result, "getFileData");
|
||||
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);
|
||||
requireDavinciResult(result, "remove");
|
||||
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