-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
845 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/iszhouhua/blog/common/constant/ConfigConst.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/iszhouhua/blog/common/constant/StorageType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/iszhouhua/blog/common/storage/AliyunCloudStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
71
src/main/java/com/iszhouhua/blog/common/storage/BaseStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
Oops, something went wrong.