Skip to content

Commit

Permalink
添加云存储支持,包括七牛云、阿里云、腾讯云
Browse files Browse the repository at this point in the history
  • Loading branch information
im-andy committed May 8, 2019
1 parent 9f3f5ad commit e8bed33
Show file tree
Hide file tree
Showing 104 changed files with 845 additions and 154 deletions.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

基于[SpringBoot](https://github.com/spring-projects/spring-boot)搭建的开源个人博客系统,主题基于Hexo主题[hexo-theme-gal](https://github.com/ZEROKISEKI/hexo-theme-gal)进行修改。

技术栈:SpringBoot、Thymeleaf、MySQL、MyBatis-Plus、Lombok、Gson、ehcache、validation、Bootstrap、jQuery、FontAwesome……
技术栈:SpringBoot、Thymeleaf、MySQL、MyBatis-Plus、Lombok、Gson、ehcache、validation、Bootstrap、jQuery、FontAwesome、Jsoup……

示例博客:[周华个人博客](https://www.iszhouhua.com)

Expand Down Expand Up @@ -60,4 +60,34 @@ clean package war:war -Dmaven.test.skip=true

后台访问地址:`http://127.0.0.1:8080/admin`

后台采用前后端分离的方式实现,如需二次开发,需在此下载前端源码:<https://github.com/iszhouhua/blog-vue>
后台采用前后端分离的方式实现,如需二次开发,需在此下载前端源码:<https://github.com/iszhouhua/blog-vue>

------

## 界面展示

![1557279251039](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508093436.png)

![20190508095012](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508095012.png)

![20190508095714](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508095714.png)

![20190508101138](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508101138.png)

![20190508101254](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508101254.png)

![20190508101400](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508101400.png)

![20190508101440](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508101440.png)

![20190508101544](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508101544.png)

![20190508101622](https://raw.githubusercontent.com/iszhouhua/blog/master/data/screenshots/20190508101622.png)

## 2019.5.1

添加规则管理,转载文章时可直接根据规则自动装配内容。

## 2019.5.8

添加云存储支持,包括七牛云、阿里云、腾讯云。
11 changes: 5 additions & 6 deletions data/blog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ CREATE TABLE `blog_config` (
`description` varchar(500) DEFAULT NULL COMMENT '描述',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_name` (`name`) USING BTREE COMMENT '参数名唯一'
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COMMENT='博客配置表';
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COMMENT='博客配置表';

-- ----------------------------
-- Records of blog_config
Expand All @@ -135,11 +135,10 @@ INSERT INTO `blog_config` VALUES ('9', 'AUTHOR_DESCRIPTION', '一二三四五,
INSERT INTO `blog_config` VALUES ('10', 'FILING_ICP', null, '1', 'ICP备案');
INSERT INTO `blog_config` VALUES ('11', 'FILING_SECURITY', null, '1', '公安备案');
INSERT INTO `blog_config` VALUES ('12', 'COMMENT_CHECK', 'false', '2', '评论是否需要校检');
INSERT INTO `blog_config` VALUES ('13', 'IMAGE_HOME', '/data/images/', '2', '图片保存路径');
INSERT INTO `blog_config` VALUES ('14', 'IMAGE_URL', 'http://127.0.0.1:8080/image/', '2', '图片访问路径');
INSERT INTO `blog_config` VALUES ('15', 'BACKGROUND_LIST', '["/images/slide/background1.jpg","/images/slide/background2.jpg","/images/slide/background3.jpg","/images/slide/background4.jpg","/images/slide/background5.jpg","/images/slide/background6.jpg"]', '1', '网站的背景图片集合,格式为JSON数组');
INSERT INTO `blog_config` VALUES ('16', 'BLOG_HEAD', null, '1', '博客头部插入的代码,如站点验证代码等');
INSERT INTO `blog_config` VALUES ('17', 'BLOG_SCRIPT', '<script><!-- 百度推送代码 -->(function(){var bp = document.createElement(''script'');var curProtocol = window.location.protocol.split('':'')[0];if (curProtocol === ''https'') {bp.src = ''https://zz.bdstatic.com/linksubmit/push.js'';}else {bp.src = ''http://push.zhanzhang.baidu.com/push.js'';}var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(bp, s);})();</script>', '1', '博客尾部插入的脚本,如统计代码、推送代码等');
INSERT INTO `blog_config` VALUES ('13', 'BACKGROUND_LIST', '[\"/images/slide/background1.jpg\",\"/images/slide/background2.jpg\",\"/images/slide/background3.jpg\",\"/images/slide/background4.jpg\",\"/images/slide/background5.jpg\",\"/images/slide/background6.jpg\"]', '1', '网站的背景图片集合,格式为JSON数组');
INSERT INTO `blog_config` VALUES ('14', 'BLOG_HEAD', '<meta name=\"google-site-verification\" content=\"_-xMXp-rAz3pUIziyjcIoJ8D9VOV6yb7XrB5qaeq_Fg\" />\n<meta name=\"baidu-site-verification\" content=\"HsvFoNGZDC\" />\n<meta name=\"360-site-verification\" content=\"42179cf63604add68d1e11b26f44c322\" />\n<meta name=\"sogou_site_verification\" content=\"XvRe3wQaqS\"/>\n', '1', '博客头部插入的代码,如站点验证代码等');
INSERT INTO `blog_config` VALUES ('15', 'BLOG_SCRIPT','<script>/*百度统计*/ var _hmt = _hmt || []; (function() { var hm = document.createElement(\"script\"); hm.src = \"https://hm.baidu.com/hm.js?77737a53e73e57c6c44b4640d1c108a1\"; var s = document.getElementsByTagName(\"script\")[0]; s.parentNode.insertBefore(hm, s); })();</script>\n<script>/*百度自动推送*/ (function(){ var bp = document.createElement(\'script\'); var curProtocol = window.location.protocol.split(\':\')[0]; if (curProtocol === \'https\') { bp.src = \'https://zz.bdstatic.com/linksubmit/push.js\'; } else { bp.src = \'http://push.zhanzhang.baidu.com/push.js\'; } var s = document.getElementsByTagName(\"script\")[0]; s.parentNode.insertBefore(bp, s); })(); </script>\n<script>/*360自动收录*/ (function(){ var src = (document.location.protocol == \"http:\") ? \"http://js.passport.qihucdn.com/11.0.1.js?6396cb521d4daf069727dc8d995a3878\":\"https://jspassport.ssl.qhimg.com/11.0.1.js?6396cb521d4daf069727dc8d995a3878\"; document.write(\'<script src=\"\' + src + \'\" id=\"sozz\"><\\/script>\'); })(); </script>\n' , '1', '博客尾部插入的脚本,如统计代码、推送代码等');
INSERT INTO `blog_config` VALUES ('16', 'FILE_STORAGE', '{\"aliyunAccessKeyId\":\"\",\"aliyunAccessKeySecret\":\"\",\"aliyunBucketName\":\"\",\"aliyunDomain\":\"\",\"aliyunEndPoint\":\"\",\"aliyunPrefix\":\"\",\"qcloudBucketName\":\"\",\"qcloudDomain\":\"\",\"qcloudPrefix\":\"\",\"qcloudSecretId\":\"\",\"qcloudSecretKey\":\"\",\"qiniuAccessKey\":\"\",\"qiniuBucketName\":\"\",\"qiniuDomain\":\"\",\"qiniuPrefix\":\"\",\"qiniuSecretKey\":\"\",\"localDirectory\":\"/data/images/\",\"localDomain\":\"http://127.0.0.1:8080/\",\"type\":4,\"localPrefix\":\"upload\"}', '2', '云/本地存储配置信息');
-- ----------------------------
-- Table structure for blog_link
-- ----------------------------
Expand Down
Binary file added data/screenshots/20190508093436.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/screenshots/20190508095012.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/screenshots/20190508095714.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/screenshots/20190508101138.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/screenshots/20190508101254.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/screenshots/20190508101400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/screenshots/20190508101440.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/screenshots/20190508101544.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/screenshots/20190508101622.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<commons-io.version>2.6</commons-io.version>
<thumbnailator.version>0.4.8</thumbnailator.version>
<jsoup.version>1.11.3</jsoup.version>
<qiniu.version>[7.2.0, 7.2.99]</qiniu.version>
<aliyun.oss.version>2.8.3</aliyun.oss.version>
<qcloud.cos.version>4.4</qcloud.cos.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -136,6 +139,30 @@
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
</dependency>
<!-- 七牛云 -->
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>${qiniu.version}</version>
</dependency>
<!-- 阿里云 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>${aliyun.oss.version}</version>
</dependency>
<!-- 腾讯云 -->
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>${qcloud.cos.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.iszhouhua.blog.common.aspect;

import com.google.gson.Gson;
import com.iszhouhua.blog.common.util.GsonUtils;
import com.iszhouhua.blog.common.util.IPUtils;
import com.iszhouhua.blog.model.Log;
import com.iszhouhua.blog.service.LogService;
Expand Down Expand Up @@ -54,6 +55,6 @@ public void before(){
}else{
logService.saveLog(blogLog);
}
log.info("访客记录:{}",new Gson().toJson(blogLog));
log.info("访客记录:{}",GsonUtils.toJson(blogLog));
}
}
11 changes: 8 additions & 3 deletions src/main/java/com/iszhouhua/blog/common/constant/CodeEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum CodeEnum {
*/
FAIL(0),
/**
* 未知错误
* 未知错误/其他异常
*/
UNKNOWN_ERROR(-1),
/**
Expand All @@ -39,9 +39,14 @@ public enum CodeEnum {
NOT_FOUND(40004),

/**
* 文章抓取失败
* 文章抓取失败
*/
SPIDER_ERROR(40005);
SPIDER_ERROR(40005),

/**
* 文件上传异常
*/
UPLOAD_ERROR(40006);

private int value;

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/iszhouhua/blog/common/constant/ConfigConst.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有,侵权必究!
*/

package com.iszhouhua.blog.common.constant;

/**
* 系统参数相关Key
* @author ZhouHua
* @date 2019/05/07
*/
public class ConfigConst {
/**
* 存储配置KEY
*/
public final static String FILE_STORAGE = "FILE_STORAGE";
/**
* 评论是否需要校检之后才显示
*/
public final static String COMMENT_CHECK = "COMMENT_CHECK";
}
4 changes: 2 additions & 2 deletions src/main/java/com/iszhouhua/blog/common/constant/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public interface Const {
int COMMENT_SIZE=10;

/**
* 压缩阈值,超过此大小的图片将被压缩,此处是256kb
* 压缩阈值,超过此大小的图片将被压缩,此处是512kb
*/
long COMPRESSION_SIZE=262144L;
long COMPRESSION_SIZE=524288L;
/**
* 爬虫默认的userAgent
*/
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/iszhouhua/blog/common/constant/StorageType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.iszhouhua.blog.common.constant;

/**
* 数据存储类型
* @author ZhouHua
* @date 2019/5/7
*/
public enum StorageType {
/**
* 七牛云
*/
QINIU(1),
/**
* 阿里云
*/
ALIYUN(2),
/**
* 腾讯云
*/
QCLOUD(3),
/**
* 本地
*/
LOCAL(4);

private int value;

StorageType(int value){
this.value = value;
}

public int getValue(){
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.iszhouhua.blog.common.storage;

import com.aliyun.oss.OSSClient;
import com.iszhouhua.blog.common.constant.CodeEnum;
import com.iszhouhua.blog.common.exception.BlogException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
* 阿里云存储
*/
public class AliyunCloudStorage extends BaseStorage {
private OSSClient client;

public AliyunCloudStorage(StorageConfig config){
super(config);
//初始化
init();
}

private void init(){
client = new OSSClient(config.getAliyunEndPoint(), config.getAliyunAccessKeyId(),
config.getAliyunAccessKeySecret());
}

@Override
public String upload(byte[] data, String path) {
return upload(new ByteArrayInputStream(data), path);
}

@Override
public String upload(InputStream inputStream, String path) {
try {
client.putObject(config.getAliyunBucketName(), path, inputStream);
} catch (Exception e){
throw new BlogException(CodeEnum.UPLOAD_ERROR.getValue(),"上传文件失败,请检查配置信息", e);
}
String domain=config.getAliyunDomain();
if(!domain.endsWith("/")){domain+="/";}
return domain + path;
}

@Override
public String uploadSuffix(byte[] data, String suffix) {
return upload(data, getPath(config.getAliyunPrefix(), suffix));
}

@Override
public String uploadSuffix(InputStream inputStream, String suffix) {
return upload(inputStream, getPath(config.getAliyunPrefix(), suffix));
}
}
71 changes: 71 additions & 0 deletions src/main/java/com/iszhouhua/blog/common/storage/BaseStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.iszhouhua.blog.common.storage;

import com.iszhouhua.blog.common.util.Result;
import org.apache.commons.lang3.StringUtils;
import org.thymeleaf.util.DateUtils;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.UUID;

/**
* 数据存储(支持本地、七牛云、阿里云、腾讯云)
*/
public abstract class BaseStorage {
/** 云存储配置信息 */
StorageConfig config;

BaseStorage(StorageConfig config){
this.config = config;
}

/**
* 文件路径
* @param prefix 前缀
* @param suffix 后缀
* @return 返回上传路径
*/
String getPath(String prefix, String suffix) {
//文件路径
LocalDateTime dateTime=LocalDateTime.now();
String path = dateTime.getYear() + "/" + dateTime.getMonthValue()+"/" + dateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
if(StringUtils.isNotBlank(prefix)){
path = prefix.endsWith("/")?prefix + path:prefix + "/" + path;
}
return path + suffix;
}

/**
* 文件上传
* @param data 文件字节数组
* @param path 文件路径,包含文件名
* @return 返回http地址
*/
public abstract String upload(byte[] data, String path);

/**
* 文件上传
* @param data 文件字节数组
* @param suffix 后缀
* @return 返回http地址
*/
public abstract String uploadSuffix(byte[] data, String suffix);

/**
* 文件上传
* @param inputStream 字节流
* @param path 文件路径,包含文件名
* @return 返回http地址
*/
public abstract String upload(InputStream inputStream, String path);

/**
* 文件上传
* @param inputStream 字节流
* @param suffix 后缀
* @return 返回http地址
*/
public abstract String uploadSuffix(InputStream inputStream, String suffix);

}
Loading

0 comments on commit e8bed33

Please sign in to comment.