提交 d30171fd authored 作者: javamaoyang's avatar javamaoyang

init

上级 f6b09a5e
流水线 #8624 已失败 于阶段
in 6 seconds
...@@ -48,6 +48,12 @@ ...@@ -48,6 +48,12 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
......
...@@ -2,10 +2,16 @@ package com.example.controller; ...@@ -2,10 +2,16 @@ package com.example.controller;
import com.example.baidu.ueditor.ActionEnter; import com.example.baidu.ueditor.ActionEnter;
import com.example.baidu.ueditor.ConfigManager; import com.example.baidu.ueditor.ConfigManager;
import com.example.util.AliyunOSSConfigConstant;
import com.example.util.AliyunOSSUtil;
import com.example.util.DataConfig;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -13,17 +19,20 @@ import javax.servlet.http.HttpServletRequest; ...@@ -13,17 +19,20 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
@Controller @Controller
public class UEditorController { public class UEditorController {
@Value("${oss.host}") private Map<String, AliyunOSSConfigConstant> projectMap = new HashMap<String, AliyunOSSConfigConstant>();
private String imageUrl;
@Autowired
private AliyunOSSUtil aliyunOSSUtil;
@Value("${oss.folder}")
private String ossPath;
@RequestMapping("/") @RequestMapping("/")
private String showPage() { private String showPage() {
...@@ -33,7 +42,12 @@ public class UEditorController { ...@@ -33,7 +42,12 @@ public class UEditorController {
@RequestMapping(value = "/config") @RequestMapping(value = "/config")
public void config(HttpServletRequest request, HttpServletResponse response) { public void config(HttpServletRequest request, HttpServletResponse response) {
String env=request.getParameter("env");
AliyunOSSConfigConstant aliyunOSSConfigConstant=aliyunOSSUtil.getOssConfig(env);
//OSSConfigConstant oSSConfigConstant=ev.getProperty("projectMap.woyou", OSSConfigConstant.class);
response.setContentType("application/json"); response.setContentType("application/json");
String rootPath = request.getSession().getServletContext().getRealPath("/"); String rootPath = request.getSession().getServletContext().getRealPath("/");
try { try {
...@@ -43,8 +57,8 @@ public class UEditorController { ...@@ -43,8 +57,8 @@ public class UEditorController {
String exec = new ActionEnter(request, rootPath).exec(); String exec = new ActionEnter(request, rootPath).exec();
//exec=exec.replace("\"imageUrlPrefix\":\"https://imgb.mofangx.com/\"","'imageUrlPrefix':'"+imageUrlPrefix+"'"); //exec=exec.replace("\"imageUrlPrefix\":\"https://imgb.mofangx.com/\"","'imageUrlPrefix':'"+imageUrlPrefix+"'");
exec=exec.replace("{imgUrl}",imageUrl+"/"); exec=exec.replace("{imgUrl}",aliyunOSSConfigConstant.getHost()+"/");
exec=exec.replace("{basePath}",ossPath); exec=exec.replace("{basePath}",aliyunOSSConfigConstant.getFolder());
//exec=exec.replace("'basePath':'erp/'","'basePath':'"+ossPath+"'"); //exec=exec.replace("'basePath':'erp/'","'basePath':'"+ossPath+"'");
......
...@@ -4,9 +4,13 @@ import com.aliyun.oss.ClientException; ...@@ -4,9 +4,13 @@ import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSSClient; import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSException; import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.*; import com.aliyun.oss.model.*;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.activation.MimetypesFileTypeMap; import javax.activation.MimetypesFileTypeMap;
...@@ -14,8 +18,12 @@ import javax.imageio.ImageIO; ...@@ -14,8 +18,12 @@ import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
...@@ -30,19 +38,24 @@ import java.util.UUID; ...@@ -30,19 +38,24 @@ import java.util.UUID;
public class AliyunOSSUtil { public class AliyunOSSUtil {
private static final Logger logger = LoggerFactory.getLogger(AliyunOSSUtil.class); private static final Logger logger = LoggerFactory.getLogger(AliyunOSSUtil.class);
///private static String bucketName = AliyunOSSConfigConstant.BUCKE_NAME; /// private static String bucketName = AliyunOSSConfigConstant.BUCKE_NAME;
private static String FILE_URL; private static String FILE_URL;
//private static String endpoint = AliyunOSSConfigConstant.END_POINT; // private static String endpoint = AliyunOSSConfigConstant.END_POINT;
// private static String accessKeyId = AliyunOSSConfigConstant.AccessKey_ID; // private static String accessKeyId = AliyunOSSConfigConstant.AccessKey_ID;
// private static String accessKeySecret = AliyunOSSConfigConstant.AccessKey_Secret; // private static String accessKeySecret =
// AliyunOSSConfigConstant.AccessKey_Secret;
// private static String fileHost = AliyunOSSConfigConstant.FILE_HOST; // private static String fileHost = AliyunOSSConfigConstant.FILE_HOST;
//@Autowired
private AliyunOSSConfigConstant aliyunOSSConfigConstant=new AliyunOSSConfigConstant();
@Autowired @Autowired
private AliyunOSSConfigConstant aliyunOSSConfigConstant; private DataConfig dataConfig;
/** /**
* Description: upolad * Description: upolad 嵌入ueditor的上传
* 嵌入ueditor的上传
* *
* @param file * @param file
* @param fileUrl * @param fileUrl
...@@ -50,11 +63,25 @@ public class AliyunOSSUtil { ...@@ -50,11 +63,25 @@ public class AliyunOSSUtil {
* @date 2019/2/21 16:40 * @date 2019/2/21 16:40
*/ */
public AliyunOSSConfigConstant getOssConfig(String env) {
dataConfig.getUeditor().forEach(oSSConfigConstant -> {
if(oSSConfigConstant.getEnv().equals(env)) {
BeanUtils.copyProperties(oSSConfigConstant, aliyunOSSConfigConstant);
}
});
return aliyunOSSConfigConstant;
}
public String upolad(File file, String fileUrl) { public String upolad(File file, String fileUrl) {
String bucketName=aliyunOSSConfigConstant.getBucketName();
String bucketName = aliyunOSSConfigConstant.getBucketName();
// 创建OSSClient实例。 // 创建OSSClient实例。
OSSClient ossClient = new OSSClient(aliyunOSSConfigConstant.getHost(), aliyunOSSConfigConstant.getKeyId(), aliyunOSSConfigConstant.getKeySecret()); OSSClient ossClient = new OSSClient(aliyunOSSConfigConstant.getHost(), aliyunOSSConfigConstant.getKeyId(),
aliyunOSSConfigConstant.getKeySecret());
try { try {
// 判断容器是否存在,不存在就创建 // 判断容器是否存在,不存在就创建
if (!ossClient.doesBucketExist(bucketName)) { if (!ossClient.doesBucketExist(bucketName)) {
...@@ -63,12 +90,12 @@ public class AliyunOSSUtil { ...@@ -63,12 +90,12 @@ public class AliyunOSSUtil {
createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead); createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
ossClient.createBucket(createBucketRequest); ossClient.createBucket(createBucketRequest);
} }
String fileType=new MimetypesFileTypeMap().getContentType(file); String fileType = new MimetypesFileTypeMap().getContentType(file);
ObjectMetadata meta = new ObjectMetadata(); // 创建上传Object的Metadata ObjectMetadata meta = new ObjectMetadata(); // 创建上传Object的Metadata
meta.setContentType(AliyunOSSUtil.contentType(fileType)); // 设置上传内容类型 meta.setContentType(AliyunOSSUtil.contentType(fileType)); // 设置上传内容类型
meta.setCacheControl("no-cache"); meta.setCacheControl("no-cache");
PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName, fileUrl, file,meta)); PutObjectResult result = ossClient.putObject(new PutObjectRequest(bucketName, fileUrl, file, meta));
// 设置权限(公开读) // 设置权限(公开读)
ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicRead); ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
if (result != null) { if (result != null) {
...@@ -109,10 +136,11 @@ public class AliyunOSSUtil { ...@@ -109,10 +136,11 @@ public class AliyunOSSUtil {
return null; return null;
} }
String bucketName=aliyunOSSConfigConstant.getBucketName(); String bucketName = aliyunOSSConfigConstant.getBucketName();
// 创建OSSClient实例。 // 创建OSSClient实例。
OSSClient ossClient = new OSSClient(aliyunOSSConfigConstant.getHost(), aliyunOSSConfigConstant.getKeyId(), aliyunOSSConfigConstant.getKeySecret()); OSSClient ossClient = new OSSClient(aliyunOSSConfigConstant.getHost(), aliyunOSSConfigConstant.getKeyId(),
aliyunOSSConfigConstant.getKeySecret());
try { try {
// 判断容器是否存在,不存在就创建 // 判断容器是否存在,不存在就创建
if (!ossClient.doesBucketExist(bucketName)) { if (!ossClient.doesBucketExist(bucketName)) {
...@@ -122,8 +150,9 @@ public class AliyunOSSUtil { ...@@ -122,8 +150,9 @@ public class AliyunOSSUtil {
ossClient.createBucket(createBucketRequest); ossClient.createBucket(createBucketRequest);
} }
// 设置文件路径和名称 // 设置文件路径和名称
String fileUrl = aliyunOSSConfigConstant.getFolder() + UUID.randomUUID().toString().replace("-", "") + "-" + file.getName(); String fileUrl = aliyunOSSConfigConstant.getFolder() + UUID.randomUUID().toString().replace("-", "") + "-"
if (isImage) {//如果是图片,则图片的URL为:.... + file.getName();
if (isImage) {// 如果是图片,则图片的URL为:....
FILE_URL = aliyunOSSConfigConstant.getHost() + "/" + fileUrl; FILE_URL = aliyunOSSConfigConstant.getHost() + "/" + fileUrl;
} else { } else {
FILE_URL = "非图片,不可预览。文件路径为:" + fileUrl; FILE_URL = "非图片,不可预览。文件路径为:" + fileUrl;
...@@ -148,7 +177,6 @@ public class AliyunOSSUtil { ...@@ -148,7 +177,6 @@ public class AliyunOSSUtil {
return FILE_URL; return FILE_URL;
} }
/** /**
* 通过文件名下载文件 * 通过文件名下载文件
* *
...@@ -158,9 +186,11 @@ public class AliyunOSSUtil { ...@@ -158,9 +186,11 @@ public class AliyunOSSUtil {
public void downloadFile(String objectName, String localFileName) { public void downloadFile(String objectName, String localFileName) {
// 创建OSSClient实例。 // 创建OSSClient实例。
OSSClient ossClient = new OSSClient(aliyunOSSConfigConstant.getHost(), aliyunOSSConfigConstant.getKeyId(), aliyunOSSConfigConstant.getKeySecret()); OSSClient ossClient = new OSSClient(aliyunOSSConfigConstant.getHost(), aliyunOSSConfigConstant.getKeyId(),
aliyunOSSConfigConstant.getKeySecret());
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。 // 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
ossClient.getObject(new GetObjectRequest(aliyunOSSConfigConstant.getBucketName(), objectName), new File(localFileName)); ossClient.getObject(new GetObjectRequest(aliyunOSSConfigConstant.getBucketName(), objectName),
new File(localFileName));
// 关闭OSSClient。 // 关闭OSSClient。
ossClient.shutdown(); ossClient.shutdown();
} }
...@@ -170,7 +200,8 @@ public class AliyunOSSUtil { ...@@ -170,7 +200,8 @@ public class AliyunOSSUtil {
*/ */
public void listFile() { public void listFile() {
// 创建OSSClient实例。 // 创建OSSClient实例。
OSSClient ossClient = new OSSClient(aliyunOSSConfigConstant.getHost(), aliyunOSSConfigConstant.getKeyId(), aliyunOSSConfigConstant.getKeySecret()); OSSClient ossClient = new OSSClient(aliyunOSSConfigConstant.getHost(), aliyunOSSConfigConstant.getKeyId(),
aliyunOSSConfigConstant.getKeySecret());
// 构造ListObjectsRequest请求。 // 构造ListObjectsRequest请求。
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(aliyunOSSConfigConstant.getBucketName()); ListObjectsRequest listObjectsRequest = new ListObjectsRequest(aliyunOSSConfigConstant.getBucketName());
...@@ -192,8 +223,6 @@ public class AliyunOSSUtil { ...@@ -192,8 +223,6 @@ public class AliyunOSSUtil {
ossClient.shutdown(); ossClient.shutdown();
} }
/** /**
* *
* @MethodName: contentType * @MethodName: contentType
...@@ -201,35 +230,46 @@ public class AliyunOSSUtil { ...@@ -201,35 +230,46 @@ public class AliyunOSSUtil {
* @param FileType * @param FileType
* @return String * @return String
*/ */
private static String contentType(String fileType){ private static String contentType(String fileType) {
fileType = fileType.toLowerCase(); fileType = fileType.toLowerCase();
String contentType = ""; String contentType = "";
switch (fileType) { switch (fileType) {
case "bmp": contentType = "image/bmp"; case "bmp":
contentType = "image/bmp";
break; break;
case "gif": contentType = "image/gif"; case "gif":
contentType = "image/gif";
break; break;
case "png": case "png":
case "jpeg": case "jpeg":
case "jpg": contentType = "image/jpeg"; case "jpg":
contentType = "image/jpeg";
break; break;
case "html":contentType = "text/html"; case "html":
contentType = "text/html";
break; break;
case "txt": contentType = "text/plain"; case "txt":
contentType = "text/plain";
break; break;
case "vsd": contentType = "application/vnd.visio"; case "vsd":
contentType = "application/vnd.visio";
break; break;
case "ppt": case "ppt":
case "pptx":contentType = "application/vnd.ms-powerpoint"; case "pptx":
contentType = "application/vnd.ms-powerpoint";
break; break;
case "doc": case "doc":
case "docx":contentType = "application/msword"; case "docx":
contentType = "application/msword";
break; break;
case "xml":contentType = "text/xml"; case "xml":
contentType = "text/xml";
break; break;
case "mp4":contentType = "video/mp4"; case "mp4":
contentType = "video/mp4";
break; break;
default: contentType = "image/jpeg"; default:
contentType = "image/jpeg";
break; break;
} }
return contentType; return contentType;
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
*/ */
var URL = window.UEDITOR_HOME_URL || getUEBasePath(); var URL = window.UEDITOR_HOME_URL || getUEBasePath();
var env=getQueryString("env");
/** /**
* 配置项主体。注意,此处所有涉及到路径的配置别遗漏URL变量。 * 配置项主体。注意,此处所有涉及到路径的配置别遗漏URL变量。
*/ */
...@@ -30,7 +32,7 @@ ...@@ -30,7 +32,7 @@
UEDITOR_HOME_URL: URL UEDITOR_HOME_URL: URL
// 服务器统一请求接口路径 // 服务器统一请求接口路径
, serverUrl: URL + "config" , serverUrl: URL + "config?env="+env
//工具栏上的所有的功能按钮和下拉框,可以在new编辑器的实例时选择自己需要的重新定义 //工具栏上的所有的功能按钮和下拉框,可以在new编辑器的实例时选择自己需要的重新定义
, toolbars: [[ , toolbars: [[
...@@ -490,6 +492,12 @@ ...@@ -490,6 +492,12 @@
} }
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
window.UE = { window.UE = {
getUEBasePath: getUEBasePath getUEBasePath: getUEBasePath
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论