Skip to content

Commit

Permalink
Merge pull request #38 from besscroft/dev
Browse files Browse the repository at this point in the history
feat:qCloud COS support
  • Loading branch information
besscroft authored Aug 13, 2023
2 parents 5f039b7 + c381a73 commit 397ce02
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum StorageTypeEnum implements BasicEnum<Integer> {
LOCAL(0, "本地"),
ONE_DRIVE(1, "OneDrive"),
ALIYUN_OSS(2, "阿里云OSS"),
AMAZON_S3(3, "Amazon S3");
AMAZON_S3(3, "Amazon S3"),
QCLOUD_COS(4, "腾讯云COS");

private final int value;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public DiyFileException(String message) {
this.message = message;
}

public DiyFileException(String message, Throwable cause) {
super(message, cause);
this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
this.message = message;
}

public DiyFileException(Integer code, String message) {
this.code = code;
this.message = message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.besscroft.diyfile.common.param.storage.init;

import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @Description 腾讯云 COS 初始化参数
* @Author Bess Croft
* @Date 2023/8/13 17:11
*/
@Data
@Builder
@EqualsAndHashCode(callSuper = true)
public class QCloudCosParam extends OssParam {

/** secretId */
private String secretId;

/** secretKey */
private String secretKey;

/** 地域 */
private String region;

/** endpoint 端点 */
private String endpoint;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import com.besscroft.diyfile.common.entity.StorageConfig;
import com.besscroft.diyfile.common.enums.StorageTypeEnum;
import com.besscroft.diyfile.common.param.FileInitParam;
import com.besscroft.diyfile.common.param.storage.init.AliYunOssParam;
import com.besscroft.diyfile.common.param.storage.init.AmazonS3Param;
import com.besscroft.diyfile.common.param.storage.init.LocalParam;
import com.besscroft.diyfile.common.param.storage.init.OneDriveParam;
import com.besscroft.diyfile.common.param.storage.init.*;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -70,6 +67,16 @@ public static FileInitParam getFileInitParam(Storage storage, List<StorageConfig
param.setMountPath(configMap.get("mount_path"));
param.setBucketName(configMap.get("bucketName"));
return param;
} else if (Objects.equals(storage.getType(), StorageTypeEnum.QCLOUD_COS.getValue())) {
// 腾讯云COS初始化参数
QCloudCosParam param = QCloudCosParam.builder().build();
param.setSecretId(configMap.get("secretId"));
param.setSecretKey(configMap.get("secretKey"));
param.setRegion(configMap.get("region"));
param.setEndpoint(configMap.get("endpoint"));
param.setMountPath(configMap.get("mount_path"));
param.setBucketName(configMap.get("bucketName"));
return param;
}
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions diyfile-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
<!-- 腾讯云 COS -->
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ public void updateStatus(Long storageId, Integer status) {
try {
storageApplicationContext.init(storage);
} catch (Exception e) {
log.error("启用存储失败:{}", e.getMessage());
throw new DiyFileException("启用存储失败!");
}
} else {
try {
storageApplicationContext.destroy(storage.getId());
} catch (Exception e) {
log.error("停用存储失败:{}", e.getMessage());
throw new DiyFileException("停用存储失败!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void deleteItem(@NonNull String filePath) {

@Override
public void uploadItem(String folderPath, String fileName) {
// TODO 上传文件
throw new DiyFileException("S3 API 暂不支持上传文件");
}

Expand All @@ -164,6 +165,7 @@ public ResponseEntity<Resource> getFileResource(String fileName, String filePath
@Override
public void moveItem(String startPath, String endPath) {
// TODO 移动文件
throw new DiyFileException("S3 API 暂不支持移动文件");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AliYunOssServiceImpl extends AbstractOSSBaseService<AliYunOssParam>
*/
@Override
public void init() {
// TODO OSSClient 初始化
// OSSClient 初始化
this.ossClient = new OSSClientBuilder()
.build(initParam.getEndpoint(),
initParam.getAccessKeyId(),
Expand Down Expand Up @@ -103,12 +103,12 @@ public FileInfoVo getFileInfo(String filePath, String fileName) {

@Override
public void createItem(String folderPath, String fileName) {
throw new DiyFileException("阿里云 OSS 服务暂不支持创建文件夹");
throw new DiyFileException("阿里云 OSS 服务暂不支持创建对象!");
}

@Override
public void updateItem(String filePath, String fileName) {
throw new DiyFileException("阿里云 OSS 服务暂不支持更新文件");
throw new DiyFileException("阿里云 OSS 服务暂不支持更新对象!");
}

@Override
Expand All @@ -123,6 +123,7 @@ public void deleteItem(String filePath) {

@Override
public void uploadItem(String folderPath, String fileName) {
// TODO 上传文件
throw new DiyFileException("阿里云 OSS 服务暂不支持上传文件");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.net.URLEncodeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.besscroft.diyfile.common.constant.FileConstants;
Expand Down Expand Up @@ -117,6 +116,7 @@ public void deleteItem(String filePath) {

@Override
public void uploadItem(String folderPath, String fileName) {
// TODO 本地文件上传
throw new DiyFileException("本地文件存储不支持上传文件!");
}

Expand Down
Loading

0 comments on commit 397ce02

Please sign in to comment.