mirror of https://github.com/halo-dev/halo
合并dev分支
commit
083dbcffcf
2
pom.xml
2
pom.xml
|
@ -35,7 +35,7 @@
|
||||||
<lombok.version>1.18.2</lombok.version>
|
<lombok.version>1.18.2</lombok.version>
|
||||||
<ehcache.version>3.6.0</ehcache.version>
|
<ehcache.version>3.6.0</ehcache.version>
|
||||||
<rome.version>1.0</rome.version>
|
<rome.version>1.0</rome.version>
|
||||||
<hutool-all.version>4.1.19</hutool-all.version>
|
<hutool-all.version>4.2.1</hutool-all.version>
|
||||||
<upyun-java-sdk.version>4.0.1</upyun-java-sdk.version>
|
<upyun-java-sdk.version>4.0.1</upyun-java-sdk.version>
|
||||||
<qiniu-java-sdk.version>7.2.14</qiniu-java-sdk.version>
|
<qiniu-java-sdk.version>7.2.14</qiniu-java-sdk.version>
|
||||||
<thumbnailator.version>0.4.8</thumbnailator.version>
|
<thumbnailator.version>0.4.8</thumbnailator.version>
|
||||||
|
|
|
@ -75,4 +75,9 @@ public class Attachment implements Serializable {
|
||||||
* 附件存储地址
|
* 附件存储地址
|
||||||
*/
|
*/
|
||||||
private String attachLocation;
|
private String attachLocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件来源,0:上传,1:外部链接
|
||||||
|
*/
|
||||||
|
private Integer attachOrigin = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,47 +61,53 @@ public interface AttachmentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传转发
|
* 上传转发
|
||||||
* @param file
|
*
|
||||||
* @param request
|
* @param file file
|
||||||
* @return
|
* @param request request
|
||||||
|
* @return Map
|
||||||
*/
|
*/
|
||||||
Map<String,String> upload(MultipartFile file, HttpServletRequest request);
|
Map<String, String> upload(MultipartFile file, HttpServletRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原生上传
|
* 原生服务器上传
|
||||||
* @param file
|
*
|
||||||
* @param request
|
* @param file file
|
||||||
* @return
|
* @param request request
|
||||||
|
* @return Map
|
||||||
*/
|
*/
|
||||||
Map<String,String> attachUpload(MultipartFile file, HttpServletRequest request);
|
Map<String, String> attachUpload(MultipartFile file, HttpServletRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 七牛云上传
|
* 七牛云上传
|
||||||
* @param file
|
*
|
||||||
* @param request
|
* @param file file
|
||||||
* @return
|
* @param request request
|
||||||
|
* @return Map
|
||||||
*/
|
*/
|
||||||
Map<String,String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request);
|
Map<String, String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 又拍云上传
|
* 又拍云上传
|
||||||
* @param file
|
*
|
||||||
* @param request
|
* @param file file
|
||||||
* @return
|
* @param request request
|
||||||
|
* @return Map
|
||||||
*/
|
*/
|
||||||
Map<String,String> attachUpYunUpload(MultipartFile file, HttpServletRequest request);
|
Map<String, String> attachUpYunUpload(MultipartFile file, HttpServletRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 七牛云删除附件
|
* 七牛云删除附件
|
||||||
* @param key
|
*
|
||||||
* @return
|
* @param key key
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
boolean deleteQiNiuAttachment(String key);
|
boolean deleteQiNiuAttachment(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 又拍云删除附件
|
* 又拍云删除附件
|
||||||
* @param fileName
|
*
|
||||||
* @return
|
* @param fileName fileName
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
boolean deleteUpYunAttachment(String fileName);
|
boolean deleteUpYunAttachment(String fileName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import cc.ryanc.halo.service.AttachmentService;
|
||||||
import cc.ryanc.halo.utils.HaloUtils;
|
import cc.ryanc.halo.utils.HaloUtils;
|
||||||
import cc.ryanc.halo.utils.Md5Util;
|
import cc.ryanc.halo.utils.Md5Util;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import com.UpYun;
|
import com.UpYun;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
@ -38,7 +39,6 @@ import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,29 +121,30 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传转发
|
* 上传转发
|
||||||
* @param file
|
*
|
||||||
* @param request
|
* @param file file
|
||||||
* @return
|
* @param request request
|
||||||
|
* @return Map
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> upload(MultipartFile file, HttpServletRequest request) {
|
public Map<String, String> upload(MultipartFile file, HttpServletRequest request) {
|
||||||
Map<String,String> resultMap;
|
Map<String, String> resultMap;
|
||||||
Options options = optionsRepository.findOptionsByOptionName("attach_loc");
|
Options options = optionsRepository.findOptionsByOptionName("attach_loc");
|
||||||
if(options == null){
|
if (options == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
switch (options.getOptionValue()){
|
switch (options.getOptionValue()) {
|
||||||
case "server":
|
case "server":
|
||||||
resultMap = this.attachUpload(file,request);
|
resultMap = this.attachUpload(file, request);
|
||||||
break;
|
break;
|
||||||
case "qiniu":
|
case "qiniu":
|
||||||
resultMap = this.attachQiNiuUpload(file,request);
|
resultMap = this.attachQiNiuUpload(file, request);
|
||||||
break;
|
break;
|
||||||
case "upyun":
|
case "upyun":
|
||||||
resultMap = this.attachUpYunUpload(file,request);
|
resultMap = this.attachUpYunUpload(file, request);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
resultMap = this.attachUpload(file,request);
|
resultMap = this.attachUpload(file, request);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return resultMap;
|
return resultMap;
|
||||||
|
@ -151,42 +152,89 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原生服务器上传
|
* 原生服务器上传
|
||||||
* @param file
|
*
|
||||||
* @param request
|
* @param file file
|
||||||
* @return
|
* @param request request
|
||||||
|
* @return Map
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> attachUpload(MultipartFile file, HttpServletRequest request) {
|
public Map<String, String> attachUpload(MultipartFile file, HttpServletRequest request) {
|
||||||
Map<String,String> resultMap = new HashMap<>(6);
|
Map<String, String> resultMap = new HashMap<>(6);
|
||||||
|
String dateString = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||||
try {
|
try {
|
||||||
//用户目录
|
//用户目录
|
||||||
String userPath = System.getProperties().getProperty("user.home") + "/halo";
|
StrBuilder uploadPath = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||||
//upload的路径
|
uploadPath.append("/halo/");
|
||||||
StringBuffer sbMedia = new StringBuffer("upload/");
|
uploadPath.append("upload/");
|
||||||
|
|
||||||
//获取当前年月以创建目录,如果没有该目录则创建
|
//获取当前年月以创建目录,如果没有该目录则创建
|
||||||
sbMedia.append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth()).append("/");
|
uploadPath.append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth()).append("/");
|
||||||
File mediaPath = new File(userPath, sbMedia.toString());
|
File mediaPath = new File(uploadPath.toString());
|
||||||
if (!mediaPath.exists()) {
|
if (!mediaPath.exists()) {
|
||||||
mediaPath.mkdirs();
|
if (!mediaPath.mkdirs()) {
|
||||||
|
resultMap.put("success", "0");
|
||||||
|
return resultMap;
|
||||||
}
|
}
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
}
|
||||||
String nameWithOutSuffix = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf('.')).replaceAll(" ", "_").replaceAll(",", "") + dateFormat.format(DateUtil.date()) + new Random().nextInt(1000);
|
|
||||||
|
//不带后缀
|
||||||
|
StrBuilder nameWithOutSuffix = new StrBuilder(file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf('.')).replaceAll(" ", "_").replaceAll(",", ""));
|
||||||
|
nameWithOutSuffix.append(dateString);
|
||||||
|
nameWithOutSuffix.append(new Random().nextInt(1000));
|
||||||
|
|
||||||
|
//文件后缀
|
||||||
String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.') + 1);
|
String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.') + 1);
|
||||||
String fileName = nameWithOutSuffix + "." + fileSuffix;
|
|
||||||
file.transferTo(new File(mediaPath.getAbsoluteFile(), fileName));
|
//带后缀
|
||||||
|
StrBuilder fileName = new StrBuilder(nameWithOutSuffix);
|
||||||
|
fileName.append(".");
|
||||||
|
fileName.append(fileSuffix);
|
||||||
|
|
||||||
|
file.transferTo(new File(mediaPath.getAbsoluteFile(), fileName.toString()));
|
||||||
|
|
||||||
|
//文件原路径
|
||||||
|
StrBuilder fullPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||||
|
fullPath.append("/");
|
||||||
|
fullPath.append(fileName);
|
||||||
|
|
||||||
|
//压缩文件路径
|
||||||
|
StrBuilder fullSmallPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||||
|
fullSmallPath.append("/");
|
||||||
|
fullSmallPath.append(nameWithOutSuffix);
|
||||||
|
fullSmallPath.append("_small.");
|
||||||
|
fullSmallPath.append(fileSuffix);
|
||||||
|
|
||||||
//压缩图片
|
//压缩图片
|
||||||
Thumbnails.of(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(fileName).toString()).size(256, 256).keepAspectRatio(false).toFile(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(nameWithOutSuffix).append("_small.").append(fileSuffix).toString());
|
Thumbnails.of(fullPath.toString()).size(256, 256).keepAspectRatio(false).toFile(fullSmallPath.toString());
|
||||||
String filePath = new StringBuffer("/upload/").append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth()).append("/").append(fileName).toString();
|
|
||||||
String smallPath = new StringBuffer("/upload/").append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth()).append("/").append(nameWithOutSuffix).append("_small.").append(fileSuffix).toString();
|
//映射路径
|
||||||
String suffix = new StringBuffer(".").append(fileSuffix).toString();
|
StrBuilder filePath = new StrBuilder("/upload/");
|
||||||
String size = HaloUtils.parseSize(new File(mediaPath, fileName).length());
|
filePath.append(DateUtil.thisYear());
|
||||||
String wh = HaloUtils.getImageWh(new File(mediaPath, fileName));
|
filePath.append("/");
|
||||||
resultMap.put("fileName",fileName);
|
filePath.append(DateUtil.thisMonth());
|
||||||
resultMap.put("filePath",filePath);
|
filePath.append("/");
|
||||||
resultMap.put("smallPath",smallPath);
|
filePath.append(fileName);
|
||||||
resultMap.put("suffix",suffix);
|
|
||||||
resultMap.put("size",size);
|
//缩略图映射路径
|
||||||
resultMap.put("wh",wh);
|
StrBuilder fileSmallPath = new StrBuilder("/upload/");
|
||||||
|
fileSmallPath.append(DateUtil.thisYear());
|
||||||
|
fileSmallPath.append("/");
|
||||||
|
fileSmallPath.append(DateUtil.thisMonth());
|
||||||
|
fileSmallPath.append("/");
|
||||||
|
fileSmallPath.append(nameWithOutSuffix);
|
||||||
|
fileSmallPath.append("_small.");
|
||||||
|
fileSmallPath.append(fileSuffix);
|
||||||
|
|
||||||
|
|
||||||
|
String size = HaloUtils.parseSize(new File(fullPath.toString()).length());
|
||||||
|
String wh = HaloUtils.getImageWh(new File(fullPath.toString()));
|
||||||
|
|
||||||
|
resultMap.put("fileName", fileName.toString());
|
||||||
|
resultMap.put("filePath", filePath.toString());
|
||||||
|
resultMap.put("smallPath", fileSmallPath.toString());
|
||||||
|
resultMap.put("suffix", fileSuffix);
|
||||||
|
resultMap.put("size", size);
|
||||||
|
resultMap.put("wh", wh);
|
||||||
resultMap.put("location", AttachLocationEnum.SERVER.getDesc());
|
resultMap.put("location", AttachLocationEnum.SERVER.getDesc());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -196,9 +244,10 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 七牛云上传
|
* 七牛云上传
|
||||||
* @param file
|
*
|
||||||
* @param request
|
* @param file file
|
||||||
* @return
|
* @param request request
|
||||||
|
* @return Map
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request) {
|
public Map<String, String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request) {
|
||||||
|
@ -211,19 +260,19 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
Options domain = optionsRepository.findOptionsByOptionName("qiniu_domain");
|
Options domain = optionsRepository.findOptionsByOptionName("qiniu_domain");
|
||||||
Options bucket = optionsRepository.findOptionsByOptionName("qiniu_bucket");
|
Options bucket = optionsRepository.findOptionsByOptionName("qiniu_bucket");
|
||||||
Options smallUrl = optionsRepository.findOptionsByOptionName("qiniu_small_url");
|
Options smallUrl = optionsRepository.findOptionsByOptionName("qiniu_small_url");
|
||||||
if(accessKey == null || secretKey == null || domain == null || bucket == null){
|
if (accessKey == null || secretKey == null || domain == null || bucket == null) {
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
Auth auth = Auth.create(accessKey.getOptionValue(),secretKey.getOptionValue());
|
Auth auth = Auth.create(accessKey.getOptionValue(), secretKey.getOptionValue());
|
||||||
StringMap putPolicy = new StringMap();
|
StringMap putPolicy = new StringMap();
|
||||||
putPolicy.put("returnBody", "{\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height)}");
|
putPolicy.put("returnBody", "{\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height)}");
|
||||||
String upToken = auth.uploadToken(bucket.getOptionValue(),null,3600,putPolicy);
|
String upToken = auth.uploadToken(bucket.getOptionValue(), null, 3600, putPolicy);
|
||||||
String localTempDir = Paths.get(System.getenv("java.io.tmpdir"),bucket.getOptionValue()).toString();
|
String localTempDir = Paths.get(System.getenv("java.io.tmpdir"), bucket.getOptionValue()).toString();
|
||||||
QiNiuPutSet putSet = new QiNiuPutSet();
|
QiNiuPutSet putSet = new QiNiuPutSet();
|
||||||
try {
|
try {
|
||||||
FileRecorder fileRecorder = new FileRecorder(localTempDir);
|
FileRecorder fileRecorder = new FileRecorder(localTempDir);
|
||||||
UploadManager uploadManager = new UploadManager(cfg,fileRecorder);
|
UploadManager uploadManager = new UploadManager(cfg, fileRecorder);
|
||||||
Response response = uploadManager.put(file.getInputStream(),key,upToken,null,null);
|
Response response = uploadManager.put(file.getInputStream(), key, upToken, null, null);
|
||||||
//解析上传成功的结果
|
//解析上传成功的结果
|
||||||
putSet = new Gson().fromJson(response.bodyString(), QiNiuPutSet.class);
|
putSet = new Gson().fromJson(response.bodyString(), QiNiuPutSet.class);
|
||||||
} catch (QiniuException e) {
|
} catch (QiniuException e) {
|
||||||
|
@ -236,16 +285,16 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
}
|
}
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}catch (IOException e){
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
String filePath = domain.getOptionValue().contains("http://")?domain.getOptionValue().trim():("http://"+domain.getOptionValue().trim()) + "/" + key;
|
String filePath = domain.getOptionValue().contains("http://") ? domain.getOptionValue().trim() : ("http://" + domain.getOptionValue().trim()) + "/" + key;
|
||||||
resultMap.put("fileName",file.getOriginalFilename());
|
resultMap.put("fileName", file.getOriginalFilename());
|
||||||
resultMap.put("filePath",filePath.trim());
|
resultMap.put("filePath", filePath.trim());
|
||||||
resultMap.put("smallPath",smallUrl == null ? filePath.trim():(filePath+smallUrl.getOptionValue()).trim());
|
resultMap.put("smallPath", smallUrl == null ? filePath.trim() : (filePath + smallUrl.getOptionValue()).trim());
|
||||||
resultMap.put("suffix",file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')));
|
resultMap.put("suffix", file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')));
|
||||||
resultMap.put("size",HaloUtils.parseSize(file.getSize()));
|
resultMap.put("size", HaloUtils.parseSize(file.getSize()));
|
||||||
resultMap.put("wh",putSet.getW() + "x" + putSet.getH());
|
resultMap.put("wh", putSet.getW() + "x" + putSet.getH());
|
||||||
resultMap.put("location", AttachLocationEnum.QINIU.getDesc());
|
resultMap.put("location", AttachLocationEnum.QINIU.getDesc());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -255,9 +304,10 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 又拍云上传
|
* 又拍云上传
|
||||||
* @param file
|
*
|
||||||
* @param request
|
* @param file file
|
||||||
* @return
|
* @param request request
|
||||||
|
* @return Map
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> attachUpYunUpload(MultipartFile file, HttpServletRequest request) {
|
public Map<String, String> attachUpYunUpload(MultipartFile file, HttpServletRequest request) {
|
||||||
|
@ -270,30 +320,30 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
Options domain = optionsRepository.findOptionsByOptionName("upyun_oss_domain");
|
Options domain = optionsRepository.findOptionsByOptionName("upyun_oss_domain");
|
||||||
Options operator = optionsRepository.findOptionsByOptionName("upyun_oss_operator");
|
Options operator = optionsRepository.findOptionsByOptionName("upyun_oss_operator");
|
||||||
Options smallUrl = optionsRepository.findOptionsByOptionName("upyun_oss_small");
|
Options smallUrl = optionsRepository.findOptionsByOptionName("upyun_oss_small");
|
||||||
if(ossSrc == null || ossPwd == null || domain == null || bucket == null || operator == null){
|
if (ossSrc == null || ossPwd == null || domain == null || bucket == null || operator == null) {
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.'));
|
String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.'));
|
||||||
UpYun upYun = new UpYun(bucket.getOptionValue(),operator.getOptionValue(),ossPwd.getOptionValue());
|
UpYun upYun = new UpYun(bucket.getOptionValue(), operator.getOptionValue(), ossPwd.getOptionValue());
|
||||||
upYun.setTimeout(60);
|
upYun.setTimeout(60);
|
||||||
upYun.setApiDomain(UpYun.ED_AUTO);
|
upYun.setApiDomain(UpYun.ED_AUTO);
|
||||||
upYun.setDebug(true);
|
upYun.setDebug(true);
|
||||||
upYun.writeFile(ossSrc.getOptionValue()+key+"."+fileSuffix,file.getBytes(),true,null);
|
upYun.writeFile(ossSrc.getOptionValue() + key + "." + fileSuffix, file.getBytes(), true, null);
|
||||||
String filePath = domain.getOptionValue().contains("http://")?domain.getOptionValue().trim():("http://"+domain.getOptionValue().trim() +ossSrc.getOptionValue() + key + "." + fileSuffix);
|
String filePath = domain.getOptionValue().contains("http://") ? domain.getOptionValue().trim() : ("http://" + domain.getOptionValue().trim() + ossSrc.getOptionValue() + key + "." + fileSuffix);
|
||||||
String smallPath = filePath;
|
String smallPath = filePath;
|
||||||
if(smallUrl != null){
|
if (smallUrl != null) {
|
||||||
smallPath += smallUrl.getOptionValue();
|
smallPath += smallUrl.getOptionValue();
|
||||||
}
|
}
|
||||||
BufferedImage image = ImageIO.read(file.getInputStream());
|
BufferedImage image = ImageIO.read(file.getInputStream());
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
resultMap.put("wh",image.getWidth()+"x"+image.getHeight());
|
resultMap.put("wh", image.getWidth() + "x" + image.getHeight());
|
||||||
}
|
}
|
||||||
resultMap.put("fileName",fileName);
|
resultMap.put("fileName", fileName);
|
||||||
resultMap.put("filePath",filePath.trim());
|
resultMap.put("filePath", filePath.trim());
|
||||||
resultMap.put("smallPath",smallPath.trim());
|
resultMap.put("smallPath", smallPath.trim());
|
||||||
resultMap.put("suffix",fileSuffix);
|
resultMap.put("suffix", fileSuffix);
|
||||||
resultMap.put("size",HaloUtils.parseSize(file.getSize()));
|
resultMap.put("size", HaloUtils.parseSize(file.getSize()));
|
||||||
resultMap.put("location", AttachLocationEnum.UPYUN.getDesc());
|
resultMap.put("location", AttachLocationEnum.UPYUN.getDesc());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -304,8 +354,9 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 七牛云删除附件
|
* 七牛云删除附件
|
||||||
* @param key
|
*
|
||||||
* @return
|
* @param key key
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteQiNiuAttachment(String key) {
|
public boolean deleteQiNiuAttachment(String key) {
|
||||||
|
@ -314,7 +365,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
Options accessKey = optionsRepository.findOptionsByOptionName("qiniu_access_key");
|
Options accessKey = optionsRepository.findOptionsByOptionName("qiniu_access_key");
|
||||||
Options secretKey = optionsRepository.findOptionsByOptionName("qiniu_secret_key");
|
Options secretKey = optionsRepository.findOptionsByOptionName("qiniu_secret_key");
|
||||||
Options bucket = optionsRepository.findOptionsByOptionName("qiniu_bucket");
|
Options bucket = optionsRepository.findOptionsByOptionName("qiniu_bucket");
|
||||||
if(accessKey == null || secretKey == null || bucket == null){
|
if (accessKey == null || secretKey == null || bucket == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Auth auth = Auth.create(accessKey.getOptionValue(), secretKey.getOptionValue());
|
Auth auth = Auth.create(accessKey.getOptionValue(), secretKey.getOptionValue());
|
||||||
|
@ -331,8 +382,9 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 又拍云删除附件
|
* 又拍云删除附件
|
||||||
* @param fileName
|
*
|
||||||
* @return
|
* @param fileName fileName
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteUpYunAttachment(String fileName) {
|
public boolean deleteUpYunAttachment(String fileName) {
|
||||||
|
@ -341,13 +393,13 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
Options ossPwd = optionsRepository.findOptionsByOptionName("upyun_oss_pwd");
|
Options ossPwd = optionsRepository.findOptionsByOptionName("upyun_oss_pwd");
|
||||||
Options bucket = optionsRepository.findOptionsByOptionName("upyun_oss_bucket");
|
Options bucket = optionsRepository.findOptionsByOptionName("upyun_oss_bucket");
|
||||||
Options operator = optionsRepository.findOptionsByOptionName("upyun_oss_operator");
|
Options operator = optionsRepository.findOptionsByOptionName("upyun_oss_operator");
|
||||||
if(ossSrc == null || ossPwd == null || bucket == null || operator == null){
|
if (ossSrc == null || ossPwd == null || bucket == null || operator == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UpYun upYun = new UpYun(bucket.getOptionValue(),operator.getOptionValue(),ossPwd.getOptionValue());
|
UpYun upYun = new UpYun(bucket.getOptionValue(), operator.getOptionValue(), ossPwd.getOptionValue());
|
||||||
upYun.setApiDomain(UpYun.ED_AUTO);
|
upYun.setApiDomain(UpYun.ED_AUTO);
|
||||||
try {
|
try {
|
||||||
flag = upYun.deleteFile(ossSrc.getOptionValue()+fileName);
|
flag = upYun.deleteFile(ossSrc.getOptionValue() + fileName);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (UpException e) {
|
} catch (UpException e) {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package cc.ryanc.halo.utils;
|
package cc.ryanc.halo.utils;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.domain.Comment;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Comment;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 拼装评论
|
* 拼装评论
|
||||||
|
|
|
@ -8,6 +8,7 @@ import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||||
import cc.ryanc.halo.model.enums.CommonParamsEnum;
|
import cc.ryanc.halo.model.enums.CommonParamsEnum;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.sun.syndication.feed.rss.Channel;
|
import com.sun.syndication.feed.rss.Channel;
|
||||||
import com.sun.syndication.feed.rss.Content;
|
import com.sun.syndication.feed.rss.Content;
|
||||||
|
@ -16,14 +17,12 @@ import com.sun.syndication.io.FeedException;
|
||||||
import com.sun.syndication.io.WireFeedOutput;
|
import com.sun.syndication.io.WireFeedOutput;
|
||||||
import io.github.biezhi.ome.OhMyEmail;
|
import io.github.biezhi.ome.OhMyEmail;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -52,8 +51,10 @@ public class HaloUtils {
|
||||||
* @return List
|
* @return List
|
||||||
*/
|
*/
|
||||||
public static List<BackupDto> getBackUps(String dir) {
|
public static List<BackupDto> getBackUps(String dir) {
|
||||||
String srcPathStr = System.getProperties().getProperty("user.home") + "/halo/backup/" + dir;
|
StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||||
File srcPath = new File(srcPathStr);
|
srcPathStr.append("/halo/backup/");
|
||||||
|
srcPathStr.append(dir);
|
||||||
|
File srcPath = new File(srcPathStr.toString());
|
||||||
File[] files = srcPath.listFiles();
|
File[] files = srcPath.listFiles();
|
||||||
List<BackupDto> backupDtos = new ArrayList<>();
|
List<BackupDto> backupDtos = new ArrayList<>();
|
||||||
BackupDto backupDto = null;
|
BackupDto backupDto = null;
|
||||||
|
@ -284,7 +285,7 @@ public class HaloUtils {
|
||||||
*
|
*
|
||||||
* @param posts posts
|
* @param posts posts
|
||||||
* @return String
|
* @return String
|
||||||
* @throws FeedException
|
* @throws FeedException FeedException
|
||||||
*/
|
*/
|
||||||
public static String getRss(List<Post> posts) throws FeedException {
|
public static String getRss(List<Post> posts) throws FeedException {
|
||||||
Assert.notEmpty(posts, "posts must not be empty");
|
Assert.notEmpty(posts, "posts must not be empty");
|
||||||
|
@ -341,17 +342,18 @@ public class HaloUtils {
|
||||||
*/
|
*/
|
||||||
public static String getSiteMap(List<Post> posts) {
|
public static String getSiteMap(List<Post> posts) {
|
||||||
Assert.notEmpty(posts, "post mut not be empty");
|
Assert.notEmpty(posts, "post mut not be empty");
|
||||||
|
StrBuilder head = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
|
||||||
String head = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";
|
StrBuilder urlBody = new StrBuilder();
|
||||||
String urlBody = "";
|
|
||||||
String urlItem;
|
|
||||||
String urlPath = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/";
|
String urlPath = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/";
|
||||||
for (Post post : posts) {
|
for (Post post : posts) {
|
||||||
urlItem = "<url><loc>" + urlPath + post.getPostUrl() + "</loc><lastmod>"
|
urlBody.append("<url><loc>");
|
||||||
+ DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") + "</lastmod>" + "</url>";
|
urlBody.append(urlPath);
|
||||||
urlBody += urlItem;
|
urlBody.append(post.getPostUrl());
|
||||||
|
urlBody.append("</loc><lastmod>");
|
||||||
|
urlBody.append(DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
|
||||||
|
urlBody.append("</lastmod></url>");
|
||||||
}
|
}
|
||||||
return head + urlBody + "</urlset>";
|
return head.append(urlBody).append("</urlset>").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -367,46 +369,6 @@ public class HaloUtils {
|
||||||
OhMyEmail.config(properties, userName, password);
|
OhMyEmail.config(properties, userName, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 访问路径获取json数据
|
|
||||||
*
|
|
||||||
* @param enterUrl 路径
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
public static String getHttpResponse(String enterUrl) {
|
|
||||||
Assert.hasText(enterUrl, "enter url must not be blank");
|
|
||||||
|
|
||||||
BufferedReader in = null;
|
|
||||||
StringBuffer result = null;
|
|
||||||
try {
|
|
||||||
URI uri = new URI(enterUrl);
|
|
||||||
URL url = uri.toURL();
|
|
||||||
URLConnection connection = url.openConnection();
|
|
||||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
||||||
connection.setRequestProperty("Charset", "utf-8");
|
|
||||||
connection.connect();
|
|
||||||
result = new StringBuffer();
|
|
||||||
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
String line;
|
|
||||||
while ((line = in.readLine()) != null) {
|
|
||||||
result.append(line);
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (in != null) {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
} catch (Exception e2) {
|
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 百度主动推送
|
* 百度主动推送
|
||||||
*
|
*
|
||||||
|
@ -420,13 +382,17 @@ public class HaloUtils {
|
||||||
Assert.hasText(token, "token must not be blank");
|
Assert.hasText(token, "token must not be blank");
|
||||||
Assert.hasText(urls, "urls must not be blank");
|
Assert.hasText(urls, "urls must not be blank");
|
||||||
|
|
||||||
String url = "http://data.zz.baidu.com/urls?site=" + blogUrl + "&token=" + token;
|
StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
|
||||||
String result = "";
|
url.append(blogUrl);
|
||||||
|
url.append("&token=");
|
||||||
|
url.append(token);
|
||||||
|
|
||||||
|
StrBuilder result = new StrBuilder();
|
||||||
PrintWriter out = null;
|
PrintWriter out = null;
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
try {
|
try {
|
||||||
// 建立URL之间的连接
|
// 建立URL之间的连接
|
||||||
URLConnection conn = new URL(url).openConnection();
|
URLConnection conn = new URL(url.toString()).openConnection();
|
||||||
// 设置通用的请求属性
|
// 设置通用的请求属性
|
||||||
conn.setRequestProperty("Host", "data.zz.baidu.com");
|
conn.setRequestProperty("Host", "data.zz.baidu.com");
|
||||||
conn.setRequestProperty("User-Agent", "curl/7.12.1");
|
conn.setRequestProperty("User-Agent", "curl/7.12.1");
|
||||||
|
@ -446,7 +412,7 @@ public class HaloUtils {
|
||||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
String line;
|
String line;
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
result += line;
|
result.append(line);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -462,7 +428,7 @@ public class HaloUtils {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,11 @@ import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||||
import cc.ryanc.halo.model.enums.ResultCodeEnum;
|
import cc.ryanc.halo.model.enums.ResultCodeEnum;
|
||||||
import cc.ryanc.halo.service.AttachmentService;
|
import cc.ryanc.halo.service.AttachmentService;
|
||||||
import cc.ryanc.halo.service.LogsService;
|
import cc.ryanc.halo.service.LogsService;
|
||||||
import cc.ryanc.halo.utils.HaloUtils;
|
|
||||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.coobird.thumbnailator.Thumbnails;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
@ -27,15 +25,11 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static cc.ryanc.halo.model.enums.AttachLocationEnum.QINIU;
|
import static cc.ryanc.halo.model.enums.AttachLocationEnum.*;
|
||||||
import static cc.ryanc.halo.model.enums.AttachLocationEnum.SERVER;
|
|
||||||
import static cc.ryanc.halo.model.enums.AttachLocationEnum.UPYUN;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -106,7 +100,7 @@ public class AttachmentController {
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/uploadModal")
|
@GetMapping(value = "/uploadModal")
|
||||||
public String uploadModal(){
|
public String uploadModal() {
|
||||||
return "admin/widget/_attachment-upload";
|
return "admin/widget/_attachment-upload";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,11 +116,11 @@ public class AttachmentController {
|
||||||
public Map<String, Object> upload(@RequestParam("file") MultipartFile file,
|
public Map<String, Object> upload(@RequestParam("file") MultipartFile file,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
Map<String, Object> result = new HashMap<>(3);
|
Map<String, Object> result = new HashMap<>(3);
|
||||||
System.out.println("源地址"+file.getOriginalFilename()+"类型"+file.getContentType()+"文件名"+file.getName()+"文件大小"+file.getSize());
|
System.out.println("源地址" + file.getOriginalFilename() + "类型" + file.getContentType() + "文件名" + file.getName() + "文件大小" + file.getSize());
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Map<String,String> resultMap = attachmentService.upload(file,request);
|
Map<String, String> resultMap = attachmentService.upload(file, request);
|
||||||
if(resultMap == null || resultMap.isEmpty()){
|
if (resultMap == null || resultMap.isEmpty()) {
|
||||||
log.error("文件上传失败");
|
log.error("文件上传失败");
|
||||||
result.put("success", 0);
|
result.put("success", 0);
|
||||||
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
|
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
|
||||||
|
@ -195,8 +189,8 @@ public class AttachmentController {
|
||||||
try {
|
try {
|
||||||
//删除数据库中的内容
|
//删除数据库中的内容
|
||||||
attachmentService.removeByAttachId(attachId);
|
attachmentService.removeByAttachId(attachId);
|
||||||
if(attachLocation!=null){
|
if (attachLocation != null) {
|
||||||
if(attachLocation.equals(SERVER.getDesc())){
|
if (attachLocation.equals(SERVER.getDesc())) {
|
||||||
String delSmallFileName = delFileName.substring(0, delFileName.lastIndexOf('.')) + "_small" + attachment.get().getAttachSuffix();
|
String delSmallFileName = delFileName.substring(0, delFileName.lastIndexOf('.')) + "_small" + attachment.get().getAttachSuffix();
|
||||||
//删除文件
|
//删除文件
|
||||||
String userPath = System.getProperties().getProperty("user.home") + "/halo";
|
String userPath = System.getProperties().getProperty("user.home") + "/halo";
|
||||||
|
@ -204,32 +198,28 @@ public class AttachmentController {
|
||||||
File delFile = new File(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(delFileName).toString());
|
File delFile = new File(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(delFileName).toString());
|
||||||
File delSmallFile = new File(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(delSmallFileName).toString());
|
File delSmallFile = new File(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(delSmallFileName).toString());
|
||||||
if (delFile.exists() && delFile.isFile()) {
|
if (delFile.exists() && delFile.isFile()) {
|
||||||
if (delFile.delete() && delSmallFile.delete()) {
|
flag = delFile.delete() && delSmallFile.delete();
|
||||||
flag = true;
|
|
||||||
} else {
|
|
||||||
flag = false;
|
|
||||||
}
|
}
|
||||||
}
|
} else if (attachLocation.equals(QINIU.getDesc())) {
|
||||||
}else if(attachLocation.equals(QINIU.getDesc())){
|
|
||||||
//七牛删除
|
//七牛删除
|
||||||
String attachPath = attachment.get().getAttachPath();
|
String attachPath = attachment.get().getAttachPath();
|
||||||
String key =attachPath.substring(attachPath.lastIndexOf("/")+1);
|
String key = attachPath.substring(attachPath.lastIndexOf("/") + 1);
|
||||||
flag = attachmentService.deleteQiNiuAttachment(key);
|
flag = attachmentService.deleteQiNiuAttachment(key);
|
||||||
}else if(attachLocation.equals(UPYUN.getDesc())){
|
} else if (attachLocation.equals(UPYUN.getDesc())) {
|
||||||
//又拍删除
|
//又拍删除
|
||||||
String attachPath = attachment.get().getAttachPath();
|
String attachPath = attachment.get().getAttachPath();
|
||||||
String fileName =attachPath.substring(attachPath.lastIndexOf("/")+1);
|
String fileName = attachPath.substring(attachPath.lastIndexOf("/") + 1);
|
||||||
flag = attachmentService.deleteUpYunAttachment(fileName);
|
flag = attachmentService.deleteUpYunAttachment(fileName);
|
||||||
}else{
|
} else {
|
||||||
//..
|
//..
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(flag){
|
if (flag) {
|
||||||
log.info("Delete file {} successfully!", delFileName);
|
log.info("Delete file {} successfully!", delFileName);
|
||||||
logsService.saveByLogs(
|
logsService.saveByLogs(
|
||||||
new Logs(LogsRecord.REMOVE_FILE, delFileName, ServletUtil.getClientIP(request), DateUtil.date())
|
new Logs(LogsRecord.REMOVE_FILE, delFileName, ServletUtil.getClientIP(request), DateUtil.date())
|
||||||
);
|
);
|
||||||
}else{
|
} else {
|
||||||
log.error("Deleting attachment {} failed!", delFileName);
|
log.error("Deleting attachment {} failed!", delFileName);
|
||||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-failed"));
|
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-failed"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import cc.ryanc.halo.utils.CommentUtil;
|
||||||
import cc.ryanc.halo.utils.OwoUtil;
|
import cc.ryanc.halo.utils.OwoUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.core.util.URLUtil;
|
import cn.hutool.core.util.URLUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
@ -126,8 +127,13 @@ public class FrontCommentController {
|
||||||
}
|
}
|
||||||
if (comment.getCommentParent() > 0) {
|
if (comment.getCommentParent() > 0) {
|
||||||
lastComment = commentService.findCommentById(comment.getCommentParent()).get();
|
lastComment = commentService.findCommentById(comment.getCommentParent()).get();
|
||||||
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
|
StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
||||||
comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
buildContent.append(lastComment.getCommentId());
|
||||||
|
buildContent.append("'>@");
|
||||||
|
buildContent.append(lastComment.getCommentAuthor());
|
||||||
|
buildContent.append("</a> ");
|
||||||
|
buildContent.append(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
||||||
|
comment.setCommentContent(buildContent.toString());
|
||||||
} else {
|
} else {
|
||||||
//将评论内容的字符专为安全字符
|
//将评论内容的字符专为安全字符
|
||||||
comment.setCommentContent(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
comment.setCommentContent(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
||||||
|
@ -170,13 +176,18 @@ public class FrontCommentController {
|
||||||
try {
|
try {
|
||||||
//发送邮件到博主
|
//发送邮件到博主
|
||||||
Map<String, Object> map = new HashMap<>(5);
|
Map<String, Object> map = new HashMap<>(5);
|
||||||
|
StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||||
|
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||||
|
pageUrl.append("/archives/");
|
||||||
|
} else {
|
||||||
|
pageUrl.append("/p/");
|
||||||
|
}
|
||||||
|
pageUrl.append(post.getPostUrl());
|
||||||
|
pageUrl.append("#comment-id-");
|
||||||
|
pageUrl.append(comment.getCommentId());
|
||||||
|
map.put("pageUrl", pageUrl.toString());
|
||||||
map.put("author", userService.findUser().getUserDisplayName());
|
map.put("author", userService.findUser().getUserDisplayName());
|
||||||
map.put("pageName", post.getPostTitle());
|
map.put("pageName", post.getPostTitle());
|
||||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
|
||||||
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
|
||||||
} else {
|
|
||||||
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
|
||||||
}
|
|
||||||
map.put("visitor", comment.getCommentAuthor());
|
map.put("visitor", comment.getCommentAuthor());
|
||||||
map.put("commentContent", comment.getCommentContent());
|
map.put("commentContent", comment.getCommentContent());
|
||||||
mailService.sendTemplateMail(userService.findUser().getUserEmail(), "有新的评论", map, "common/mail_template/mail_admin.ftl");
|
mailService.sendTemplateMail(userService.findUser().getUserEmail(), "有新的评论", map, "common/mail_template/mail_admin.ftl");
|
||||||
|
@ -207,14 +218,20 @@ public class FrontCommentController {
|
||||||
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
||||||
if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
|
if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
|
||||||
Map<String, Object> map = new HashMap<>(8);
|
Map<String, Object> map = new HashMap<>(8);
|
||||||
|
StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||||
|
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||||
|
pageUrl.append("/archives/");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
pageUrl.append("/p/");
|
||||||
|
}
|
||||||
|
pageUrl.append(post.getPostUrl());
|
||||||
|
pageUrl.append("#comment-id-");
|
||||||
|
pageUrl.append(comment.getCommentId());
|
||||||
|
map.put("pageUrl", pageUrl.toString());
|
||||||
map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
|
map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
|
||||||
map.put("commentAuthor", lastComment.getCommentAuthor());
|
map.put("commentAuthor", lastComment.getCommentAuthor());
|
||||||
map.put("pageName", lastComment.getPost().getPostTitle());
|
map.put("pageName", lastComment.getPost().getPostTitle());
|
||||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
|
||||||
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
|
||||||
} else {
|
|
||||||
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
|
||||||
}
|
|
||||||
map.put("commentContent", lastComment.getCommentContent());
|
map.put("commentContent", lastComment.getCommentContent());
|
||||||
map.put("replyAuthor", comment.getCommentAuthor());
|
map.put("replyAuthor", comment.getCommentAuthor());
|
||||||
map.put("replyContent", comment.getCommentContent());
|
map.put("replyContent", comment.getCommentContent());
|
||||||
|
|
|
@ -1,129 +0,0 @@
|
||||||
#loading{
|
|
||||||
background-color: #fff;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
position: fixed;
|
|
||||||
z-index: 9999;
|
|
||||||
margin-top: 0px;
|
|
||||||
top: 0px;
|
|
||||||
}
|
|
||||||
#loading-center{
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
#loading-center-absolute {
|
|
||||||
position: absolute;
|
|
||||||
left: 50%;
|
|
||||||
top: 50%;
|
|
||||||
height: 60px;
|
|
||||||
width: 60px;
|
|
||||||
margin-top: -30px;
|
|
||||||
margin-left: -30px;
|
|
||||||
-webkit-animation: loading-center-absolute 1s infinite;
|
|
||||||
animation: loading-center-absolute 1s infinite;
|
|
||||||
|
|
||||||
}
|
|
||||||
.object{
|
|
||||||
width: 20px;
|
|
||||||
height: 20px;
|
|
||||||
background-color: skyblue;
|
|
||||||
float: left;
|
|
||||||
-moz-border-radius: 50% 50% 50% 50%;
|
|
||||||
-webkit-border-radius: 50% 50% 50% 50%;
|
|
||||||
border-radius: 50% 50% 50% 50%;
|
|
||||||
margin-right: 20px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
.object:nth-child(2n+0) {
|
|
||||||
margin-right: 0px;
|
|
||||||
|
|
||||||
}
|
|
||||||
#object_one{
|
|
||||||
-webkit-animation: object_one 1s infinite;
|
|
||||||
animation: object_one 1s infinite;
|
|
||||||
}
|
|
||||||
#object_two{
|
|
||||||
-webkit-animation: object_two 1s infinite;
|
|
||||||
animation: object_two 1s infinite;
|
|
||||||
}
|
|
||||||
#object_three{
|
|
||||||
-webkit-animation: object_three 1s infinite;
|
|
||||||
animation: object_three 1s infinite;
|
|
||||||
}
|
|
||||||
#object_four{
|
|
||||||
-webkit-animation: object_four 1s infinite;
|
|
||||||
animation: object_four 1s infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
@-webkit-keyframes loading-center-absolute{
|
|
||||||
100% {
|
|
||||||
-ms-transform: rotate(360deg);
|
|
||||||
-webkit-transform: rotate(360deg);
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@keyframes loading-center-absolute{
|
|
||||||
100% {
|
|
||||||
-ms-transform: rotate(360deg);
|
|
||||||
-webkit-transform: rotate(360deg);
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@-webkit-keyframes object_one{
|
|
||||||
50% {
|
|
||||||
-ms-transform: translate(20px,20px);
|
|
||||||
-webkit-transform: translate(20px,20px);
|
|
||||||
transform: translate(20px,20px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@keyframes object_one{
|
|
||||||
50% {
|
|
||||||
-ms-transform: translate(20px,20px);
|
|
||||||
-webkit-transform: translate(20px,20px);
|
|
||||||
transform: translate(20px,20px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@-webkit-keyframes object_two{
|
|
||||||
50% {
|
|
||||||
-ms-transform: translate(-20px,20px);
|
|
||||||
-webkit-transform: translate(-20px,20px);
|
|
||||||
transform: translate(-20px,20px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@keyframes object_two{
|
|
||||||
50% {
|
|
||||||
-ms-transform: translate(-20px,20px);
|
|
||||||
-webkit-transform: translate(-20px,20px);
|
|
||||||
transform: translate(-20px,20px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@-webkit-keyframes object_three{
|
|
||||||
50% {
|
|
||||||
-ms-transform: translate(20px,-20px);
|
|
||||||
-webkit-transform: translate(20px,-20px);
|
|
||||||
transform: translate(20px,-20px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@keyframes object_three{
|
|
||||||
50% {
|
|
||||||
-ms-transform: translate(20px,-20px);
|
|
||||||
-webkit-transform: translate(20px,-20px);
|
|
||||||
transform: translate(20px,-20px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@-webkit-keyframes object_four{
|
|
||||||
50% {
|
|
||||||
-ms-transform: translate(-20px,-20px);
|
|
||||||
-webkit-transform: translate(-20px,-20px);
|
|
||||||
transform: translate(-20px,-20px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@keyframes object_four{
|
|
||||||
50% {
|
|
||||||
-ms-transform: translate(-20px,-20px);
|
|
||||||
-webkit-transform: translate(-20px,-20px);
|
|
||||||
transform: translate(-20px,-20px);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
#loading{background-color:#fff;height:100%;width:100%;position:fixed;z-index:9999;margin-top:0;top:0}#loading-center{width:100%;height:100%;position:relative}#loading-center-absolute{position:absolute;left:50%;top:50%;height:60px;width:60px;margin-top:-30px;margin-left:-30px;-webkit-animation:loading-center-absolute 1s infinite;animation:loading-center-absolute 1s infinite}.object{width:20px;height:20px;background-color:skyblue;float:left;-moz-border-radius:50% 50% 50% 50%;-webkit-border-radius:50% 50% 50% 50%;border-radius:50% 50% 50% 50%;margin-right:20px;margin-bottom:20px}.object:nth-child(2n+0){margin-right:0}#object_one{-webkit-animation:object_one 1s infinite;animation:object_one 1s infinite}#object_two{-webkit-animation:object_two 1s infinite;animation:object_two 1s infinite}#object_three{-webkit-animation:object_three 1s infinite;animation:object_three 1s infinite}#object_four{-webkit-animation:object_four 1s infinite;animation:object_four 1s infinite}@-webkit-keyframes loading-center-absolute{100%{-ms-transform:rotate(360deg);-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes loading-center-absolute{100%{-ms-transform:rotate(360deg);-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@-webkit-keyframes object_one{50%{-ms-transform:translate(20px,20px);-webkit-transform:translate(20px,20px);transform:translate(20px,20px)}}@keyframes object_one{50%{-ms-transform:translate(20px,20px);-webkit-transform:translate(20px,20px);transform:translate(20px,20px)}}@-webkit-keyframes object_two{50%{-ms-transform:translate(-20px,20px);-webkit-transform:translate(-20px,20px);transform:translate(-20px,20px)}}@keyframes object_two{50%{-ms-transform:translate(-20px,20px);-webkit-transform:translate(-20px,20px);transform:translate(-20px,20px)}}@-webkit-keyframes object_three{50%{-ms-transform:translate(20px,-20px);-webkit-transform:translate(20px,-20px);transform:translate(20px,-20px)}}@keyframes object_three{50%{-ms-transform:translate(20px,-20px);-webkit-transform:translate(20px,-20px);transform:translate(20px,-20px)}}@-webkit-keyframes object_four{50%{-ms-transform:translate(-20px,-20px);-webkit-transform:translate(-20px,-20px);transform:translate(-20px,-20px)}}@keyframes object_four{50%{-ms-transform:translate(-20px,-20px);-webkit-transform:translate(-20px,-20px);transform:translate(-20px,-20px)}}
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -13,7 +13,6 @@
|
||||||
<link rel="stylesheet" href="/static/css/AdminLTE.min.css">
|
<link rel="stylesheet" href="/static/css/AdminLTE.min.css">
|
||||||
<link rel="stylesheet" href="/static/css/skins/_all-skins.min.css">
|
<link rel="stylesheet" href="/static/css/skins/_all-skins.min.css">
|
||||||
<link rel="stylesheet" href="/static/css/style.min.css">
|
<link rel="stylesheet" href="/static/css/style.min.css">
|
||||||
<link rel="stylesheet" href="/static/css/loader.min.css">
|
|
||||||
<link rel="stylesheet" href="/static/plugins/toast/css/jquery.toast.min.css">
|
<link rel="stylesheet" href="/static/plugins/toast/css/jquery.toast.min.css">
|
||||||
<link rel="stylesheet" href="/static/plugins/fileinput/fileinput.min.css">
|
<link rel="stylesheet" href="/static/plugins/fileinput/fileinput.min.css">
|
||||||
<link rel="stylesheet" href="/static/plugins/OwO/OwO.min.css">
|
<link rel="stylesheet" href="/static/plugins/OwO/OwO.min.css">
|
||||||
|
|
Loading…
Reference in New Issue