parent
e1e26d53e6
commit
940b996e2d
12
pom.xml
12
pom.xml
@ -45,11 +45,7 @@
|
||||
<guava.version>30.0-jre</guava.version>
|
||||
|
||||
<!-- OSS 配置 -->
|
||||
<qiniu.version>7.9.5</qiniu.version>
|
||||
<aliyun.oss.version>3.14.0</aliyun.oss.version>
|
||||
<qcloud.cos.version>5.6.72</qcloud.cos.version>
|
||||
<minio.version>8.3.8</minio.version>
|
||||
|
||||
<aws-java-sdk-s3.version>1.12.215</aws-java-sdk-s3.version>
|
||||
<!-- SMS 配置 -->
|
||||
<aliyun.sms.version>2.0.9</aliyun.sms.version>
|
||||
<tencent.sms.version>3.1.500</tencent.sms.version>
|
||||
@ -196,6 +192,12 @@
|
||||
<version>${okhttp.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<version>${aws-java-sdk-s3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
|
@ -24,34 +24,8 @@
|
||||
</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>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>${minio.version}</version>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
@ -35,6 +35,11 @@ public interface OssConstant {
|
||||
*/
|
||||
List<Integer> SYSTEM_DATA_IDS = Arrays.asList(1, 2, 3, 4);
|
||||
|
||||
/**
|
||||
* 云服务商
|
||||
*/
|
||||
String[] CLOUD_SERVICE = new String[] {"aliyun", "qcloud", "qiniu"};
|
||||
|
||||
/**
|
||||
* https 状态
|
||||
*/
|
||||
|
188
ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java
Normal file
188
ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java
Normal file
@ -0,0 +1,188 @@
|
||||
package com.ruoyi.oss.core;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.amazonaws.ClientConfiguration;
|
||||
import com.amazonaws.Protocol;
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.AWSCredentialsProvider;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.model.CannedAccessControlList;
|
||||
import com.amazonaws.services.s3.model.CreateBucketRequest;
|
||||
import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
import com.amazonaws.services.s3.model.PutObjectRequest;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.oss.constant.OssConstant;
|
||||
import com.ruoyi.oss.entity.UploadResult;
|
||||
import com.ruoyi.oss.enumd.PolicyType;
|
||||
import com.ruoyi.oss.exception.OssException;
|
||||
import com.ruoyi.oss.properties.OssProperties;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* S3 存储协议 所有兼容S3协议的云厂商均支持
|
||||
* 阿里云 腾讯云 七牛云 minio
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public class OssClient {
|
||||
|
||||
private final String configKey;
|
||||
|
||||
private final OssProperties properties;
|
||||
|
||||
private final AmazonS3 client;
|
||||
|
||||
public OssClient(String configKey, OssProperties ossProperties) {
|
||||
this.configKey = configKey;
|
||||
this.properties = ossProperties;
|
||||
try {
|
||||
AwsClientBuilder.EndpointConfiguration endpointConfig =
|
||||
new AwsClientBuilder.EndpointConfiguration(properties.getEndpoint(), properties.getRegion());
|
||||
|
||||
AWSCredentials credentials = new BasicAWSCredentials(properties.getAccessKey(), properties.getSecretKey());
|
||||
AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
|
||||
ClientConfiguration clientConfig = new ClientConfiguration();
|
||||
if (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) {
|
||||
clientConfig.setProtocol(Protocol.HTTPS);
|
||||
} else {
|
||||
clientConfig.setProtocol(Protocol.HTTP);
|
||||
}
|
||||
this.client = AmazonS3Client.builder()
|
||||
.withEndpointConfiguration(endpointConfig)
|
||||
.withClientConfiguration(clientConfig)
|
||||
.withCredentials(credentialsProvider)
|
||||
.disableChunkedEncoding()
|
||||
.build();
|
||||
|
||||
createBucket();
|
||||
} catch (Exception e) {
|
||||
if (e instanceof OssException) {
|
||||
throw e;
|
||||
}
|
||||
throw new OssException("配置错误! 请检查系统配置:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public void createBucket() {
|
||||
try {
|
||||
String bucketName = properties.getBucketName();
|
||||
if (client.doesBucketExistV2(bucketName)) {
|
||||
return;
|
||||
}
|
||||
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
|
||||
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
|
||||
client.createBucket(createBucketRequest);
|
||||
client.setBucketPolicy(bucketName, getPolicy(bucketName, PolicyType.READ));
|
||||
} catch (Exception e) {
|
||||
throw new OssException("创建Bucket失败, 请核对配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||
return upload(new ByteArrayInputStream(data), path, contentType);
|
||||
}
|
||||
|
||||
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
||||
try {
|
||||
ObjectMetadata metadata = new ObjectMetadata();
|
||||
metadata.setContentType(contentType);
|
||||
metadata.setContentLength(inputStream.available());
|
||||
client.putObject(new PutObjectRequest(properties.getBucketName(), path, inputStream, metadata));
|
||||
} catch (Exception e) {
|
||||
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
return UploadResult.builder().url(getUrl() + "/" + path).filename(path).build();
|
||||
}
|
||||
|
||||
public void delete(String path) {
|
||||
path = path.replace(getUrl() + "/", "");
|
||||
try {
|
||||
client.deleteObject(properties.getBucketName(), path);
|
||||
} catch (Exception e) {
|
||||
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||
return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
String domain = properties.getDomain();
|
||||
if (StringUtils.isNotBlank(domain)) {
|
||||
return domain;
|
||||
}
|
||||
String endpoint = properties.getEndpoint();
|
||||
String header = OssConstant.IS_HTTPS.equals(properties.getIsHttps()) ? "https://" : "http://";
|
||||
// 云服务商直接返回
|
||||
if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)){
|
||||
return header + properties.getBucketName() + "." + endpoint;
|
||||
}
|
||||
// minio 单独处理
|
||||
return header + endpoint + "/" + properties.getBucketName();
|
||||
}
|
||||
|
||||
public String getPath(String prefix, String suffix) {
|
||||
// 生成uuid
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
// 文件路径
|
||||
String path = DateUtils.datePath() + "/" + uuid;
|
||||
if (StringUtils.isNotBlank(prefix)) {
|
||||
path = prefix + "/" + path;
|
||||
}
|
||||
return path + suffix;
|
||||
}
|
||||
|
||||
|
||||
public String getConfigKey() {
|
||||
return configKey;
|
||||
}
|
||||
|
||||
private static String getPolicy(String bucketName, PolicyType policyType) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("{\n\"Statement\": [\n{\n\"Action\": [\n");
|
||||
if (policyType == PolicyType.WRITE) {
|
||||
builder.append("\"s3:GetBucketLocation\",\n\"s3:ListBucketMultipartUploads\"\n");
|
||||
} else if (policyType == PolicyType.READ_WRITE) {
|
||||
builder.append("\"s3:GetBucketLocation\",\n\"s3:ListBucket\",\n\"s3:ListBucketMultipartUploads\"\n");
|
||||
} else {
|
||||
builder.append("\"s3:GetBucketLocation\"\n");
|
||||
}
|
||||
builder.append("],\n\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
|
||||
builder.append(bucketName);
|
||||
builder.append("\"\n},\n");
|
||||
if (policyType == PolicyType.READ) {
|
||||
builder.append("{\n\"Action\": [\n\"s3:ListBucket\"\n],\n\"Effect\": \"Deny\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
|
||||
builder.append(bucketName);
|
||||
builder.append("\"\n},\n");
|
||||
}
|
||||
builder.append("{\n\"Action\": ");
|
||||
switch (policyType) {
|
||||
case WRITE:
|
||||
builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n");
|
||||
break;
|
||||
case READ_WRITE:
|
||||
builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:GetObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n");
|
||||
break;
|
||||
default:
|
||||
builder.append("\"s3:GetObject\",\n");
|
||||
break;
|
||||
}
|
||||
builder.append("\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
|
||||
builder.append(bucketName);
|
||||
builder.append("/*\"\n}\n],\n\"Version\": \"2012-10-17\"\n}\n");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.ruoyi.oss.enumd;
|
||||
|
||||
import com.ruoyi.oss.service.impl.AliyunOssStrategy;
|
||||
import com.ruoyi.oss.service.impl.MinioOssStrategy;
|
||||
import com.ruoyi.oss.service.impl.QcloudOssStrategy;
|
||||
import com.ruoyi.oss.service.impl.QiniuOssStrategy;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 对象存储服务商枚举
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum OssEnumd {
|
||||
|
||||
/**
|
||||
* 七牛云
|
||||
*/
|
||||
QINIU("qiniu", QiniuOssStrategy.class),
|
||||
|
||||
/**
|
||||
* 阿里云
|
||||
*/
|
||||
ALIYUN("aliyun", AliyunOssStrategy.class),
|
||||
|
||||
/**
|
||||
* 腾讯云
|
||||
*/
|
||||
QCLOUD("qcloud", QcloudOssStrategy.class),
|
||||
|
||||
/**
|
||||
* minio
|
||||
*/
|
||||
MINIO("minio", MinioOssStrategy.class);
|
||||
|
||||
private final String value;
|
||||
|
||||
private final Class<?> beanClass;
|
||||
|
||||
public static OssEnumd find(String value) {
|
||||
for (OssEnumd enumd : values()) {
|
||||
if (enumd.getValue().equals(value)) {
|
||||
return enumd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +1,3 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the dreamlu.net developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: Chill 庄骞 (smallchill@163.com)
|
||||
*/
|
||||
package com.ruoyi.oss.enumd;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -3,15 +3,15 @@ package com.ruoyi.oss.factory;
|
||||
import com.ruoyi.common.utils.JsonUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.redis.RedisUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.oss.constant.OssConstant;
|
||||
import com.ruoyi.oss.enumd.OssEnumd;
|
||||
import com.ruoyi.oss.core.OssClient;
|
||||
import com.ruoyi.oss.exception.OssException;
|
||||
import com.ruoyi.oss.properties.OssProperties;
|
||||
import com.ruoyi.oss.service.IOssStrategy;
|
||||
import com.ruoyi.oss.service.abstractd.AbstractOssStrategy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 文件上传Factory
|
||||
*
|
||||
@ -20,17 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public class OssFactory {
|
||||
|
||||
private static final Map<String, OssClient> CLIENT_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 初始化工厂
|
||||
*/
|
||||
public static void init() {
|
||||
log.info("初始化OSS工厂");
|
||||
RedisUtils.subscribe(OssConstant.CACHE_CONFIG_KEY, String.class, type -> {
|
||||
AbstractOssStrategy strategy = getStrategy(type);
|
||||
RedisUtils.subscribe(OssConstant.CACHE_CONFIG_KEY, String.class, configKey -> {
|
||||
OssClient client = getClient(configKey);
|
||||
// 未初始化不处理
|
||||
if (strategy.isInit) {
|
||||
refresh(type);
|
||||
log.info("订阅刷新OSS配置 => " + type);
|
||||
if (client != null) {
|
||||
refresh(configKey);
|
||||
log.info("订阅刷新OSS配置 => " + configKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -38,42 +40,38 @@ public class OssFactory {
|
||||
/**
|
||||
* 获取默认实例
|
||||
*/
|
||||
public static IOssStrategy instance() {
|
||||
public static OssClient instance() {
|
||||
// 获取redis 默认类型
|
||||
String type = RedisUtils.getCacheObject(OssConstant.CACHE_CONFIG_KEY);
|
||||
if (StringUtils.isEmpty(type)) {
|
||||
String configKey = RedisUtils.getCacheObject(OssConstant.CACHE_CONFIG_KEY);
|
||||
if (StringUtils.isEmpty(configKey)) {
|
||||
throw new OssException("文件存储服务类型无法找到!");
|
||||
}
|
||||
return instance(type);
|
||||
return instance(configKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型获取实例
|
||||
*/
|
||||
public static IOssStrategy instance(String type) {
|
||||
OssEnumd enumd = OssEnumd.find(type);
|
||||
if (enumd == null) {
|
||||
throw new OssException("文件存储服务类型无法找到!");
|
||||
public static OssClient instance(String configKey) {
|
||||
OssClient client = getClient(configKey);
|
||||
if (client == null) {
|
||||
refresh(configKey);
|
||||
return getClient(configKey);
|
||||
}
|
||||
AbstractOssStrategy strategy = getStrategy(type);
|
||||
if (!strategy.isInit) {
|
||||
refresh(type);
|
||||
}
|
||||
return strategy;
|
||||
return client;
|
||||
}
|
||||
|
||||
private static void refresh(String type) {
|
||||
Object json = RedisUtils.getCacheObject(OssConstant.SYS_OSS_KEY + type);
|
||||
private static void refresh(String configKey) {
|
||||
Object json = RedisUtils.getCacheObject(OssConstant.SYS_OSS_KEY + configKey);
|
||||
OssProperties properties = JsonUtils.parseObject(json.toString(), OssProperties.class);
|
||||
if (properties == null) {
|
||||
throw new OssException("系统异常, '" + type + "'配置信息不存在!");
|
||||
throw new OssException("系统异常, '" + configKey + "'配置信息不存在!");
|
||||
}
|
||||
getStrategy(type).init(properties);
|
||||
CLIENT_CACHE.put(configKey, new OssClient(configKey, properties));
|
||||
}
|
||||
|
||||
private static AbstractOssStrategy getStrategy(String type) {
|
||||
OssEnumd enumd = OssEnumd.find(type);
|
||||
return (AbstractOssStrategy) SpringUtils.getBean(enumd.getBeanClass());
|
||||
private static OssClient getClient(String configKey) {
|
||||
return CLIENT_CACHE.get(configKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,15 @@ import lombok.Data;
|
||||
public class OssProperties {
|
||||
|
||||
/**
|
||||
* 域名
|
||||
* 访问站点
|
||||
*/
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* 自定义域名
|
||||
*/
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 前缀
|
||||
*/
|
||||
|
@ -1,73 +0,0 @@
|
||||
package com.ruoyi.oss.service;
|
||||
|
||||
import com.ruoyi.oss.entity.UploadResult;
|
||||
import com.ruoyi.oss.enumd.OssEnumd;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 对象存储策略
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public interface IOssStrategy {
|
||||
|
||||
/**
|
||||
* 创建存储桶
|
||||
*/
|
||||
void createBucket();
|
||||
|
||||
/**
|
||||
* 获取服务商类型
|
||||
* @return 对象存储服务商枚举
|
||||
*/
|
||||
OssEnumd getServiceType();
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param data 文件字节数组
|
||||
* @param path 文件路径,包含文件名
|
||||
* @param contentType 文件类型
|
||||
* @return 返回http地址
|
||||
*/
|
||||
UploadResult upload(byte[] data, String path, String contentType);
|
||||
|
||||
/**
|
||||
* 文件删除
|
||||
*
|
||||
* @param path 文件路径,包含文件名
|
||||
*/
|
||||
void delete(String path);
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param data 文件字节数组
|
||||
* @param suffix 后缀
|
||||
* @param contentType 文件类型
|
||||
* @return 返回http地址
|
||||
*/
|
||||
UploadResult uploadSuffix(byte[] data, String suffix, String contentType);
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param inputStream 字节流
|
||||
* @param path 文件路径,包含文件名
|
||||
* @param contentType 文件类型
|
||||
* @return 返回http地址
|
||||
*/
|
||||
UploadResult upload(InputStream inputStream, String path, String contentType);
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param inputStream 字节流
|
||||
* @param suffix 后缀
|
||||
* @param contentType 文件类型
|
||||
* @return 返回http地址
|
||||
*/
|
||||
UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType);
|
||||
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package com.ruoyi.oss.service.abstractd;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.oss.entity.UploadResult;
|
||||
import com.ruoyi.oss.enumd.OssEnumd;
|
||||
import com.ruoyi.oss.properties.OssProperties;
|
||||
import com.ruoyi.oss.service.IOssStrategy;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 对象存储策略(支持七牛、阿里云、腾讯云、minio)
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public abstract class AbstractOssStrategy implements IOssStrategy {
|
||||
|
||||
protected OssProperties properties;
|
||||
public boolean isInit = false;
|
||||
|
||||
public void init(OssProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void createBucket();
|
||||
|
||||
@Override
|
||||
public abstract OssEnumd getServiceType();
|
||||
|
||||
public String getPath(String prefix, String suffix) {
|
||||
// 生成uuid
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
// 文件路径
|
||||
String path = DateUtils.datePath() + "/" + uuid;
|
||||
if (StringUtils.isNotBlank(prefix)) {
|
||||
path = prefix + "/" + path;
|
||||
}
|
||||
return path + suffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract UploadResult upload(byte[] data, String path, String contentType);
|
||||
|
||||
@Override
|
||||
public abstract void delete(String path);
|
||||
|
||||
@Override
|
||||
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
||||
byte[] data = IoUtil.readBytes(inputStream);
|
||||
return this.upload(data, path, contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract UploadResult uploadSuffix(byte[] data, String suffix, String contentType);
|
||||
|
||||
@Override
|
||||
public abstract UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType);
|
||||
|
||||
/**
|
||||
* 获取域名访问链接
|
||||
*
|
||||
* @return 域名访问链接
|
||||
*/
|
||||
public abstract String getEndpointLink();
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
package com.ruoyi.oss.service.impl;
|
||||
|
||||
import com.aliyun.oss.ClientConfiguration;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
|
||||
import com.aliyun.oss.common.comm.Protocol;
|
||||
import com.aliyun.oss.model.CannedAccessControlList;
|
||||
import com.aliyun.oss.model.CreateBucketRequest;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.oss.constant.OssConstant;
|
||||
import com.ruoyi.oss.entity.UploadResult;
|
||||
import com.ruoyi.oss.enumd.OssEnumd;
|
||||
import com.ruoyi.oss.exception.OssException;
|
||||
import com.ruoyi.oss.properties.OssProperties;
|
||||
import com.ruoyi.oss.service.abstractd.AbstractOssStrategy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 阿里云存储策略
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Component
|
||||
public class AliyunOssStrategy extends AbstractOssStrategy {
|
||||
|
||||
private OSSClient client;
|
||||
|
||||
@Override
|
||||
public void init(OssProperties ossProperties) {
|
||||
super.init(ossProperties);
|
||||
try {
|
||||
ClientConfiguration configuration = new ClientConfiguration();
|
||||
if (OssConstant.IS_HTTPS.equals(ossProperties.getIsHttps())) {
|
||||
configuration.setProtocol(Protocol.HTTPS);
|
||||
}
|
||||
DefaultCredentialProvider credentialProvider = new DefaultCredentialProvider(
|
||||
properties.getAccessKey(), properties.getSecretKey());
|
||||
client = new OSSClient(properties.getEndpoint(), credentialProvider, configuration);
|
||||
createBucket();
|
||||
} catch (Exception e) {
|
||||
throw new OssException("阿里云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
|
||||
}
|
||||
isInit = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createBucket() {
|
||||
try {
|
||||
String bucketName = properties.getBucketName();
|
||||
if (client.doesBucketExist(bucketName)) {
|
||||
return;
|
||||
}
|
||||
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
|
||||
createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
|
||||
client.createBucket(createBucketRequest);
|
||||
} catch (Exception e) {
|
||||
throw new OssException("创建Bucket失败, 请核对阿里云配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssEnumd getServiceType() {
|
||||
return OssEnumd.ALIYUN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||
return upload(new ByteArrayInputStream(data), path, contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
||||
try {
|
||||
ObjectMetadata metadata = new ObjectMetadata();
|
||||
metadata.setContentType(contentType);
|
||||
client.putObject(new PutObjectRequest(properties.getBucketName(), path, inputStream, metadata));
|
||||
} catch (Exception e) {
|
||||
throw new OssException("上传文件失败,请检查阿里云配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
return UploadResult.builder().url(getEndpointLink() + "/" + path).filename(path).build(); }
|
||||
|
||||
@Override
|
||||
public void delete(String path) {
|
||||
path = path.replace(getEndpointLink() + "/", "");
|
||||
try {
|
||||
client.deleteObject(properties.getBucketName(), path);
|
||||
} catch (Exception e) {
|
||||
throw new OssException("上传文件失败,请检查阿里云配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||
return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEndpointLink() {
|
||||
String endpoint = properties.getEndpoint();
|
||||
StringBuilder sb = new StringBuilder(endpoint);
|
||||
if (StringUtils.containsAnyIgnoreCase(endpoint, "http://")) {
|
||||
sb.insert(7, properties.getBucketName() + ".");
|
||||
} else if (StringUtils.containsAnyIgnoreCase(endpoint, "https://")) {
|
||||
sb.insert(8, properties.getBucketName() + ".");
|
||||
} else {
|
||||
throw new OssException("Endpoint配置错误");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,194 +0,0 @@
|
||||
package com.ruoyi.oss.service.impl;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.oss.constant.OssConstant;
|
||||
import com.ruoyi.oss.entity.UploadResult;
|
||||
import com.ruoyi.oss.enumd.OssEnumd;
|
||||
import com.ruoyi.oss.enumd.PolicyType;
|
||||
import com.ruoyi.oss.exception.OssException;
|
||||
import com.ruoyi.oss.properties.OssProperties;
|
||||
import com.ruoyi.oss.service.abstractd.AbstractOssStrategy;
|
||||
import io.minio.*;
|
||||
import io.minio.http.HttpUtils;
|
||||
import okhttp3.HttpUrl;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* minio存储策略
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Component
|
||||
public class MinioOssStrategy extends AbstractOssStrategy {
|
||||
|
||||
private MinioClient minioClient;
|
||||
|
||||
@Override
|
||||
public void init(OssProperties ossProperties) {
|
||||
super.init(ossProperties);
|
||||
try {
|
||||
MinioClient.Builder builder = MinioClient.builder();
|
||||
if (OssConstant.IS_HTTPS.equals(ossProperties.getIsHttps())) {
|
||||
HttpUrl url = HttpUtils.getBaseUrl(properties.getEndpoint())
|
||||
.newBuilder().scheme("https").build();
|
||||
builder.endpoint(url);
|
||||
} else {
|
||||
builder.endpoint(properties.getEndpoint());
|
||||
}
|
||||
minioClient = builder.credentials(properties.getAccessKey(), properties.getSecretKey()).build();
|
||||
createBucket();
|
||||
} catch (Exception e) {
|
||||
throw new OssException("Minio存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
|
||||
}
|
||||
isInit = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createBucket() {
|
||||
try {
|
||||
String bucketName = properties.getBucketName();
|
||||
boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
// 不存在就创建桶
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.config(getPolicy(bucketName, PolicyType.READ))
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
throw new OssException("创建Bucket失败, 请核对Minio配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssEnumd getServiceType() {
|
||||
return OssEnumd.MINIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||
return upload(new ByteArrayInputStream(data), path, contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
||||
try {
|
||||
// 解决 inputStream.available() 再 socket 下传输延迟问题 导致获取数值不精确
|
||||
Thread.sleep(1000);
|
||||
minioClient.putObject(PutObjectArgs.builder()
|
||||
.bucket(properties.getBucketName())
|
||||
.object(path)
|
||||
.contentType(StringUtils.blankToDefault(contentType, MediaType.APPLICATION_OCTET_STREAM_VALUE))
|
||||
.stream(inputStream, inputStream.available(), -1)
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
throw new OssException("上传文件失败,请核对Minio配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
return UploadResult.builder().url(getEndpointLink() + "/" + path).filename(path).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String path) {
|
||||
path = path.replace(getEndpointLink() + "/", "");
|
||||
try {
|
||||
minioClient.removeObject(RemoveObjectArgs.builder()
|
||||
.bucket(properties.getBucketName())
|
||||
.object(path)
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
throw new OssException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||
return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEndpointLink() {
|
||||
return properties.getEndpoint() + "/" + properties.getBucketName();
|
||||
}
|
||||
|
||||
private String getPolicy(String bucketName, PolicyType policyType) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("{\n");
|
||||
builder.append(" \"Statement\": [\n");
|
||||
builder.append(" {\n");
|
||||
builder.append(" \"Action\": [\n");
|
||||
if (policyType == PolicyType.WRITE) {
|
||||
builder.append(" \"s3:GetBucketLocation\",\n");
|
||||
builder.append(" \"s3:ListBucketMultipartUploads\"\n");
|
||||
} else if (policyType == PolicyType.READ_WRITE) {
|
||||
builder.append(" \"s3:GetBucketLocation\",\n");
|
||||
builder.append(" \"s3:ListBucket\",\n");
|
||||
builder.append(" \"s3:ListBucketMultipartUploads\"\n");
|
||||
} else {
|
||||
builder.append(" \"s3:GetBucketLocation\"\n");
|
||||
}
|
||||
builder.append(" ],\n");
|
||||
builder.append(" \"Effect\": \"Allow\",\n");
|
||||
builder.append(" \"Principal\": \"*\",\n");
|
||||
builder.append(" \"Resource\": \"arn:aws:s3:::");
|
||||
builder.append(bucketName);
|
||||
builder.append("\"\n");
|
||||
builder.append(" },\n");
|
||||
if (PolicyType.READ.equals(policyType)) {
|
||||
builder.append(" {\n");
|
||||
builder.append(" \"Action\": [\n");
|
||||
builder.append(" \"s3:ListBucket\"\n");
|
||||
builder.append(" ],\n");
|
||||
builder.append(" \"Effect\": \"Deny\",\n");
|
||||
builder.append(" \"Principal\": \"*\",\n");
|
||||
builder.append(" \"Resource\": \"arn:aws:s3:::");
|
||||
builder.append(bucketName);
|
||||
builder.append("\"\n");
|
||||
builder.append(" },\n");
|
||||
}
|
||||
builder.append(" {\n");
|
||||
builder.append(" \"Action\": ");
|
||||
switch (policyType) {
|
||||
case WRITE:
|
||||
builder.append("[\n");
|
||||
builder.append(" \"s3:AbortMultipartUpload\",\n");
|
||||
builder.append(" \"s3:DeleteObject\",\n");
|
||||
builder.append(" \"s3:ListMultipartUploadParts\",\n");
|
||||
builder.append(" \"s3:PutObject\"\n");
|
||||
builder.append(" ],\n");
|
||||
break;
|
||||
case READ_WRITE:
|
||||
builder.append("[\n");
|
||||
builder.append(" \"s3:AbortMultipartUpload\",\n");
|
||||
builder.append(" \"s3:DeleteObject\",\n");
|
||||
builder.append(" \"s3:GetObject\",\n");
|
||||
builder.append(" \"s3:ListMultipartUploadParts\",\n");
|
||||
builder.append(" \"s3:PutObject\"\n");
|
||||
builder.append(" ],\n");
|
||||
break;
|
||||
default:
|
||||
builder.append("\"s3:GetObject\",\n");
|
||||
break;
|
||||
}
|
||||
builder.append(" \"Effect\": \"Allow\",\n");
|
||||
builder.append(" \"Principal\": \"*\",\n");
|
||||
builder.append(" \"Resource\": \"arn:aws:s3:::");
|
||||
builder.append(bucketName);
|
||||
builder.append("/*\"\n");
|
||||
builder.append(" }\n");
|
||||
builder.append(" ],\n");
|
||||
builder.append(" \"Version\": \"2012-10-17\"\n");
|
||||
builder.append("}\n");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package com.ruoyi.oss.service.impl;
|
||||
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.http.HttpProtocol;
|
||||
import com.qcloud.cos.model.*;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.oss.constant.OssConstant;
|
||||
import com.ruoyi.oss.entity.UploadResult;
|
||||
import com.ruoyi.oss.enumd.OssEnumd;
|
||||
import com.ruoyi.oss.exception.OssException;
|
||||
import com.ruoyi.oss.properties.OssProperties;
|
||||
import com.ruoyi.oss.service.abstractd.AbstractOssStrategy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 腾讯云存储策略
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Component
|
||||
public class QcloudOssStrategy extends AbstractOssStrategy {
|
||||
|
||||
private COSClient client;
|
||||
|
||||
@Override
|
||||
public void init(OssProperties ossProperties) {
|
||||
super.init(ossProperties);
|
||||
try {
|
||||
COSCredentials credentials = new BasicCOSCredentials(
|
||||
properties.getAccessKey(), properties.getSecretKey());
|
||||
// 初始化客户端配置
|
||||
ClientConfig clientConfig = new ClientConfig();
|
||||
// 设置bucket所在的区域,华南:gz 华北:tj 华东:sh
|
||||
clientConfig.setRegion(new Region(properties.getRegion()));
|
||||
if (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) {
|
||||
clientConfig.setHttpProtocol(HttpProtocol.https);
|
||||
} else {
|
||||
clientConfig.setHttpProtocol(HttpProtocol.http);
|
||||
}
|
||||
client = new COSClient(credentials, clientConfig);
|
||||
createBucket();
|
||||
} catch (Exception e) {
|
||||
throw new OssException("腾讯云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
|
||||
}
|
||||
isInit = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createBucket() {
|
||||
try {
|
||||
String bucketName = properties.getBucketName();
|
||||
if (client.doesBucketExist(bucketName)) {
|
||||
return;
|
||||
}
|
||||
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
|
||||
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
|
||||
client.createBucket(createBucketRequest);
|
||||
} catch (Exception e) {
|
||||
throw new OssException("创建Bucket失败, 请核对腾讯云配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssEnumd getServiceType() {
|
||||
return OssEnumd.QCLOUD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||
return upload(new ByteArrayInputStream(data), path, contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult upload(InputStream inputStream, String path, String contentType) {
|
||||
try {
|
||||
ObjectMetadata metadata = new ObjectMetadata();
|
||||
metadata.setContentType(contentType);
|
||||
client.putObject(new PutObjectRequest(properties.getBucketName(), path, inputStream, metadata));
|
||||
} catch (Exception e) {
|
||||
throw new OssException("上传文件失败,请检查腾讯云配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
return UploadResult.builder().url(getEndpointLink() + "/" + path).filename(path).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String path) {
|
||||
path = path.replace(getEndpointLink() + "/", "");
|
||||
try {
|
||||
client.deleteObject(new DeleteObjectRequest(properties.getBucketName(), path));
|
||||
} catch (Exception e) {
|
||||
throw new OssException("上传文件失败,请检腾讯云查配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||
return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEndpointLink() {
|
||||
String endpoint = properties.getEndpoint();
|
||||
StringBuilder sb = new StringBuilder(endpoint);
|
||||
if (StringUtils.containsAnyIgnoreCase(endpoint, "http://")) {
|
||||
sb.insert(7, properties.getBucketName() + ".");
|
||||
} else if (StringUtils.containsAnyIgnoreCase(endpoint, "https://")) {
|
||||
sb.insert(8, properties.getBucketName() + ".");
|
||||
} else {
|
||||
throw new OssException("Endpoint配置错误");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
package com.ruoyi.oss.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.Region;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.util.Auth;
|
||||
import com.ruoyi.oss.constant.OssConstant;
|
||||
import com.ruoyi.oss.entity.UploadResult;
|
||||
import com.ruoyi.oss.enumd.OssEnumd;
|
||||
import com.ruoyi.oss.exception.OssException;
|
||||
import com.ruoyi.oss.properties.OssProperties;
|
||||
import com.ruoyi.oss.service.abstractd.AbstractOssStrategy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 七牛云存储策略
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Component
|
||||
public class QiniuOssStrategy extends AbstractOssStrategy {
|
||||
|
||||
private UploadManager uploadManager;
|
||||
private BucketManager bucketManager;
|
||||
private Auth auth;
|
||||
|
||||
|
||||
@Override
|
||||
public void init(OssProperties ossProperties) {
|
||||
super.init(ossProperties);
|
||||
try {
|
||||
Configuration config = new Configuration(getRegion(properties.getRegion()));
|
||||
// https设置
|
||||
config.useHttpsDomains = OssConstant.IS_HTTPS.equals(properties.getIsHttps());
|
||||
uploadManager = new UploadManager(config);
|
||||
auth = Auth.create(properties.getAccessKey(), properties.getSecretKey());
|
||||
bucketManager = new BucketManager(auth, config);
|
||||
createBucket();
|
||||
} catch (Exception e) {
|
||||
throw new OssException("七牛云存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");
|
||||
}
|
||||
isInit = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createBucket() {
|
||||
try {
|
||||
String bucketName = properties.getBucketName();
|
||||
if (ArrayUtil.contains(bucketManager.buckets(), bucketName)) {
|
||||
return;
|
||||
}
|
||||
bucketManager.createBucket(bucketName, properties.getRegion());
|
||||
} catch (Exception e) {
|
||||
throw new OssException("创建Bucket失败, 请核对七牛云配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssEnumd getServiceType() {
|
||||
return OssEnumd.QINIU;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult upload(byte[] data, String path, String contentType) {
|
||||
try {
|
||||
String token = auth.uploadToken(properties.getBucketName());
|
||||
Response res = uploadManager.put(data, path, token, null, contentType, false);
|
||||
if (!res.isOK()) {
|
||||
throw new RuntimeException("上传七牛出错:" + res.error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new OssException("上传文件失败,请核对七牛配置信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
return UploadResult.builder().url(getEndpointLink() + "/" + path).filename(path).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String path) {
|
||||
try {
|
||||
path = path.replace(getEndpointLink() + "/", "");
|
||||
Response res = bucketManager.delete(properties.getBucketName(), path);
|
||||
if (!res.isOK()) {
|
||||
throw new RuntimeException("删除七牛文件出错:" + res.error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new OssException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) {
|
||||
return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEndpointLink() {
|
||||
return properties.getEndpoint();
|
||||
}
|
||||
|
||||
private Region getRegion(String region) {
|
||||
switch (region) {
|
||||
case "z0":
|
||||
return Region.region0();
|
||||
case "z1":
|
||||
return Region.region1();
|
||||
case "z2":
|
||||
return Region.region2();
|
||||
case "na0":
|
||||
return Region.regionNa0();
|
||||
case "as0":
|
||||
return Region.regionAs0();
|
||||
default:
|
||||
return Region.autoRegion();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 对象存储配置对象 sys_oss_config
|
||||
@ -53,6 +52,11 @@ public class SysOssConfig extends BaseEntity {
|
||||
*/
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* 自定义域名
|
||||
*/
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 是否https(0否 1是)
|
||||
*/
|
||||
|
@ -35,8 +35,8 @@ public class SysOssConfigBo extends BaseEntity {
|
||||
/**
|
||||
* 配置key
|
||||
*/
|
||||
@ApiModelProperty(value = "configKey", required = true)
|
||||
@NotBlank(message = "configKey不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@ApiModelProperty(value = "配置key", required = true)
|
||||
@NotBlank(message = "配置key不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Size(min = 2, max = 100, message = "configKey长度必须介于2和20 之间")
|
||||
private String configKey;
|
||||
|
||||
@ -59,8 +59,8 @@ public class SysOssConfigBo extends BaseEntity {
|
||||
/**
|
||||
* 桶名称
|
||||
*/
|
||||
@ApiModelProperty(value = "bucketName", required = true)
|
||||
@NotBlank(message = "bucketName不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@ApiModelProperty(value = "桶名称", required = true)
|
||||
@NotBlank(message = "桶名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Size(min = 2, max = 100, message = "bucketName长度必须介于2和100之间")
|
||||
private String bucketName;
|
||||
|
||||
@ -73,11 +73,17 @@ public class SysOssConfigBo extends BaseEntity {
|
||||
/**
|
||||
* 访问站点
|
||||
*/
|
||||
@ApiModelProperty(value = "endpoint", required = true)
|
||||
@NotBlank(message = "endpoint不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@ApiModelProperty(value = "访问站点", required = true)
|
||||
@NotBlank(message = "访问站点不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Size(min = 2, max = 100, message = "endpoint长度必须介于2和100之间")
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* 自定义域名
|
||||
*/
|
||||
@ApiModelProperty("自定义域名")
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 是否https(Y=是,N=否)
|
||||
*/
|
||||
@ -93,7 +99,7 @@ public class SysOssConfigBo extends BaseEntity {
|
||||
/**
|
||||
* 域
|
||||
*/
|
||||
@ApiModelProperty(value = "region")
|
||||
@ApiModelProperty(value = "域")
|
||||
private String region;
|
||||
|
||||
/**
|
||||
|
@ -62,6 +62,12 @@ public class SysOssConfigVo {
|
||||
@ApiModelProperty("访问站点")
|
||||
private String endpoint;
|
||||
|
||||
/**
|
||||
* 自定义域名
|
||||
*/
|
||||
@ApiModelProperty("自定义域名")
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 是否https(Y=是,N=否)
|
||||
*/
|
||||
|
@ -7,9 +7,9 @@ import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.oss.core.OssClient;
|
||||
import com.ruoyi.oss.entity.UploadResult;
|
||||
import com.ruoyi.oss.factory.OssFactory;
|
||||
import com.ruoyi.oss.service.IOssStrategy;
|
||||
import com.ruoyi.system.domain.SysOss;
|
||||
import com.ruoyi.system.domain.bo.SysOssBo;
|
||||
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||
@ -65,7 +65,7 @@ public class SysOssServiceImpl implements ISysOssService {
|
||||
public SysOss upload(MultipartFile file) {
|
||||
String originalfileName = file.getOriginalFilename();
|
||||
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
||||
IOssStrategy storage = OssFactory.instance();
|
||||
OssClient storage = OssFactory.instance();
|
||||
UploadResult uploadResult;
|
||||
try {
|
||||
uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
|
||||
@ -78,7 +78,7 @@ public class SysOssServiceImpl implements ISysOssService {
|
||||
oss.setFileSuffix(suffix);
|
||||
oss.setFileName(uploadResult.getFilename());
|
||||
oss.setOriginalName(originalfileName);
|
||||
oss.setService(storage.getServiceType().getValue());
|
||||
oss.setService(storage.getConfigKey());
|
||||
baseMapper.insert(oss);
|
||||
return oss;
|
||||
}
|
||||
@ -90,7 +90,7 @@ public class SysOssServiceImpl implements ISysOssService {
|
||||
}
|
||||
List<SysOss> list = baseMapper.selectBatchIds(ids);
|
||||
for (SysOss sysOss : list) {
|
||||
IOssStrategy storage = OssFactory.instance(sysOss.getService());
|
||||
OssClient storage = OssFactory.instance(sysOss.getService());
|
||||
storage.delete(sysOss.getUrl());
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
|
@ -2,14 +2,13 @@
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item label="配置key" prop="configKey">
|
||||
<el-select v-model="queryParams.configKey" placeholder="请选择配置key" clearable size="small">
|
||||
<el-option
|
||||
v-for="configKey in configKeyOptions"
|
||||
:key="configKey.configKey"
|
||||
:label="configKey.label"
|
||||
:value="configKey.configKey"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input
|
||||
v-model="queryParams.configKey"
|
||||
placeholder="配置key"
|
||||
clearable
|
||||
size="small"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="桶名称" prop="bucketName">
|
||||
<el-input
|
||||
@ -77,6 +76,7 @@
|
||||
<el-table-column label="主建" align="center" prop="ossConfigId" v-if="false"/>
|
||||
<el-table-column label="配置key" align="center" prop="configKey" />
|
||||
<el-table-column label="访问站点" align="center" prop="endpoint" width="200" />
|
||||
<el-table-column label="自定义域名" align="center" prop="domain" width="200" />
|
||||
<el-table-column label="桶名称" align="center" prop="bucketName" />
|
||||
<el-table-column label="前缀" align="center" prop="prefix" />
|
||||
<el-table-column label="域" align="center" prop="region" />
|
||||
@ -122,18 +122,14 @@
|
||||
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
|
||||
<el-form-item label="配置key" prop="configKey">
|
||||
<el-select v-model="form.configKey" placeholder="请选择配置key">
|
||||
<el-option
|
||||
v-for="configKey in configKeyOptions"
|
||||
:key="configKey.configKey"
|
||||
:label="configKey.label"
|
||||
:value="configKey.configKey"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input v-model="form.configKey" placeholder="请输入配置key" />
|
||||
</el-form-item>
|
||||
<el-form-item label="访问站点" prop="endpoint">
|
||||
<el-input v-model="form.endpoint" placeholder="请输入访问站点" />
|
||||
</el-form-item>
|
||||
<el-form-item label="自定义域名" prop="domain">
|
||||
<el-input v-model="form.domain" placeholder="请输入自定义域名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="accessKey" prop="accessKey">
|
||||
<el-input v-model="form.accessKey" placeholder="请输入accessKey" />
|
||||
</el-form-item>
|
||||
@ -204,14 +200,6 @@ export default {
|
||||
total: 0,
|
||||
// 对象存储配置表格数据
|
||||
ossConfigList: [],
|
||||
// configKeyOptions
|
||||
configKeyOptions: [],
|
||||
configKeyDatas: [
|
||||
{ configKey: "minio", label: "Minio" },
|
||||
{ configKey: "qiniu", label: "七牛云" },
|
||||
{ configKey: "aliyun", label: "阿里云" },
|
||||
{ configKey: "qcloud", label: "腾讯云" },
|
||||
],
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 是否显示弹出层
|
||||
@ -276,7 +264,6 @@ export default {
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
this.configKeyOptions = this.configKeyDatas;
|
||||
},
|
||||
methods: {
|
||||
/** 查询对象存储配置列表 */
|
||||
@ -303,6 +290,7 @@ export default {
|
||||
bucketName: undefined,
|
||||
prefix: undefined,
|
||||
endpoint: undefined,
|
||||
domain: undefined,
|
||||
isHttps: "N",
|
||||
region: undefined,
|
||||
status: "1",
|
||||
|
@ -904,6 +904,7 @@ create table sys_oss_config (
|
||||
bucket_name varchar(255) default '',
|
||||
prefix varchar(255) default '',
|
||||
endpoint varchar(255) default '',
|
||||
domain varchar(255) default '',
|
||||
is_https char(1) default 'N',
|
||||
region varchar(255) default '',
|
||||
status char(1) default '1',
|
||||
@ -925,6 +926,7 @@ comment on column sys_oss_config.secret_key is '秘钥';
|
||||
comment on column sys_oss_config.bucket_name is '桶名称';
|
||||
comment on column sys_oss_config.prefix is '前缀';
|
||||
comment on column sys_oss_config.endpoint is '访问站点';
|
||||
comment on column sys_oss_config.domain is '自定义域名';
|
||||
comment on column sys_oss_config.is_https is '是否https(Y=是,N=否)';
|
||||
comment on column sys_oss_config.region is '域';
|
||||
comment on column sys_oss_config.status is '状态(0=正常,1=停用)';
|
||||
@ -935,10 +937,12 @@ comment on column sys_oss_config.create_time is '创建时间';
|
||||
comment on column sys_oss_config.update_by is '更新者';
|
||||
comment on column sys_oss_config.update_time is '更新时间';
|
||||
|
||||
insert into sys_oss_config values (1, 'minio', 'ruoyi', 'ruoyi123', 'ruoyi', '', 'http://localhost:9000', 'N', '', '0', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
insert into sys_oss_config values (2, 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://XXX.XXXX.com', 'N', 'z0', '1', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
insert into sys_oss_config values (3, 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://oss-cn-beijing.aliyuncs.com', 'N', '', '1', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
insert into sys_oss_config values (4, 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'http://cos.ap-beijing.myqcloud.com', 'N', 'ap-beijing', '1', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
insert into sys_oss_config values (1, 'minio', 'ruoyi', 'ruoyi123', 'ruoyi', '', 'localhost:9000', '','N', '', '0', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
insert into sys_oss_config values (2, 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 's3-cn-north-1.qiniucs.com', '','N', '', '1', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
insert into sys_oss_config values (3, 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'oss-cn-beijing.aliyuncs.com', '','N', '', '1', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
insert into sys_oss_config values (4, 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'cos.ap-beijing.myqcloud.com', '','N', 'ap-beijing', '1', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
insert into sys_oss_config values (5, 'image', 'ruoyi', 'ruoyi123', 'ruoyi', 'image', 'localhost:9000', '','N', '', '1', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- 钩子 ,用于session连接之后 自动设置默认的date类型格式化 简化时间查询
|
||||
|
@ -917,6 +917,7 @@ create table if not exists sys_oss_config
|
||||
bucket_name varchar(255) default ''::varchar,
|
||||
prefix varchar(255) default ''::varchar,
|
||||
endpoint varchar(255) default ''::varchar,
|
||||
domain varchar(255) default ''::varchar,
|
||||
is_https char default 'N'::bpchar,
|
||||
region varchar(255) default ''::varchar,
|
||||
status char default '1'::bpchar,
|
||||
@ -937,6 +938,7 @@ comment on column sys_oss_config.secret_key is '秘钥';
|
||||
comment on column sys_oss_config.bucket_name is '桶名称';
|
||||
comment on column sys_oss_config.prefix is '前缀';
|
||||
comment on column sys_oss_config.endpoint is '访问站点';
|
||||
comment on column sys_oss_config.domain is '自定义域名';
|
||||
comment on column sys_oss_config.is_https is '是否https(Y=是,N=否)';
|
||||
comment on column sys_oss_config.region is '域';
|
||||
comment on column sys_oss_config.status is '状态(0=正常,1=停用)';
|
||||
@ -947,7 +949,9 @@ comment on column sys_oss_config.update_by is '更新者';
|
||||
comment on column sys_oss_config.update_time is '更新时间';
|
||||
comment on column sys_oss_config.remark is '备注';
|
||||
|
||||
insert into sys_oss_config values (1, 'minio', 'ruoyi', 'ruoyi123', 'ruoyi', '', 'http://localhost:9000', 'N', '', '0', '', 'admin', now(), 'admin', now(), null);
|
||||
insert into sys_oss_config values (2, 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://XXX.XXXX.com', 'N', 'z0', '1', '', 'admin', now(), 'admin', now(), null);
|
||||
insert into sys_oss_config values (3, 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://oss-cn-beijing.aliyuncs.com', 'N', '', '1', '', 'admin', now(), 'admin', now(), null);
|
||||
insert into sys_oss_config values (4, 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'http://cos.ap-beijing.myqcloud.com', 'N', 'ap-beijing', '1', '', 'admin', now(), 'admin', now(), null);
|
||||
insert into sys_oss_config values (1, 'minio', 'ruoyi', 'ruoyi123', 'ruoyi', '', 'localhost:9000', '','N', '', '0', '', 'admin', now(), 'admin', now(), null);
|
||||
insert into sys_oss_config values (2, 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 's3-cn-north-1.qiniucs.com', '','N', '', '1', '', 'admin', now(), 'admin', now(), null);
|
||||
insert into sys_oss_config values (3, 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'oss-cn-beijing.aliyuncs.com', '','N', '', '1', '', 'admin', now(), 'admin', now(), null);
|
||||
insert into sys_oss_config values (4, 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'cos.ap-beijing.myqcloud.com', '','N', 'ap-beijing', '1', '', 'admin', now(), 'admin', now(), null);
|
||||
insert into sys_oss_config values (5, 'image', 'ruoyi', 'ruoyi123', 'ruoyi', 'image', 'localhost:9000', '','N', '', '1', '', 'admin', now(), 'admin', now(), NULL);
|
||||
|
||||
|
@ -668,6 +668,7 @@ create table sys_oss_config (
|
||||
bucket_name varchar(255) default '' comment '桶名称',
|
||||
prefix varchar(255) default '' comment '前缀',
|
||||
endpoint varchar(255) default '' comment '访问站点',
|
||||
domain varchar(255) default '' comment '自定义域名',
|
||||
is_https char(1) default 'N' comment '是否https(Y=是,N=否)',
|
||||
region varchar(255) default '' comment '域',
|
||||
status char(1) default '1' comment '状态(0=正常,1=停用)',
|
||||
@ -680,7 +681,9 @@ create table sys_oss_config (
|
||||
primary key (oss_config_id)
|
||||
) engine=innodb comment='对象存储配置表';
|
||||
|
||||
insert into sys_oss_config values (1, 'minio', 'ruoyi', 'ruoyi123', 'ruoyi', '', 'http://localhost:9000', 'N', '', '0', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
insert into sys_oss_config values (2, 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://XXX.XXXX.com', 'N', 'z0', '1', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
insert into sys_oss_config values (3, 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'http://oss-cn-beijing.aliyuncs.com', 'N', '', '1', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
insert into sys_oss_config values (4, 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'http://cos.ap-beijing.myqcloud.com', 'N', 'ap-beijing', '1', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
insert into sys_oss_config values (1, 'minio', 'ruoyi', 'ruoyi123', 'ruoyi', '', 'localhost:9000', '','N', '', '0', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
insert into sys_oss_config values (2, 'qiniu', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 's3-cn-north-1.qiniucs.com', '','N', '', '1', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
insert into sys_oss_config values (3, 'aliyun', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi', '', 'oss-cn-beijing.aliyuncs.com', '','N', '', '1', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
insert into sys_oss_config values (4, 'qcloud', 'XXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXX', 'ruoyi-1250000000', '', 'cos.ap-beijing.myqcloud.com', '','N', 'ap-beijing', '1', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
insert into sys_oss_config values (5, 'image', 'ruoyi', 'ruoyi123', 'ruoyi', 'image', 'localhost:9000', '','N', '', '1', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
|
||||
|
@ -2193,6 +2193,7 @@ CREATE TABLE [sys_oss_config]
|
||||
[bucket_name] nvarchar(255) DEFAULT '' NULL,
|
||||
[prefix] nvarchar(255) DEFAULT '' NULL,
|
||||
[endpoint] nvarchar(255) DEFAULT '' NULL,
|
||||
[domain] nvarchar(255) DEFAULT '' NULL,
|
||||
[is_https] nchar(1) DEFAULT ('N') NULL,
|
||||
[region] nvarchar(255) DEFAULT '' NULL,
|
||||
[status] nchar(1) DEFAULT ('1') NULL,
|
||||
@ -2251,6 +2252,12 @@ EXEC sp_addextendedproperty
|
||||
'TABLE', N'sys_oss_config',
|
||||
'COLUMN', N'endpoint'
|
||||
GO
|
||||
EXEC sp_addextendedproperty
|
||||
'MS_Description', N'自定义域名',
|
||||
'SCHEMA', N'dbo',
|
||||
'TABLE', N'sys_oss_config',
|
||||
'COLUMN', N'domain'
|
||||
GO
|
||||
EXEC sp_addextendedproperty
|
||||
'MS_Description', N'是否https(Y=是,N=否)',
|
||||
'SCHEMA', N'dbo',
|
||||
@ -2311,11 +2318,13 @@ EXEC sp_addextendedproperty
|
||||
'TABLE', N'sys_oss_config'
|
||||
GO
|
||||
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'1', N'minio', N'lihongbo', N'lihongbo.123', N'ruoyi', N'', N'http://81.70.150.73:9000', N'N', N'', N'0', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [domain], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'1', N'minio', N'ruoyi', N'ruoyi123', N'ruoyi', N'', N'localhost:9000', N'',N'N', N'', N'0', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
GO
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'2', N'qiniu', N'XXXXXXXXXXXXXXXX', N'XXXXXXXXXXXXXXX', N'ruoyi', N'', N'http://XXX.XXXX.com', N'N', N'z0', N'1', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [domain], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'2', N'qiniu', N'XXXXXXXXXXXXXXXX', N'XXXXXXXXXXXXXXX', N'ruoyi', N'', N's3-cn-north-1.qiniucs.com', N'',N'N', N'', N'1', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
GO
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'3', N'aliyun', N'XXXXXXXXXXXXXXX', N'XXXXXXXXXXXXXXX', N'ruoyi', N'', N'http://oss-cn-beijing.aliyuncs.com', N'N', N'', N'1', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [domain], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'3', N'aliyun', N'XXXXXXXXXXXXXXX', N'XXXXXXXXXXXXXXX', N'ruoyi', N'', N'oss-cn-beijing.aliyuncs.com', N'',N'N', N'', N'1', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
GO
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'4', N'qcloud', N'XXXXXXXXXXXXXXX', N'XXXXXXXXXXXXXXX', N'ruoyi-1250000000', N'', N'http://cos.ap-beijing.myqcloud.com', N'N', N'ap-beijing', N'1', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [domain], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'4', N'qcloud', N'XXXXXXXXXXXXXXX', N'XXXXXXXXXXXXXXX', N'ruoyi-1250000000', N'', N'cos.ap-beijing.myqcloud.com', N'',N'N', N'ap-beijing', N'1', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
GO
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [domain], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'4', N'image', N'ruoyi', N'ruoyi123', N'ruoyi', N'image', N'localhost:9000', N'',N'N', N'', N'1', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
GO
|
||||
|
10
script/sql/update/oracle/update-4.1-4.2.sql
Normal file
10
script/sql/update/oracle/update-4.1-4.2.sql
Normal file
@ -0,0 +1,10 @@
|
||||
ALTER TABLE "SYS_OSS_CONFIG" ADD ("DOMAIN" VARCHAR2(255));
|
||||
|
||||
COMMENT ON COLUMN "SYS_OSS_CONFIG"."DOMAIN" IS '自定义域名';
|
||||
|
||||
update sys_oss_config set endpoint = 'localhost:9000' where oss_config_id = 1;
|
||||
update sys_oss_config set endpoint = 's3-cn-north-1.qiniucs.com', region = '' where oss_config_id = 2;
|
||||
update sys_oss_config set endpoint = 'oss-cn-beijing.aliyuncs.com' where oss_config_id = 3;
|
||||
update sys_oss_config set endpoint = 'cos.ap-beijing.myqcloud.com' where oss_config_id = 4;
|
||||
|
||||
insert into sys_oss_config values (5, 'image', 'ruoyi', 'ruoyi123', 'ruoyi', 'image', 'localhost:9000', '','N', '', '1', '', NULL, 'admin', sysdate, 'admin', sysdate);
|
11
script/sql/update/postgres/update-4.1-4.2.sql
Normal file
11
script/sql/update/postgres/update-4.1-4.2.sql
Normal file
@ -0,0 +1,11 @@
|
||||
ALTER TABLE "sys_oss_config" ADD COLUMN "domain" varchar(255);
|
||||
|
||||
COMMENT ON COLUMN "sys_oss_config"."domain" IS '自定义域名';
|
||||
|
||||
update sys_oss_config set endpoint = 'localhost:9000' where oss_config_id = 1;
|
||||
update sys_oss_config set endpoint = 's3-cn-north-1.qiniucs.com', region = '' where oss_config_id = 2;
|
||||
update sys_oss_config set endpoint = 'oss-cn-beijing.aliyuncs.com' where oss_config_id = 3;
|
||||
update sys_oss_config set endpoint = 'cos.ap-beijing.myqcloud.com' where oss_config_id = 4;
|
||||
|
||||
insert into sys_oss_config values (5, 'image', 'ruoyi', 'ruoyi123', 'ruoyi', 'image', 'localhost:9000', '','N', '', '1', '', 'admin', now(), 'admin', now(), NULL);
|
||||
|
24
script/sql/update/sqlserver/update-4.1-4.2.sql
Normal file
24
script/sql/update/sqlserver/update-4.1-4.2.sql
Normal file
@ -0,0 +1,24 @@
|
||||
ALTER TABLE [sys_oss_config] ADD [domain] nvarchar(255) DEFAULT '' NULL
|
||||
GO
|
||||
|
||||
EXEC sp_addextendedproperty
|
||||
'MS_Description', N'自定义域名',
|
||||
'SCHEMA', N'dbo',
|
||||
'TABLE', N'sys_oss_config',
|
||||
'COLUMN', N'domain'
|
||||
GO
|
||||
|
||||
UPDATE [sys_oss_config] SET [access_key] = N'ruoyi', [secret_key] = N'ruoyi123', [endpoint] = N'localhost:9000' WHERE [oss_config_id] = 1
|
||||
GO
|
||||
|
||||
UPDATE [sys_oss_config] SET [endpoint] = N's3-cn-north-1.qiniucs.com' WHERE [oss_config_id] = 2
|
||||
GO
|
||||
|
||||
UPDATE [sys_oss_config] SET [endpoint] = N'oss-cn-beijing.aliyuncs.com' WHERE [oss_config_id] = 3
|
||||
GO
|
||||
|
||||
UPDATE [sys_oss_config] SET [endpoint] = N'cos.ap-beijing.myqcloud.com' WHERE [oss_config_id] = 4
|
||||
GO
|
||||
|
||||
INSERT INTO [sys_oss_config] ([oss_config_id], [config_key], [access_key], [secret_key], [bucket_name], [prefix], [endpoint], [domain], [is_https], [region], [status], [ext1], [create_by], [create_time], [update_by], [update_time], [remark]) VALUES (N'4', N'image', N'ruoyi', N'ruoyi123', N'ruoyi', N'image', N'localhost:9000', N'',N'N', N'', N'1', N'', N'admin', getdate(), N'admin', getdate(), NULL)
|
||||
GO
|
9
script/sql/update/update-4.1-4.2.sql
Normal file
9
script/sql/update/update-4.1-4.2.sql
Normal file
@ -0,0 +1,9 @@
|
||||
alter table sys_oss_config add column domain varchar(255) null default '' COMMENT '自定义域名';
|
||||
|
||||
update sys_oss_config set endpoint = 'localhost:9000' where oss_config_id = 1;
|
||||
update sys_oss_config set endpoint = 's3-cn-north-1.qiniucs.com', region = '' where oss_config_id = 2;
|
||||
update sys_oss_config set endpoint = 'oss-cn-beijing.aliyuncs.com' where oss_config_id = 3;
|
||||
update sys_oss_config set endpoint = 'cos.ap-beijing.myqcloud.com' where oss_config_id = 4;
|
||||
|
||||
insert into sys_oss_config values (5, 'image', 'ruoyi', 'ruoyi123', 'ruoyi', 'image', 'localhost:9000', '','N', '', '1', '', 'admin', sysdate(), 'admin', sysdate(), NULL);
|
||||
|
Loading…
x
Reference in New Issue
Block a user