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

init

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