Skip to content

Commit

Permalink
Merge pull request #44 from 1171736840/dev
Browse files Browse the repository at this point in the history
Release 0.7.0
  • Loading branch information
1171736840 authored Nov 14, 2022
2 parents 9e40d39 + 94ddf54 commit a3f1608
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

### 简介
在 SpringBoot 中通过简单的方式将文件存储到
本地、FTP、SFTP、WebDAV、阿里云OSS、华为云OBS、七牛云Kodo、腾讯云COS、百度云 BOS、又拍云USS、MinIO、
本地、FTP、SFTP、WebDAV、谷歌云存储、阿里云OSS、华为云OBS、七牛云Kodo、腾讯云COS、百度云 BOS、又拍云USS、MinIO、
AWS S3、金山云 KS3、美团云 MSS、京东云 OSS、天翼云 OOS、移动云 EOS、沃云 OSS、
网易数帆 NOS、Ucloud US3、青云 QingStor、平安云 OBS、首云 OSS、IBM COS、其它兼容 S3 协议的平台

查看 [所有支持的存储平台](https://spring-file-storage.xuyanwu.cn/#/存储平台)

后续即将支持 谷歌云存储、Samba、NFS
后续即将支持 Samba、NFS

> 通过 WebDAV 连接到 Alist 后,可以使用百度网盘、天翼云盘、阿里云盘、迅雷网盘等常见存储服务,[查看 Alist 支持的存储平台](https://alist-doc.nn.ci/docs/webdav)
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

# 简介
在 SpringBoot 中通过简单的方式将文件存储到
本地、FTP、SFTP、WebDAV、阿里云OSS、华为云OBS、七牛云Kodo、腾讯云COS、百度云 BOS、又拍云USS、MinIO、
本地、FTP、SFTP、WebDAV、谷歌云存储、阿里云OSS、华为云OBS、七牛云Kodo、腾讯云COS、百度云 BOS、又拍云USS、MinIO、
AWS S3、金山云 KS3、美团云 MSS、京东云 OSS、天翼云 OOS、移动云 EOS、沃云 OSS、
网易数帆 NOS、Ucloud US3、青云 QingStor、平安云 OBS、首云 OSS、IBM COS、其它兼容 S3 协议的平台

查看 [所有支持的存储平台](存储平台)

后续即将支持 谷歌云存储、Samba、NFS
后续即将支持 Samba、NFS

> 通过 WebDAV 连接到 Alist 后,可以使用百度网盘、天翼云盘、阿里云盘、迅雷网盘等常见存储服务,[查看 Alist 支持的存储平台](https://alist-doc.nn.ci/docs/webdav)
Expand Down
3 changes: 2 additions & 1 deletion docs/_navbar.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* 文档版本 0.6.1
* 文档版本 0.7.0

* [0.7.0](https://spring-file-storage.xuyanwu.cn/0.7.0/)
* [0.6.1](https://spring-file-storage.xuyanwu.cn/0.6.1/)
* [0.6.0](https://spring-file-storage.xuyanwu.cn/0.6.0/)
* [0.5.0](https://spring-file-storage.xuyanwu.cn/0.5.0/)
Expand Down
9 changes: 9 additions & 0 deletions docs/存储平台.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
| 平安云 OBS | × || [查看](https://yun.pingan.com/ssr/help/storage/obs/OBS_SDK_.Java_SDK_) |
| 首云 OSS | × || [查看](http://www.capitalonline.net.cn/zh-cn/service/distribution/oss-new/#product-adv) |
| IBM COS | × || [查看](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-compatibility-api) |
| 谷歌云存储 || × | - |
| 其它兼容 S3 协议的平台 | × || - |

如果想通 AWS S3 SDK 使用对应的存储平台,直接将配置写在 ASW S3 中。
Expand Down Expand Up @@ -197,3 +198,11 @@ FileStorage myLocal = fileStorageService.getFileStorage("my-local-1");
list.remove(myLocal);
myLocal.close();//释放资源
```

## 获取对应存储平台

```java
AliyunOssFileStorage storage = (AliyunOssFileStorage) fileStorageService.getFileStorage("aliyun-oss-1");
OSS client = storage.getClient();
//获取到对应SDK的原生客户端对象,可以进行更多高级操作
```
22 changes: 22 additions & 0 deletions docs/快速入门.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@
<version>5.10</version>
</dependency>

<!-- 谷歌云 Google Cloud Storage-->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.14.0</version>
</dependency>

<!--因 guava 存在较多冲突版本导致谷歌云存储无法使用,故引入独立版本-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>

</dependencies>
```

Expand Down Expand Up @@ -223,6 +237,14 @@ spring:
domain: ?? # 访问域名,注意“/”结尾,例如:https://file.abc.com/
base-path: webdav/ # 基础路径
storage-path: / # 存储路径,可以配合 Nginx 实现访问,注意“/”结尾,默认“/”
google-cloud: # 谷歌云存储
- platform: google-1 # 存储平台标识
enable-storage: true # 启用存储
project-id: ?? # 项目 id
bucket-name: ??
credentials-path: file:/deploy/example-key.json # 授权 key json 路径,兼容Spring的ClassPath路径、文件路径、HTTP路径等
domain: ?? # 访问域名,注意“/”结尾,例如:https://storage.googleapis.com/test-bucket/
base-path: hy/ # 基础路径
```
注意配置每个平台前面都有个`-`号,通过以下方式可以配置多个
Expand Down
6 changes: 6 additions & 0 deletions docs/更新记录.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新记录

## 0.7.0
2022-11-14
- 增加对 谷歌云存储 的支持,由 [kytrun](https://github.com/1171736840/spring-file-storage/pull/42) 提供,非常感谢
- 修复 WebDAV 提示有误
- 使用 Tika 识别 ContentType

## 0.6.1
2022-09-05
- 优化 ContentType 的识别方式
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cn.xuyanwu</groupId>
<artifactId>spring-file-storage-parent</artifactId>
<packaging>pom</packaging>
<version>0.6.1</version>
<version>0.7.0</version>

<name>spring-file-storage-parent</name>
<description>A File Storage Service</description>
Expand Down
18 changes: 16 additions & 2 deletions spring-file-storage-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>cn.xuyanwu</groupId>
<artifactId>spring-file-storage-test</artifactId>
<version>0.6.1</version>
<version>0.7.0</version>
<name>spring-file-storage-test</name>
<description>spring-file-storage 的测试和演示模块</description>

Expand Down Expand Up @@ -106,6 +106,20 @@
<version>3.22.3.1</version>
</dependency>

<!-- 谷歌云 Google Cloud Platform Storage-->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.14.0</version>
</dependency>

<!--因存在较多冲突版本导致谷歌云无法使用,故引入独立版本-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>

<!--糊涂工具类核心-->
<dependency>
<groupId>cn.hutool</groupId>
Expand All @@ -116,7 +130,7 @@
<dependency>
<groupId>cn.xuyanwu</groupId>
<artifactId>spring-file-storage</artifactId>
<version>0.6.1</version>
<version>0.7.0</version>
</dependency>

<dependency>
Expand Down
8 changes: 8 additions & 0 deletions spring-file-storage-test/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@ spring:
domain: ?? # 访问域名,注意“/”结尾,例如:https://file.abc.com/
base-path: webdav/ # 基础路径
storage-path: / # 存储路径,上传的文件都会存储在这个路径下面,默认“/”,注意“/”结尾
google-cloud: # 谷歌云存储
- platform: google-1 # 存储平台标识
enable-storage: true # 启用存储
project-id: ?? # 项目 id
bucket-name: ??
credentials-path: file:/deploy/example-key.json # 授权 key json 路径,兼容Spring的ClassPath路径、文件路径、HTTP路径等
domain: ?? # 访问域名,注意“/”结尾,例如:https://storage.googleapis.com/test-bucket/
base-path: hy/ # 基础路径
18 changes: 17 additions & 1 deletion spring-file-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
<parent>
<artifactId>spring-file-storage-parent</artifactId>
<groupId>cn.xuyanwu</groupId>
<version>0.6.1</version>
<version>0.7.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-file-storage</artifactId>

<dependencies>

<!-- Tika -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.4.1</version>
</dependency>

<!-- WebDAV -->
<dependency>
<groupId>com.github.lookfirst</groupId>
Expand Down Expand Up @@ -127,6 +134,15 @@
<optional>true</optional>
</dependency>

<!-- 谷歌云 Google Cloud Platform Storage-->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.14.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<!--糊涂工具类核心-->
<dependency>
<groupId>cn.hutool</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import cn.xuyanwu.spring.file.storage.platform.*;
import cn.xuyanwu.spring.file.storage.recorder.DefaultFileRecorder;
import cn.xuyanwu.spring.file.storage.recorder.FileRecorder;
import cn.xuyanwu.spring.file.storage.tika.DefaultTikaFactory;
import cn.xuyanwu.spring.file.storage.tika.TikaFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down Expand Up @@ -324,6 +326,23 @@ public List<WebDavFileStorage> webDavFileStorageList() {
}).filter(Objects::nonNull).collect(Collectors.toList());
}

@Bean
@ConditionalOnClass(name = "com.google.cloud.storage.Storage")
public List<GoogleCloudStorage> googleCloudStorageList() {
return properties.getGoogleCloud().stream().map(googleCloud -> {
if (!googleCloud.getEnableStorage()) return null;
log.info("加载存储平台:{}", googleCloud.getPlatform());
GoogleCloudStorage storage = new GoogleCloudStorage();
storage.setPlatform(googleCloud.getPlatform());
storage.setProjectId(googleCloud.getProjectId());
storage.setBucketName(googleCloud.getBucketName());
storage.setCredentialsPath(googleCloud.getCredentialsPath());
storage.setDomain(googleCloud.getDomain());
storage.setBasePath(googleCloud.getBasePath());
return storage;
}).filter(Objects::nonNull).collect(Collectors.toList());
}

/**
* 当没有找到 FileRecorder 时使用默认的 FileRecorder
*/
Expand All @@ -334,20 +353,31 @@ public FileRecorder fileRecorder() {
return new DefaultFileRecorder();
}

/**
* Tika 工厂类型,用于识别上传的文件的 MINE
*/
@Bean
@ConditionalOnMissingBean(TikaFactory.class)
public TikaFactory tikaFactory() {
return new DefaultTikaFactory();
}

/**
* 文件存储服务
*/
@Bean
public FileStorageService fileStorageService(FileRecorder fileRecorder,
List<List<? extends FileStorage>> fileStorageLists,
List<FileStorageAspect> aspectList) {
List<FileStorageAspect> aspectList,
TikaFactory tikaFactory) {
this.initDetect();
FileStorageService service = new FileStorageService();
service.setFileStorageList(new CopyOnWriteArrayList<>());
fileStorageLists.forEach(service.getFileStorageList()::addAll);
service.setFileRecorder(fileRecorder);
service.setProperties(properties);
service.setAspectList(new CopyOnWriteArrayList<>(aspectList));
service.setTikaFactory(tikaFactory);
return service;
}

Expand Down Expand Up @@ -392,9 +422,12 @@ public void initDetect() {
if (CollUtil.isNotEmpty(properties.getFtp()) && (doesNotExistClass("com.jcraft.jsch.ChannelSftp") || doesNotExistClass("cn.hutool.extra.ftp.Ftp"))) {
log.warn(template," SFTP ");
}
if (CollUtil.isNotEmpty(properties.getAwsS3()) && doesNotExistClass("com.github.sardine.Sardine")) {
if (CollUtil.isNotEmpty(properties.getWebDav()) && doesNotExistClass("com.github.sardine.Sardine")) {
log.warn(template," WebDAV ");
}
if (CollUtil.isNotEmpty(properties.getGoogleCloud()) && doesNotExistClass("com.google.cloud.storage.Storage")) {
log.warn(template, " 谷歌云存储 ");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public class FileStorageProperties {
*/
private List<WebDAV> WebDav = new ArrayList<>();

/**
* 谷歌云存储
*/
private List<GoogleCloud> googleCloud = new ArrayList<>();

/**
* 本地存储
*/
Expand Down Expand Up @@ -523,4 +528,30 @@ public static class WebDAV {
*/
private String storagePath = "/";
}

@Data
public static class GoogleCloud {
private String projectId;
/**
* 证书路径,兼容Spring的ClassPath路径、文件路径、HTTP路径等
*/
private String credentialsPath;
private String bucketName;
/**
* 访问域名
*/
private String domain = "";
/**
* 启用存储
*/
private Boolean enableStorage = false;
/**
* 存储平台
*/
private String platform = "";
/**
* 基础路径
*/
private String basePath = "";
}
}
Loading

0 comments on commit a3f1608

Please sign in to comment.