mirror of https://gitee.com/topiam/eiam
⚡ 优化存储相关逻辑实现
parent
c17ad46301
commit
9da70a8aeb
|
@ -15,7 +15,7 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package cn.topiam.employee.common.util;
|
package cn.topiam.employee.common.enums;
|
||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* eiam-common - Employee Identity and Access Management
|
||||||
|
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package cn.topiam.employee.common.storage;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储服务异常
|
||||||
|
*
|
||||||
|
* @author TopIAM
|
||||||
|
* Created by support@topiam.cn on 2020/8/19 22:53
|
||||||
|
*/
|
||||||
|
public class UploadException extends StorageProviderException {
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 6249098979022610064L;
|
||||||
|
|
||||||
|
public UploadException(Throwable cause) {
|
||||||
|
super(cause, "Upload fail", cause.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -55,7 +55,7 @@ import jakarta.servlet.MultipartConfigElement;
|
||||||
@RequestMapping(value = StorageConstants.STORAGE_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = StorageConstants.STORAGE_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class StorageFileResource {
|
public class StorageFileEndpoint {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
|
@ -26,7 +26,7 @@ import cn.topiam.employee.common.storage.impl.*;
|
||||||
import cn.topiam.employee.support.web.converter.EnumConvert;
|
import cn.topiam.employee.support.web.converter.EnumConvert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信平台
|
* 存储提供商
|
||||||
*
|
*
|
||||||
* @author TopIAM
|
* @author TopIAM
|
||||||
* Created by support@topiam.cn on 2020/8/19
|
* Created by support@topiam.cn on 2020/8/19
|
||||||
|
|
|
@ -25,7 +25,7 @@ import jakarta.persistence.AttributeConverter;
|
||||||
import jakarta.persistence.Converter;
|
import jakarta.persistence.Converter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmsPlatformWritingConverter
|
* StorageProviderConverter
|
||||||
*
|
*
|
||||||
* @author TopIAM
|
* @author TopIAM
|
||||||
* Created by support@topiam.cn on 2020/12/5 21:52
|
* Created by support@topiam.cn on 2020/12/5 21:52
|
||||||
|
|
|
@ -31,11 +31,12 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
|
||||||
|
import cn.topiam.employee.common.enums.ViewContentType;
|
||||||
import cn.topiam.employee.common.jackjson.encrypt.JsonPropertyEncrypt;
|
import cn.topiam.employee.common.jackjson.encrypt.JsonPropertyEncrypt;
|
||||||
import cn.topiam.employee.common.storage.AbstractStorage;
|
import cn.topiam.employee.common.storage.AbstractStorage;
|
||||||
import cn.topiam.employee.common.storage.StorageConfig;
|
import cn.topiam.employee.common.storage.StorageConfig;
|
||||||
import cn.topiam.employee.common.storage.StorageProviderException;
|
import cn.topiam.employee.common.storage.StorageProviderException;
|
||||||
import cn.topiam.employee.common.util.ViewContentType;
|
import cn.topiam.employee.common.storage.UploadException;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
@ -100,8 +101,8 @@ public class MinIoStorage extends AbstractStorage {
|
||||||
+ SEPARATOR
|
+ SEPARATOR
|
||||||
+ URLEncoder.encode(key, StandardCharsets.UTF_8).replaceAll("\\+", "%20");
|
+ URLEncoder.encode(key, StandardCharsets.UTF_8).replaceAll("\\+", "%20");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("minio upload exception: {}", e.getMessage(), e);
|
log.error("Minio upload exception: {}", e.getMessage(), e);
|
||||||
throw new StorageProviderException("minio upload exception", e);
|
throw new UploadException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import cn.topiam.employee.common.storage.AbstractStorage;
|
import cn.topiam.employee.common.storage.Storage;
|
||||||
import cn.topiam.employee.common.storage.StorageProviderException;
|
import cn.topiam.employee.common.storage.StorageProviderException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,10 +30,9 @@ import cn.topiam.employee.common.storage.StorageProviderException;
|
||||||
* @author TopIAM
|
* @author TopIAM
|
||||||
* Created by support@topiam.cn on 2021/11/10 21:32
|
* Created by support@topiam.cn on 2021/11/10 21:32
|
||||||
*/
|
*/
|
||||||
public class NoneStorage extends AbstractStorage {
|
public class NoneStorage implements Storage {
|
||||||
|
|
||||||
public NoneStorage() {
|
public NoneStorage() {
|
||||||
super(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -59,35 +59,10 @@ public class QiNiuKodoStorage extends AbstractStorage {
|
||||||
public QiNiuKodoStorage(StorageConfig config) {
|
public QiNiuKodoStorage(StorageConfig config) {
|
||||||
super(config);
|
super(config);
|
||||||
qiNiuConfig = (Config) this.config.getConfig();
|
qiNiuConfig = (Config) this.config.getConfig();
|
||||||
Configuration cfg = new Configuration(Region.huadong());
|
Configuration cfg = new Configuration(Region.createWithRegionId("z0"));
|
||||||
uploadManager = new UploadManager(cfg);
|
uploadManager = new UploadManager(cfg);
|
||||||
// try {
|
|
||||||
// createBucket(cfg);
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error("create bucket error: {}", e.getMessage(), e);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void createBucket(Configuration cfg) {
|
|
||||||
// try {
|
|
||||||
// Auth auth = Auth.create(qiNiuConfig.getAccessKey(), qiNiuConfig.getSecretKey());
|
|
||||||
// BucketManager bucketManager = new BucketManager(auth, cfg);
|
|
||||||
// Response response = bucketManager.createBucket(qiNiuConfig.getBucket(), "z0");
|
|
||||||
// //解析创建成功的结果
|
|
||||||
// BucketInfo putRet = JSON.parseObject(response.bodyString(), BucketInfo.class);
|
|
||||||
// log.info("qi niu create bucket response: {}", putRet);
|
|
||||||
// } catch (QiniuException ex) {
|
|
||||||
// Response r = ex.response;
|
|
||||||
// log.error("qi niu create bucket fail response: {}", r.toString());
|
|
||||||
// try {
|
|
||||||
// log.error("qi niu create bucket fail response body: {}", r.bodyString());
|
|
||||||
// } catch (QiniuException ex2) {
|
|
||||||
// //ignore
|
|
||||||
// }
|
|
||||||
// throw new StorageProviderException("qiu niu create bucket exception", ex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String upload(@NotNull String fileName,
|
public String upload(@NotNull String fileName,
|
||||||
InputStream inputStream) throws StorageProviderException {
|
InputStream inputStream) throws StorageProviderException {
|
||||||
|
|
|
@ -49,10 +49,8 @@ import software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequ
|
||||||
import static cn.topiam.employee.common.constant.StorageConstants.URL_REGEXP;
|
import static cn.topiam.employee.common.constant.StorageConstants.URL_REGEXP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* S3 协议实现
|
|
||||||
*
|
|
||||||
* @author TopIAM
|
* @author TopIAM
|
||||||
* Created by support@topiam.cn on 2023/08/29 22:30
|
* Created by support@topiam.cn on 2021/11/10 21:36
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class S3Storage extends AbstractStorage {
|
public class S3Storage extends AbstractStorage {
|
||||||
|
|
Loading…
Reference in New Issue