合并dev分支

pull/69/head
ruibaby 2018-12-05 10:24:33 +08:00
commit 083dbcffcf
20 changed files with 233 additions and 6413 deletions

View File

@ -35,7 +35,7 @@
<lombok.version>1.18.2</lombok.version>
<ehcache.version>3.6.0</ehcache.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>
<qiniu-java-sdk.version>7.2.14</qiniu-java-sdk.version>
<thumbnailator.version>0.4.8</thumbnailator.version>

View File

@ -75,4 +75,9 @@ public class Attachment implements Serializable {
*
*/
private String attachLocation;
/**
* 01
*/
private Integer attachOrigin = 0;
}

View File

@ -61,47 +61,53 @@ public interface AttachmentService {
/**
*
* @param file
* @param request
* @return
*
* @param file file
* @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
* @return
*
*
* @param file file
* @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
* @return
*
* @param file file
* @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
* @return
*
* @param file file
* @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);
/**
*
* @param fileName
* @return
*
* @param fileName fileName
* @return boolean
*/
boolean deleteUpYunAttachment(String fileName);
}

View File

@ -10,6 +10,7 @@ import cc.ryanc.halo.service.AttachmentService;
import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.utils.Md5Util;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.StrBuilder;
import com.UpYun;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
@ -38,7 +39,6 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@ -121,29 +121,30 @@ public class AttachmentServiceImpl implements AttachmentService {
/**
*
* @param file
* @param request
* @return
*
* @param file file
* @param request request
* @return Map
*/
@Override
public Map<String, String> upload(MultipartFile file, HttpServletRequest request) {
Map<String,String> resultMap;
Map<String, String> resultMap;
Options options = optionsRepository.findOptionsByOptionName("attach_loc");
if(options == null){
if (options == null) {
return null;
}
switch (options.getOptionValue()){
switch (options.getOptionValue()) {
case "server":
resultMap = this.attachUpload(file,request);
resultMap = this.attachUpload(file, request);
break;
case "qiniu":
resultMap = this.attachQiNiuUpload(file,request);
resultMap = this.attachQiNiuUpload(file, request);
break;
case "upyun":
resultMap = this.attachUpYunUpload(file,request);
resultMap = this.attachUpYunUpload(file, request);
break;
default:
resultMap = this.attachUpload(file,request);
resultMap = this.attachUpload(file, request);
break;
}
return resultMap;
@ -151,42 +152,89 @@ public class AttachmentServiceImpl implements AttachmentService {
/**
*
* @param file
* @param request
* @return
*
* @param file file
* @param request request
* @return Map
*/
@Override
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 {
//用户目录
String userPath = System.getProperties().getProperty("user.home") + "/halo";
//upload的路径
StringBuffer sbMedia = new StringBuffer("upload/");
StrBuilder uploadPath = new StrBuilder(System.getProperties().getProperty("user.home"));
uploadPath.append("/halo/");
uploadPath.append("upload/");
//获取当前年月以创建目录,如果没有该目录则创建
sbMedia.append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth()).append("/");
File mediaPath = new File(userPath, sbMedia.toString());
uploadPath.append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth()).append("/");
File mediaPath = new File(uploadPath.toString());
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 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());
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();
String size = HaloUtils.parseSize(new File(mediaPath, fileName).length());
String wh = HaloUtils.getImageWh(new File(mediaPath, fileName));
resultMap.put("fileName",fileName);
resultMap.put("filePath",filePath);
resultMap.put("smallPath",smallPath);
resultMap.put("suffix",suffix);
resultMap.put("size",size);
resultMap.put("wh",wh);
Thumbnails.of(fullPath.toString()).size(256, 256).keepAspectRatio(false).toFile(fullSmallPath.toString());
//映射路径
StrBuilder filePath = new StrBuilder("/upload/");
filePath.append(DateUtil.thisYear());
filePath.append("/");
filePath.append(DateUtil.thisMonth());
filePath.append("/");
filePath.append(fileName);
//缩略图映射路径
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());
} catch (IOException e) {
e.printStackTrace();
@ -196,9 +244,10 @@ public class AttachmentServiceImpl implements AttachmentService {
/**
*
* @param file
* @param request
* @return
*
* @param file file
* @param request request
* @return Map
*/
@Override
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 bucket = optionsRepository.findOptionsByOptionName("qiniu_bucket");
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;
}
Auth auth = Auth.create(accessKey.getOptionValue(),secretKey.getOptionValue());
Auth auth = Auth.create(accessKey.getOptionValue(), secretKey.getOptionValue());
StringMap putPolicy = new StringMap();
putPolicy.put("returnBody", "{\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height)}");
String upToken = auth.uploadToken(bucket.getOptionValue(),null,3600,putPolicy);
String localTempDir = Paths.get(System.getenv("java.io.tmpdir"),bucket.getOptionValue()).toString();
String upToken = auth.uploadToken(bucket.getOptionValue(), null, 3600, putPolicy);
String localTempDir = Paths.get(System.getenv("java.io.tmpdir"), bucket.getOptionValue()).toString();
QiNiuPutSet putSet = new QiNiuPutSet();
try {
FileRecorder fileRecorder = new FileRecorder(localTempDir);
UploadManager uploadManager = new UploadManager(cfg,fileRecorder);
Response response = uploadManager.put(file.getInputStream(),key,upToken,null,null);
UploadManager uploadManager = new UploadManager(cfg, fileRecorder);
Response response = uploadManager.put(file.getInputStream(), key, upToken, null, null);
//解析上传成功的结果
putSet = new Gson().fromJson(response.bodyString(), QiNiuPutSet.class);
} catch (QiniuException e) {
@ -236,16 +285,16 @@ public class AttachmentServiceImpl implements AttachmentService {
}
} catch (JsonSyntaxException e) {
e.printStackTrace();
}catch (IOException e){
} catch (IOException e) {
e.printStackTrace();
}
String filePath = domain.getOptionValue().contains("http://")?domain.getOptionValue().trim():("http://"+domain.getOptionValue().trim()) + "/" + key;
resultMap.put("fileName",file.getOriginalFilename());
resultMap.put("filePath",filePath.trim());
resultMap.put("smallPath",smallUrl == null ? filePath.trim():(filePath+smallUrl.getOptionValue()).trim());
resultMap.put("suffix",file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')));
resultMap.put("size",HaloUtils.parseSize(file.getSize()));
resultMap.put("wh",putSet.getW() + "x" + putSet.getH());
String filePath = domain.getOptionValue().contains("http://") ? domain.getOptionValue().trim() : ("http://" + domain.getOptionValue().trim()) + "/" + key;
resultMap.put("fileName", file.getOriginalFilename());
resultMap.put("filePath", filePath.trim());
resultMap.put("smallPath", smallUrl == null ? filePath.trim() : (filePath + smallUrl.getOptionValue()).trim());
resultMap.put("suffix", file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')));
resultMap.put("size", HaloUtils.parseSize(file.getSize()));
resultMap.put("wh", putSet.getW() + "x" + putSet.getH());
resultMap.put("location", AttachLocationEnum.QINIU.getDesc());
} catch (Exception e) {
e.printStackTrace();
@ -255,9 +304,10 @@ public class AttachmentServiceImpl implements AttachmentService {
/**
*
* @param file
* @param request
* @return
*
* @param file file
* @param request request
* @return Map
*/
@Override
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 operator = optionsRepository.findOptionsByOptionName("upyun_oss_operator");
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;
}
String fileName = file.getOriginalFilename();
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.setApiDomain(UpYun.ED_AUTO);
upYun.setDebug(true);
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);
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 smallPath = filePath;
if(smallUrl != null){
if (smallUrl != null) {
smallPath += smallUrl.getOptionValue();
}
BufferedImage image = ImageIO.read(file.getInputStream());
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("filePath",filePath.trim());
resultMap.put("smallPath",smallPath.trim());
resultMap.put("suffix",fileSuffix);
resultMap.put("size",HaloUtils.parseSize(file.getSize()));
resultMap.put("fileName", fileName);
resultMap.put("filePath", filePath.trim());
resultMap.put("smallPath", smallPath.trim());
resultMap.put("suffix", fileSuffix);
resultMap.put("size", HaloUtils.parseSize(file.getSize()));
resultMap.put("location", AttachLocationEnum.UPYUN.getDesc());
} catch (Exception e) {
@ -304,8 +354,9 @@ public class AttachmentServiceImpl implements AttachmentService {
/**
*
* @param key
* @return
*
* @param key key
* @return boolean
*/
@Override
public boolean deleteQiNiuAttachment(String key) {
@ -314,7 +365,7 @@ public class AttachmentServiceImpl implements AttachmentService {
Options accessKey = optionsRepository.findOptionsByOptionName("qiniu_access_key");
Options secretKey = optionsRepository.findOptionsByOptionName("qiniu_secret_key");
Options bucket = optionsRepository.findOptionsByOptionName("qiniu_bucket");
if(accessKey == null || secretKey == null || bucket == null){
if (accessKey == null || secretKey == null || bucket == null) {
return false;
}
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
public boolean deleteUpYunAttachment(String fileName) {
@ -341,13 +393,13 @@ public class AttachmentServiceImpl implements AttachmentService {
Options ossPwd = optionsRepository.findOptionsByOptionName("upyun_oss_pwd");
Options bucket = optionsRepository.findOptionsByOptionName("upyun_oss_bucket");
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;
}
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);
try {
flag = upYun.deleteFile(ossSrc.getOptionValue()+fileName);
flag = upYun.deleteFile(ossSrc.getOptionValue() + fileName);
} catch (IOException e) {
e.printStackTrace();
} catch (UpException e) {

View File

@ -1,14 +1,13 @@
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.Collections;
import java.util.List;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import cc.ryanc.halo.model.domain.Comment;
/**
* <pre>
*

View File

@ -8,6 +8,7 @@ import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
import cc.ryanc.halo.model.enums.CommonParamsEnum;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;
import com.sun.syndication.feed.rss.Channel;
import com.sun.syndication.feed.rss.Content;
@ -16,14 +17,12 @@ import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.WireFeedOutput;
import io.github.biezhi.ome.OhMyEmail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
@ -52,8 +51,10 @@ public class HaloUtils {
* @return List
*/
public static List<BackupDto> getBackUps(String dir) {
String srcPathStr = System.getProperties().getProperty("user.home") + "/halo/backup/" + dir;
File srcPath = new File(srcPathStr);
StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
srcPathStr.append("/halo/backup/");
srcPathStr.append(dir);
File srcPath = new File(srcPathStr.toString());
File[] files = srcPath.listFiles();
List<BackupDto> backupDtos = new ArrayList<>();
BackupDto backupDto = null;
@ -284,7 +285,7 @@ public class HaloUtils {
*
* @param posts posts
* @return String
* @throws FeedException
* @throws FeedException FeedException
*/
public static String getRss(List<Post> posts) throws FeedException {
Assert.notEmpty(posts, "posts must not be empty");
@ -341,17 +342,18 @@ public class HaloUtils {
*/
public static String getSiteMap(List<Post> posts) {
Assert.notEmpty(posts, "post mut not be empty");
String head = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";
String urlBody = "";
String urlItem;
StrBuilder head = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
StrBuilder urlBody = new StrBuilder();
String urlPath = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/";
for (Post post : posts) {
urlItem = "<url><loc>" + urlPath + post.getPostUrl() + "</loc><lastmod>"
+ DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") + "</lastmod>" + "</url>";
urlBody += urlItem;
urlBody.append("<url><loc>");
urlBody.append(urlPath);
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);
}
/**
* 访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(urls, "urls must not be blank");
String url = "http://data.zz.baidu.com/urls?site=" + blogUrl + "&token=" + token;
String result = "";
StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
url.append(blogUrl);
url.append("&token=");
url.append(token);
StrBuilder result = new StrBuilder();
PrintWriter out = null;
BufferedReader in = null;
try {
// 建立URL之间的连接
URLConnection conn = new URL(url).openConnection();
URLConnection conn = new URL(url.toString()).openConnection();
// 设置通用的请求属性
conn.setRequestProperty("Host", "data.zz.baidu.com");
conn.setRequestProperty("User-Agent", "curl/7.12.1");
@ -446,7 +412,7 @@ public class HaloUtils {
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
@ -462,7 +428,7 @@ public class HaloUtils {
ex.printStackTrace();
}
}
return result;
return result.toString();
}
}

View File

@ -8,13 +8,11 @@ import cc.ryanc.halo.model.enums.PostTypeEnum;
import cc.ryanc.halo.model.enums.ResultCodeEnum;
import cc.ryanc.halo.service.AttachmentService;
import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.utils.LocaleMessageUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -27,15 +25,11 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
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.SERVER;
import static cc.ryanc.halo.model.enums.AttachLocationEnum.UPYUN;
import static cc.ryanc.halo.model.enums.AttachLocationEnum.*;
/**
* <pre>
@ -106,7 +100,7 @@ public class AttachmentController {
* @return String
*/
@GetMapping(value = "/uploadModal")
public String uploadModal(){
public String uploadModal() {
return "admin/widget/_attachment-upload";
}
@ -122,11 +116,11 @@ public class AttachmentController {
public Map<String, Object> upload(@RequestParam("file") MultipartFile file,
HttpServletRequest request) {
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()) {
try {
Map<String,String> resultMap = attachmentService.upload(file,request);
if(resultMap == null || resultMap.isEmpty()){
Map<String, String> resultMap = attachmentService.upload(file, request);
if (resultMap == null || resultMap.isEmpty()) {
log.error("文件上传失败");
result.put("success", 0);
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
@ -195,8 +189,8 @@ public class AttachmentController {
try {
//删除数据库中的内容
attachmentService.removeByAttachId(attachId);
if(attachLocation!=null){
if(attachLocation.equals(SERVER.getDesc())){
if (attachLocation != null) {
if (attachLocation.equals(SERVER.getDesc())) {
String delSmallFileName = delFileName.substring(0, delFileName.lastIndexOf('.')) + "_small" + attachment.get().getAttachSuffix();
//删除文件
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 delSmallFile = new File(new StringBuffer(mediaPath.getAbsolutePath()).append("/").append(delSmallFileName).toString());
if (delFile.exists() && delFile.isFile()) {
if (delFile.delete() && delSmallFile.delete()) {
flag = true;
} else {
flag = false;
flag = delFile.delete() && delSmallFile.delete();
}
}
}else if(attachLocation.equals(QINIU.getDesc())){
} else if (attachLocation.equals(QINIU.getDesc())) {
//七牛删除
String attachPath = attachment.get().getAttachPath();
String key =attachPath.substring(attachPath.lastIndexOf("/")+1);
String key = attachPath.substring(attachPath.lastIndexOf("/") + 1);
flag = attachmentService.deleteQiNiuAttachment(key);
}else if(attachLocation.equals(UPYUN.getDesc())){
} else if (attachLocation.equals(UPYUN.getDesc())) {
//又拍删除
String attachPath = attachment.get().getAttachPath();
String fileName =attachPath.substring(attachPath.lastIndexOf("/")+1);
String fileName = attachPath.substring(attachPath.lastIndexOf("/") + 1);
flag = attachmentService.deleteUpYunAttachment(fileName);
}else{
} else {
//..
}
}
if(flag){
if (flag) {
log.info("Delete file {} successfully!", delFileName);
logsService.saveByLogs(
new Logs(LogsRecord.REMOVE_FILE, delFileName, ServletUtil.getClientIP(request), DateUtil.date())
);
}else{
} else {
log.error("Deleting attachment {} failed!", delFileName);
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-failed"));
}

View File

@ -13,6 +13,7 @@ import cc.ryanc.halo.utils.CommentUtil;
import cc.ryanc.halo.utils.OwoUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.crypto.SecureUtil;
@ -126,8 +127,13 @@ public class FrontCommentController {
}
if (comment.getCommentParent() > 0) {
lastComment = commentService.findCommentById(comment.getCommentParent()).get();
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("&lt;br/&gt;", "<br/>")));
StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
buildContent.append(lastComment.getCommentId());
buildContent.append("'>@");
buildContent.append(lastComment.getCommentAuthor());
buildContent.append("</a> ");
buildContent.append(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("&lt;br/&gt;", "<br/>")));
comment.setCommentContent(buildContent.toString());
} else {
//将评论内容的字符专为安全字符
comment.setCommentContent(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("&lt;br/&gt;", "<br/>")));
@ -170,13 +176,18 @@ public class FrontCommentController {
try {
//发送邮件到博主
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("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("commentContent", comment.getCommentContent());
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 (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
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("commentAuthor", lastComment.getCommentAuthor());
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("replyAuthor", comment.getCommentAuthor());
map.put("replyContent", comment.getCommentContent());

View File

@ -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);
}
}

View File

@ -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 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

View File

@ -13,7 +13,6 @@
<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/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/fileinput/fileinput.min.css">
<link rel="stylesheet" href="/static/plugins/OwO/OwO.min.css">