优化存储相关逻辑实现

pull/80/head
awenes 2024-02-04 20:36:58 +08:00
parent c17ad46301
commit 9da70a8aeb
9 changed files with 50 additions and 39 deletions

View File

@ -15,7 +15,7 @@
* 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.util;
package cn.topiam.employee.common.enums;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;

View File

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

View File

@ -55,7 +55,7 @@ import jakarta.servlet.MultipartConfigElement;
@RequestMapping(value = StorageConstants.STORAGE_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
@AllArgsConstructor
@Slf4j
public class StorageFileResource {
public class StorageFileEndpoint {
/**
*

View File

@ -26,7 +26,7 @@ import cn.topiam.employee.common.storage.impl.*;
import cn.topiam.employee.support.web.converter.EnumConvert;
/**
*
*
*
* @author TopIAM
* Created by support@topiam.cn on 2020/8/19

View File

@ -25,7 +25,7 @@ import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
/**
* SmsPlatformWritingConverter
* StorageProviderConverter
*
* @author TopIAM
* Created by support@topiam.cn on 2020/12/5 21:52

View File

@ -31,11 +31,12 @@ import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpHeaders;
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.storage.AbstractStorage;
import cn.topiam.employee.common.storage.StorageConfig;
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.EqualsAndHashCode;
@ -100,8 +101,8 @@ public class MinIoStorage extends AbstractStorage {
+ SEPARATOR
+ URLEncoder.encode(key, StandardCharsets.UTF_8).replaceAll("\\+", "%20");
} catch (Exception e) {
log.error("minio upload exception: {}", e.getMessage(), e);
throw new StorageProviderException("minio upload exception", e);
log.error("Minio upload exception: {}", e.getMessage(), e);
throw new UploadException(e);
}
}

View File

@ -21,7 +21,7 @@ import java.io.InputStream;
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;
/**
@ -30,10 +30,9 @@ import cn.topiam.employee.common.storage.StorageProviderException;
* @author TopIAM
* Created by support@topiam.cn on 2021/11/10 21:32
*/
public class NoneStorage extends AbstractStorage {
public class NoneStorage implements Storage {
public NoneStorage() {
super(null);
}
@Override

View File

@ -59,35 +59,10 @@ public class QiNiuKodoStorage extends AbstractStorage {
public QiNiuKodoStorage(StorageConfig config) {
super(config);
qiNiuConfig = (Config) this.config.getConfig();
Configuration cfg = new Configuration(Region.huadong());
Configuration cfg = new Configuration(Region.createWithRegionId("z0"));
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
public String upload(@NotNull String fileName,
InputStream inputStream) throws StorageProviderException {

View File

@ -49,10 +49,8 @@ import software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequ
import static cn.topiam.employee.common.constant.StorageConstants.URL_REGEXP;
/**
* S3
*
* @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
public class S3Storage extends AbstractStorage {