ソースを参照

MinIo文件上传

ZeroLiYi 1 年間 前
コミット
4472d0037c
共有26 個のファイルを変更した1580 個の追加0 個の削除を含む
  1. 22 0
      pom.xml
  2. 3 0
      src/main/java/com/chinaitop/DepotSmartStorageQinghaiApplication.java
  3. 93 0
      src/main/java/com/chinaitop/depot/intelligent/file/controller/CommonCacheOperator.java
  4. 63 0
      src/main/java/com/chinaitop/depot/intelligent/file/controller/DevFileController.java
  5. 68 0
      src/main/java/com/chinaitop/depot/intelligent/file/entity/CommonEntity.java
  6. 61 0
      src/main/java/com/chinaitop/depot/intelligent/file/entity/DevConfig.java
  7. 78 0
      src/main/java/com/chinaitop/depot/intelligent/file/entity/DevFile.java
  8. 52 0
      src/main/java/com/chinaitop/depot/intelligent/file/entity/MinIoProperties.java
  9. 38 0
      src/main/java/com/chinaitop/depot/intelligent/file/enums/DevFileBucketAuthEnum.java
  10. 43 0
      src/main/java/com/chinaitop/depot/intelligent/file/enums/DevFileEngineTypeEnum.java
  11. 25 0
      src/main/java/com/chinaitop/depot/intelligent/file/mapper/DevConfigMapper.java
  12. 26 0
      src/main/java/com/chinaitop/depot/intelligent/file/mapper/DevFileMapper.java
  13. 6 0
      src/main/java/com/chinaitop/depot/intelligent/file/mapper/mapping/DevConfigMapper.xml
  14. 6 0
      src/main/java/com/chinaitop/depot/intelligent/file/mapper/mapping/DevFileMapper.xml
  15. 35 0
      src/main/java/com/chinaitop/depot/intelligent/file/param/DevFileIdParam.java
  16. 36 0
      src/main/java/com/chinaitop/depot/intelligent/file/param/DevFileListParam.java
  17. 36 0
      src/main/java/com/chinaitop/depot/intelligent/file/param/DevFilePageParam.java
  18. 39 0
      src/main/java/com/chinaitop/depot/intelligent/file/service/DevConfigService.java
  19. 34 0
      src/main/java/com/chinaitop/depot/intelligent/file/service/DevFileService.java
  20. 36 0
      src/main/java/com/chinaitop/depot/intelligent/file/service/impl/DevConfigApiProvider.java
  21. 64 0
      src/main/java/com/chinaitop/depot/intelligent/file/service/impl/DevConfigServiceImpl.java
  22. 195 0
      src/main/java/com/chinaitop/depot/intelligent/file/service/impl/DevFileServiceImpl.java
  23. 37 0
      src/main/java/com/chinaitop/depot/intelligent/file/util/CommonProperties.java
  24. 259 0
      src/main/java/com/chinaitop/depot/intelligent/file/util/DevFileLocalUtil.java
  25. 219 0
      src/main/java/com/chinaitop/depot/intelligent/file/util/DevFileMinIoUtil.java
  26. 6 0
      src/main/resources/bootstrap-dev.yml

+ 22 - 0
pom.xml

@@ -87,6 +87,28 @@
87 87
             <artifactId>fastjson</artifactId>
88 88
             <version>1.2.37</version>
89 89
         </dependency>
90
+        <!--minio上传文件客户端-->
91
+        <dependency>
92
+            <groupId>io.minio</groupId>
93
+            <artifactId>minio</artifactId>
94
+            <version>8.5.2</version>
95
+            <exclusions>
96
+                <exclusion>
97
+                    <artifactId>okhttp</artifactId>
98
+                    <groupId>com.squareup.okhttp3</groupId>
99
+                </exclusion>
100
+            </exclusions>
101
+        </dependency>
102
+        <dependency>
103
+            <groupId>com.squareup.okhttp3</groupId>
104
+            <artifactId>okhttp</artifactId>
105
+            <version>4.10.0</version>
106
+        </dependency>
107
+        <dependency>
108
+            <groupId>cn.hutool</groupId>
109
+            <artifactId>hutool-all</artifactId>
110
+            <version>5.8.12</version>
111
+        </dependency>
90 112
         <dependency>
91 113
             <groupId>org.springframework.boot</groupId>
92 114
             <artifactId>spring-boot-starter-actuator</artifactId>

+ 3 - 0
src/main/java/com/chinaitop/DepotSmartStorageQinghaiApplication.java

@@ -1,8 +1,10 @@
1 1
 package com.chinaitop;
2 2
 
3
+import com.chinaitop.depot.intelligent.file.entity.MinIoProperties;
3 4
 import org.mybatis.spring.annotation.MapperScan;
4 5
 import org.springframework.boot.SpringApplication;
5 6
 import org.springframework.boot.autoconfigure.SpringBootApplication;
7
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 8
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
7 9
 import org.springframework.context.annotation.Bean;
8 10
 import org.springframework.web.client.RestTemplate;
@@ -12,6 +14,7 @@ import org.springframework.web.client.RestTemplate;
12 14
 @MapperScan({
13 15
         "com.chinaitop.depot.intelligent.*.mapper"
14 16
 })
17
+@EnableConfigurationProperties(MinIoProperties.class)
15 18
 public class DepotSmartStorageQinghaiApplication {
16 19
 
17 20
     public static void main(String[] args) {

+ 93 - 0
src/main/java/com/chinaitop/depot/intelligent/file/controller/CommonCacheOperator.java

@@ -0,0 +1,93 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.controller;
14
+
15
+import cn.hutool.core.collection.CollectionUtil;
16
+import cn.hutool.core.map.MapUtil;
17
+import cn.hutool.core.util.StrUtil;
18
+import org.springframework.data.redis.core.RedisTemplate;
19
+import org.springframework.stereotype.Component;
20
+
21
+import javax.annotation.Resource;
22
+import java.util.*;
23
+import java.util.concurrent.TimeUnit;
24
+import java.util.stream.Collectors;
25
+
26
+/**
27
+ * 通用Redis缓存操作器
28
+ *
29
+ * @author xuyuxiang
30
+ * @date 2022/6/21 16:00
31
+ **/
32
+@Component
33
+public class CommonCacheOperator {
34
+
35
+    /** 所有缓存Key的前缀 */
36
+    private static final String CACHE_KEY_PREFIX = "Cache:";
37
+
38
+    @Resource
39
+    private RedisTemplate<String, Object> redisTemplate;
40
+
41
+    public void put(String key, Object value) {
42
+        redisTemplate.boundValueOps(CACHE_KEY_PREFIX + key).set(value);
43
+    }
44
+
45
+    public void put(String key, Object value, long timeoutSeconds) {
46
+        redisTemplate.boundValueOps(CACHE_KEY_PREFIX + key).set(value, timeoutSeconds, TimeUnit.SECONDS);
47
+    }
48
+
49
+    public Object get(String key) {
50
+        return redisTemplate.boundValueOps(CACHE_KEY_PREFIX + key).get();
51
+    }
52
+
53
+    public void remove(String... key) {
54
+        ArrayList<String> keys = CollectionUtil.toList(key);
55
+        List<String> withPrefixKeys = keys.stream().map(i -> CACHE_KEY_PREFIX + i).collect(Collectors.toList());
56
+        redisTemplate.delete(withPrefixKeys);
57
+    }
58
+
59
+    public Collection<String> getAllKeys() {
60
+        Set<String> keys = redisTemplate.keys(CACHE_KEY_PREFIX + "*");
61
+        if (keys != null) {
62
+            // 去掉缓存key的common prefix前缀
63
+            return keys.stream().map(key -> StrUtil.removePrefix(key, CACHE_KEY_PREFIX)).collect(Collectors.toSet());
64
+        } else {
65
+            return CollectionUtil.newHashSet();
66
+        }
67
+    }
68
+
69
+    public Collection<Object> getAllValues() {
70
+        Set<String> keys = redisTemplate.keys(CACHE_KEY_PREFIX + "*");
71
+        if (keys != null) {
72
+            return redisTemplate.opsForValue().multiGet(keys);
73
+        } else {
74
+            return CollectionUtil.newArrayList();
75
+        }
76
+    }
77
+
78
+    public Map<String, Object> getAllKeyValues() {
79
+        Collection<String> allKeys = this.getAllKeys();
80
+        HashMap<String, Object> results = MapUtil.newHashMap();
81
+        for (String key : allKeys) {
82
+            results.put(key, this.get(key));
83
+        }
84
+        return results;
85
+    }
86
+
87
+    public void removeBatch(String pattern) {
88
+        Set<String> keys = redisTemplate.keys(CACHE_KEY_PREFIX + pattern);
89
+        if (keys != null) {
90
+            redisTemplate.delete(keys);
91
+        }
92
+    }
93
+}

+ 63 - 0
src/main/java/com/chinaitop/depot/intelligent/file/controller/DevFileController.java

@@ -0,0 +1,63 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.controller;
14
+
15
+
16
+
17
+import com.chinaitop.depot.intelligent.file.enums.DevFileEngineTypeEnum;
18
+import com.chinaitop.depot.intelligent.file.service.DevFileService;
19
+import io.swagger.annotations.Api;
20
+import io.swagger.annotations.ApiOperation;
21
+import org.springframework.http.MediaType;
22
+import org.springframework.validation.annotation.Validated;
23
+import org.springframework.web.bind.annotation.*;
24
+import org.springframework.web.multipart.MultipartFile;
25
+
26
+
27
+import javax.annotation.Resource;
28
+
29
+
30
+/**
31
+ * 文件控制器
32
+ *
33
+ * @author xuyuxiang
34
+ * @date 2022/2/23 18:26
35
+ **/
36
+@Api(tags = "文件控制器")
37
+@RestController
38
+@Validated
39
+public class DevFileController<DevConfigApi> {
40
+
41
+    /** 默认文件引擎 */
42
+    private static final String SNOWY_SYS_DEFAULT_FILE_ENGINE_KEY = "SNOWY_SYS_DEFAULT_FILE_ENGINE";
43
+
44
+
45
+    @Resource
46
+    private DevFileService devFileService;
47
+
48
+
49
+    /**
50
+     * MINIO文件上传,返回文件Url
51
+     *
52
+     * @author xuyuxiang
53
+     * @date 2021/10/13 14:01
54
+     **/
55
+    @ApiOperation("上传MINIO文件返回url")
56
+    @PostMapping("/dev/file/uploadMinioReturnUrl")
57
+    public String uploadMinioReturnUrl(@RequestPart("file") MultipartFile file) {
58
+        return devFileService.uploadReturnUrl(DevFileEngineTypeEnum.MINIO.getValue(), file);
59
+    }
60
+
61
+
62
+
63
+}

+ 68 - 0
src/main/java/com/chinaitop/depot/intelligent/file/entity/CommonEntity.java

@@ -0,0 +1,68 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.entity;
14
+
15
+import com.baomidou.mybatisplus.annotation.FieldFill;
16
+import com.baomidou.mybatisplus.annotation.TableField;
17
+import com.baomidou.mybatisplus.annotation.TableLogic;
18
+import com.fasterxml.jackson.annotation.JsonIgnore;
19
+import io.swagger.annotations.ApiModelProperty;
20
+import lombok.Getter;
21
+import lombok.Setter;
22
+
23
+import java.io.Serializable;
24
+import java.util.Date;
25
+
26
+/**
27
+ * <p>
28
+ *     通用基础字段实体:创建时间、创建人、修改时间、修改人,需要此通用字段的实体可继承此类,
29
+ *     继承此类要求数据表有对应的字段
30
+ * </p>
31
+ *
32
+ * @author xuyuxiang
33
+ * @date 2020/3/10 16:02
34
+ */
35
+@Getter
36
+@Setter
37
+public class CommonEntity implements Serializable{
38
+
39
+    /** 删除标志 */
40
+    @JsonIgnore
41
+    @TableLogic
42
+    @ApiModelProperty(value = "删除标志", position = 999)
43
+    @TableField(fill = FieldFill.INSERT)
44
+    private String deleteFlag;
45
+
46
+    /** 创建时间 */
47
+    @ApiModelProperty(value = "创建时间", position = 1000)
48
+    @TableField(fill = FieldFill.INSERT)
49
+    private Date createTime;
50
+
51
+
52
+
53
+    /** 创建人名称 */
54
+    @ApiModelProperty(value = "创建人名称", position = 1002)
55
+    @TableField(exist = false)
56
+    private String createUserName;
57
+
58
+    /** 更新时间 */
59
+    @ApiModelProperty(value = "更新时间", position = 1003)
60
+    @TableField(fill = FieldFill.UPDATE)
61
+    private Date updateTime;
62
+
63
+
64
+    /** 更新人名称 */
65
+    @ApiModelProperty(value = "更新人名称", position = 1005)
66
+    @TableField(exist = false)
67
+    private String updateUserName;
68
+}

+ 61 - 0
src/main/java/com/chinaitop/depot/intelligent/file/entity/DevConfig.java

@@ -0,0 +1,61 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.entity;
14
+
15
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
16
+import com.baomidou.mybatisplus.annotation.TableField;
17
+import com.baomidou.mybatisplus.annotation.TableName;
18
+import io.swagger.annotations.ApiModelProperty;
19
+import lombok.Getter;
20
+import lombok.Setter;
21
+
22
+/**
23
+ * 配置实体
24
+ *
25
+ * @author xuyuxiang
26
+ * @date 2022/2/23 18:27
27
+ **/
28
+@Getter
29
+@Setter
30
+@TableName("DEV_CONFIG")
31
+public class DevConfig extends CommonEntity {
32
+
33
+    /** id */
34
+    @ApiModelProperty(value = "id", position = 1)
35
+    private String id;
36
+
37
+    /** 配置键 */
38
+    @ApiModelProperty(value = "配置键", position = 2)
39
+    private String configKey;
40
+
41
+    /** 配置值 */
42
+    @ApiModelProperty(value = "配置值", position = 3)
43
+    private String configValue;
44
+
45
+    /** 分类 */
46
+    @ApiModelProperty(value = "分类", position = 4)
47
+    private String category;
48
+
49
+    /** 备注 */
50
+    @ApiModelProperty(value = "备注", position = 5)
51
+    private String remark;
52
+
53
+    /** 排序码 */
54
+    @ApiModelProperty(value = "排序码", position = 6)
55
+    private Integer sortCode;
56
+
57
+    /** 扩展信息 */
58
+    @ApiModelProperty(value = "扩展信息", position = 7)
59
+    @TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
60
+    private String extJson;
61
+}

+ 78 - 0
src/main/java/com/chinaitop/depot/intelligent/file/entity/DevFile.java

@@ -0,0 +1,78 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.entity;
14
+
15
+import com.baomidou.mybatisplus.annotation.TableName;
16
+import io.swagger.annotations.ApiModelProperty;
17
+import lombok.Getter;
18
+import lombok.Setter;
19
+
20
+/**
21
+ * 文件实体
22
+ *
23
+ * @author xuyuxiang
24
+ * @date 2022/2/23 18:27
25
+ **/
26
+@Getter
27
+@Setter
28
+@TableName("DEV_FILE")
29
+public class DevFile extends CommonEntity {
30
+
31
+    /** id */
32
+    @ApiModelProperty(value = "id", position = 1)
33
+    private String id;
34
+
35
+    /** 存储引擎 */
36
+    @ApiModelProperty(value = "存储引擎", position = 2)
37
+    private String engine;
38
+
39
+    /** 存储桶 */
40
+    @ApiModelProperty(value = "存储桶", position = 3)
41
+    private String bucket;
42
+
43
+    /** 文件名称 */
44
+    @ApiModelProperty(value = "文件名称", position = 4)
45
+    private String name;
46
+
47
+    /** 文件后缀 */
48
+    @ApiModelProperty(value = "文件后缀", position = 5)
49
+    private String suffix;
50
+
51
+    /** 文件大小kb */
52
+    @ApiModelProperty(value = "文件大小kb", position = 6)
53
+    private String sizeKb;
54
+
55
+    /** 文件大小(格式化后) */
56
+    @ApiModelProperty(value = "文件大小(格式化后)", position = 7)
57
+    private String sizeInfo;
58
+
59
+    /** 文件的对象名(唯一名称) */
60
+    @ApiModelProperty(value = "文件的对象名(唯一名称)", position = 8)
61
+    private String objName;
62
+
63
+    /** 文件存储路径 */
64
+    @ApiModelProperty(value = "文件存储路径", position = 9)
65
+    private String storagePath;
66
+
67
+    /** 文件下载路径 */
68
+    @ApiModelProperty(value = "文件下载路径", position = 10)
69
+    private String downloadPath;
70
+
71
+    /** 图片缩略图 */
72
+    @ApiModelProperty(value = "图片缩略图", position = 11)
73
+    private String thumbnail;
74
+
75
+    /** 扩展信息 */
76
+    @ApiModelProperty(value = "扩展信息", position = 12)
77
+    private String extJson;
78
+}

+ 52 - 0
src/main/java/com/chinaitop/depot/intelligent/file/entity/MinIoProperties.java

@@ -0,0 +1,52 @@
1
+package com.chinaitop.depot.intelligent.file.entity;
2
+
3
+
4
+import io.lettuce.core.ConnectionBuilder;
5
+
6
+import org.springframework.beans.factory.annotation.Value;
7
+import org.springframework.boot.context.properties.ConfigurationProperties;
8
+
9
+
10
+@ConfigurationProperties(prefix = "minio")
11
+public class MinIoProperties {
12
+    @Value("${minio.endpoint}")
13
+    private String endpoint;
14
+    @Value("${minio.access-key}")
15
+    private String accessKey;
16
+    @Value("${minio.secret-key}")
17
+    private String secretKey;
18
+    @Value("${minio.bucket-name}")
19
+    private String bucketName;
20
+
21
+    public String getEndpoint() {
22
+        return endpoint;
23
+    }
24
+
25
+    public void setEndpoint(String endpoint) {
26
+        this.endpoint = endpoint;
27
+    }
28
+
29
+    public String getAccessKey() {
30
+        return accessKey;
31
+    }
32
+
33
+    public void setAccessKey(String accessKey) {
34
+        this.accessKey = accessKey;
35
+    }
36
+
37
+    public String getSecretKey() {
38
+        return secretKey;
39
+    }
40
+
41
+    public void setSecretKey(String secretKey) {
42
+        this.secretKey = secretKey;
43
+    }
44
+
45
+    public String getBucketName() {
46
+        return bucketName;
47
+    }
48
+
49
+    public void setBucketName(String bucketName) {
50
+        this.bucketName = bucketName;
51
+    }
52
+}

+ 38 - 0
src/main/java/com/chinaitop/depot/intelligent/file/enums/DevFileBucketAuthEnum.java

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.enums;
14
+
15
+/**
16
+ * 文件存储桶的权限策略枚举
17
+ *
18
+ * @author xuyuxiang
19
+ * @date 2022/1/5 23:29
20
+ */
21
+public enum DevFileBucketAuthEnum {
22
+
23
+    /**
24
+     * 私有的(仅有 owner 可以读写)
25
+     */
26
+    PRIVATE,
27
+
28
+    /**
29
+     * 公有读,私有写( owner 可以读写, 其他客户可以读)
30
+     */
31
+    PUBLIC_READ,
32
+
33
+    /**
34
+     * 公共读写(即所有人都可以读写,慎用)
35
+     */
36
+    PUBLIC_READ_WRITE
37
+
38
+}

+ 43 - 0
src/main/java/com/chinaitop/depot/intelligent/file/enums/DevFileEngineTypeEnum.java

@@ -0,0 +1,43 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.enums;
14
+
15
+import lombok.Getter;
16
+
17
+/**
18
+ * 文件存储引擎类型枚举
19
+ *
20
+ * @author xuyuxiang
21
+ * @date 2022/6/16 16:14
22
+ **/
23
+@Getter
24
+public enum DevFileEngineTypeEnum {
25
+
26
+    /** 本地 */
27
+    LOCAL("LOCAL"),
28
+
29
+    /** 阿里云 */
30
+    ALIYUN("ALIYUN"),
31
+
32
+    /** 腾讯云 */
33
+    TENCENT("TENCENT"),
34
+
35
+    /** MINIO */
36
+    MINIO("MINIO");
37
+
38
+    private final String value;
39
+
40
+    DevFileEngineTypeEnum(String value) {
41
+        this.value = value;
42
+    }
43
+}

+ 25 - 0
src/main/java/com/chinaitop/depot/intelligent/file/mapper/DevConfigMapper.java

@@ -0,0 +1,25 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.mapper;
14
+
15
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
16
+import com.chinaitop.depot.intelligent.file.entity.DevConfig;
17
+
18
+/**
19
+ * 配置Mapper接口
20
+ *
21
+ * @author xuyuxiang
22
+ * @date 2022/4/22 10:43
23
+ **/
24
+public interface DevConfigMapper extends BaseMapper<DevConfig> {
25
+}

+ 26 - 0
src/main/java/com/chinaitop/depot/intelligent/file/mapper/DevFileMapper.java

@@ -0,0 +1,26 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.mapper;
14
+
15
+
16
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
17
+import com.chinaitop.depot.intelligent.file.entity.DevFile;
18
+
19
+/**
20
+ * 文件Mapper接口
21
+ *
22
+ * @author xuyuxiang
23
+ * @date 2022/2/23 18:40
24
+ **/
25
+public interface DevFileMapper extends BaseMapper<DevFile> {
26
+}

+ 6 - 0
src/main/java/com/chinaitop/depot/intelligent/file/mapper/mapping/DevConfigMapper.xml

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.unis.dev.modular.config.mapper.DevConfigMapper">
4
+
5
+
6
+</mapper>

+ 6 - 0
src/main/java/com/chinaitop/depot/intelligent/file/mapper/mapping/DevFileMapper.xml

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.chinaitop.depot.intelligent.file.mapper.DevFileMapper">
4
+
5
+
6
+</mapper>

+ 35 - 0
src/main/java/com/chinaitop/depot/intelligent/file/param/DevFileIdParam.java

@@ -0,0 +1,35 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.param;
14
+
15
+import io.swagger.annotations.ApiModelProperty;
16
+import lombok.Getter;
17
+import lombok.Setter;
18
+
19
+import javax.validation.constraints.NotBlank;
20
+
21
+/**
22
+ * 文件Id参数
23
+ *
24
+ * @author xuyuxiang
25
+ * @date 2022/7/31 10:24
26
+ */
27
+@Getter
28
+@Setter
29
+public class DevFileIdParam {
30
+
31
+    /** id */
32
+    @ApiModelProperty(value = "id", required = true)
33
+    @NotBlank(message = "id不能为空")
34
+    private String id;
35
+}

+ 36 - 0
src/main/java/com/chinaitop/depot/intelligent/file/param/DevFileListParam.java

@@ -0,0 +1,36 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.param;
14
+
15
+import io.swagger.annotations.ApiModelProperty;
16
+import lombok.Getter;
17
+import lombok.Setter;
18
+
19
+/**
20
+ * 文件列表参数
21
+ *
22
+ * @author xuyuxiang
23
+ * @date 2022/7/31 10:24
24
+ */
25
+@Getter
26
+@Setter
27
+public class DevFileListParam {
28
+
29
+    /** 文件引擎 */
30
+    @ApiModelProperty(value = "文件引擎")
31
+    private String engine;
32
+
33
+    /** 文件名关键词 */
34
+    @ApiModelProperty(value = "文件名关键词")
35
+    private String searchKey;
36
+}

+ 36 - 0
src/main/java/com/chinaitop/depot/intelligent/file/param/DevFilePageParam.java

@@ -0,0 +1,36 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.param;
14
+
15
+import io.swagger.annotations.ApiModelProperty;
16
+import lombok.Getter;
17
+import lombok.Setter;
18
+
19
+/**
20
+ * 文件分页列表参数
21
+ *
22
+ * @author xuyuxiang
23
+ * @date 2022/7/31 10:24
24
+ */
25
+@Getter
26
+@Setter
27
+public class DevFilePageParam {
28
+
29
+    /** 文件引擎 */
30
+    @ApiModelProperty(value = "文件引擎")
31
+    private String engine;
32
+
33
+    /** 文件名关键词 */
34
+    @ApiModelProperty(value = "文件名关键词")
35
+    private String searchKey;
36
+}

+ 39 - 0
src/main/java/com/chinaitop/depot/intelligent/file/service/DevConfigService.java

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.service;
14
+
15
+
16
+
17
+import com.baomidou.mybatisplus.extension.service.IService;
18
+import com.chinaitop.depot.intelligent.file.entity.DevConfig;
19
+
20
+import java.util.List;
21
+
22
+/**
23
+ * 配置Service接口
24
+ *
25
+ * @author xuyuxiang
26
+ * @date 2022/4/22 10:41
27
+ **/
28
+public interface DevConfigService extends IService<DevConfig> {
29
+
30
+    /**
31
+     * 根据键获取值
32
+     *
33
+     * @author xuyuxiang
34
+     * @date 2022/4/22 14:52
35
+     **/
36
+    String getValueByKey(String key);
37
+
38
+
39
+}

+ 34 - 0
src/main/java/com/chinaitop/depot/intelligent/file/service/DevFileService.java

@@ -0,0 +1,34 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.service;
14
+
15
+import org.springframework.web.multipart.MultipartFile;
16
+
17
+
18
+/**
19
+ * 文件Service接口
20
+ *
21
+ * @author xuyuxiang
22
+ * @date 2022/2/23 18:27
23
+ **/
24
+public interface DevFileService {
25
+
26
+    /**
27
+     * MultipartFile文件上传,返回文件Url
28
+     *
29
+     * @author xuyuxiang
30
+     * @date 2022/4/22 15:53
31
+     **/
32
+    String uploadReturnUrl(String engine, MultipartFile file);
33
+
34
+}

+ 36 - 0
src/main/java/com/chinaitop/depot/intelligent/file/service/impl/DevConfigApiProvider.java

@@ -0,0 +1,36 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.service.impl;
14
+
15
+import com.chinaitop.depot.intelligent.file.service.DevConfigService;
16
+import org.springframework.stereotype.Service;
17
+
18
+import javax.annotation.Resource;
19
+
20
+/**
21
+ * 配置API接口实现类
22
+ *
23
+ * @author xuyuxiang
24
+ * @date 2022/6/17 14:43
25
+ **/
26
+@Service
27
+public class DevConfigApiProvider implements DevConfigApi {
28
+
29
+    @Resource
30
+    private DevConfigService devConfigService;
31
+
32
+    @Override
33
+    public String getValueByKey(String key) {
34
+        return devConfigService.getValueByKey(key);
35
+    }
36
+}

+ 64 - 0
src/main/java/com/chinaitop/depot/intelligent/file/service/impl/DevConfigServiceImpl.java

@@ -0,0 +1,64 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.service.impl;
14
+
15
+
16
+import cn.hutool.core.convert.Convert;
17
+import cn.hutool.core.util.ObjectUtil;
18
+import cn.hutool.core.util.StrUtil;
19
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
20
+
21
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
22
+import com.chinaitop.depot.intelligent.file.controller.CommonCacheOperator;
23
+import com.chinaitop.depot.intelligent.file.entity.DevConfig;
24
+import com.chinaitop.depot.intelligent.file.mapper.DevConfigMapper;
25
+import com.chinaitop.depot.intelligent.file.service.DevConfigService;
26
+
27
+import org.springframework.stereotype.Service;
28
+
29
+
30
+import javax.annotation.Resource;
31
+
32
+/**
33
+ * 配置Service接口实现类
34
+ *
35
+ * @author xuyuxiang
36
+ * @date 2022/4/22 10:41
37
+ **/
38
+@Service
39
+public class DevConfigServiceImpl extends ServiceImpl<DevConfigMapper, DevConfig> implements DevConfigService {
40
+
41
+    private static final String CONFIG_CACHE_KEY = "dev-config:";
42
+
43
+    private static final String SNOWY_SYS_DEFAULT_PASSWORD_KEY = "SNOWY_SYS_DEFAULT_PASSWORD";
44
+
45
+    @Resource
46
+    private CommonCacheOperator commonCacheOperator;
47
+
48
+    @Override
49
+    public String getValueByKey(String key) {
50
+        // 从缓存中取
51
+        Object cacheValue = commonCacheOperator.get(CONFIG_CACHE_KEY + key);
52
+        if(ObjectUtil.isNotEmpty(cacheValue)) {
53
+            return Convert.toStr(cacheValue);
54
+        }
55
+        DevConfig devConfig = this.getOne(new LambdaQueryWrapper<DevConfig>().eq(DevConfig::getConfigKey, key));
56
+        if(ObjectUtil.isNotEmpty(devConfig)) {
57
+            // 更新到缓存
58
+            commonCacheOperator.put(CONFIG_CACHE_KEY + key, devConfig.getConfigValue());
59
+            return devConfig.getConfigValue();
60
+        }
61
+        return null;
62
+    }
63
+
64
+}

+ 195 - 0
src/main/java/com/chinaitop/depot/intelligent/file/service/impl/DevFileServiceImpl.java

@@ -0,0 +1,195 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.service.impl;
14
+
15
+import cn.hutool.core.convert.Convert;
16
+import cn.hutool.core.date.DateUtil;
17
+import cn.hutool.core.img.ImgUtil;
18
+import cn.hutool.core.io.FileUtil;
19
+
20
+import cn.hutool.core.util.NumberUtil;
21
+import cn.hutool.core.util.ObjectUtil;
22
+import cn.hutool.core.util.StrUtil;
23
+
24
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
25
+
26
+
27
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
28
+import com.chinaitop.depot.intelligent.file.entity.DevFile;
29
+import com.chinaitop.depot.intelligent.file.enums.DevFileEngineTypeEnum;
30
+import com.chinaitop.depot.intelligent.file.mapper.DevFileMapper;
31
+import com.chinaitop.depot.intelligent.file.service.DevFileService;
32
+
33
+import com.chinaitop.depot.intelligent.file.util.CommonProperties;
34
+import com.chinaitop.depot.intelligent.file.util.DevFileMinIoUtil;
35
+import org.springframework.stereotype.Service;
36
+import org.springframework.web.multipart.MultipartFile;
37
+
38
+
39
+import javax.annotation.Resource;
40
+import java.math.BigDecimal;
41
+
42
+
43
+/**
44
+ * 文件Service接口实现类
45
+ *
46
+ * @author xuyuxiang
47
+ * @date 2022/2/23 18:43
48
+ **/
49
+@Service
50
+public class DevFileServiceImpl extends ServiceImpl<DevFileMapper, DevFile> implements DevFileService {
51
+
52
+    @Resource
53
+    private CommonProperties commonProperties;
54
+
55
+
56
+    @Override
57
+    public String uploadReturnUrl(String engine, MultipartFile file) {
58
+        return this.storageFile(engine, file, false);
59
+    }
60
+
61
+
62
+    /**
63
+     * 存储文件
64
+     *
65
+     * @author xuyuxiang
66
+     * @date 2022/6/16 16:24
67
+     **/
68
+    private String storageFile(String engine, MultipartFile file, boolean returnFileId) {
69
+
70
+        // 如果引擎为空,默认使用本地
71
+        if(ObjectUtil.isEmpty(engine)) {
72
+            engine = DevFileEngineTypeEnum.LOCAL.getValue();
73
+        }
74
+
75
+        // 生成id
76
+        String fileId = IdWorker.getIdStr();
77
+
78
+        // 存储桶名称
79
+        String bucketName = null;
80
+
81
+        // 定义存储的url,本地文件返回文件实际路径,其他引擎返回网络地址
82
+        String storageUrl = null;
83
+
84
+        // 根据引擎类型执行不同方法
85
+       if(engine.equals(DevFileEngineTypeEnum.MINIO.getValue())) {
86
+
87
+            // 使用MINIO默认配置的bucketName
88
+            bucketName = DevFileMinIoUtil.getDefaultBucketName();
89
+            storageUrl = DevFileMinIoUtil.storageFileWithReturnUrl(bucketName, genFileKey(fileId, file), file);
90
+        } else {
91
+            //throw new CommonException("不支持的文件引擎:{}", engine);
92
+        }
93
+
94
+        // 将文件信息保存到数据库
95
+        DevFile devFile = new DevFile();
96
+
97
+        // 设置文件id
98
+        devFile.setId(fileId);
99
+
100
+        // 设置存储引擎类型
101
+        devFile.setEngine(engine);
102
+        devFile.setBucket(bucketName);
103
+        devFile.setName(file.getOriginalFilename());
104
+        String suffix = ObjectUtil.isNotEmpty(file.getOriginalFilename())?StrUtil.subAfter(file.getOriginalFilename(),
105
+                StrUtil.DOT, true):null;
106
+        devFile.setSuffix(suffix);
107
+        devFile.setSizeKb(Convert.toStr(NumberUtil.div(new BigDecimal(file.getSize()), BigDecimal.valueOf(1024))
108
+                .setScale(0, BigDecimal.ROUND_HALF_UP)));
109
+        devFile.setSizeInfo(FileUtil.readableFileSize(file.getSize()));
110
+        devFile.setObjName(ObjectUtil.isNotEmpty(devFile.getSuffix())?fileId + StrUtil.DOT + devFile.getSuffix():null);
111
+        // 如果是图片,则压缩生成缩略图
112
+        if(ObjectUtil.isNotEmpty(suffix)) {
113
+            if(isPic(suffix)) {
114
+                try {
115
+                    devFile.setThumbnail(ImgUtil.toBase64DataUri(ImgUtil.scale(ImgUtil.toImage(file.getBytes()),
116
+                            100, 100, null), suffix));
117
+                } catch (Exception ignored) {
118
+                }
119
+            }
120
+        }
121
+        // 存储路径
122
+        devFile.setStoragePath(storageUrl);
123
+
124
+        // 定义下载地址
125
+        String downloadUrl = null;
126
+
127
+        // 下载路径,注意:本地文件下载地址设置为下载接口地址 + 文件id
128
+        if(engine.equals(DevFileEngineTypeEnum.LOCAL.getValue())) {
129
+            String apiUrl = commonProperties.getBackendUrl();
130
+//            if(ObjectUtil.isEmpty(apiUrl)) {
131
+//                throw new CommonException("后端域名地址未正确配置:snowy.config.common.backend-url为空");
132
+//            }
133
+            downloadUrl= apiUrl + "/dev/file/download?id=" + fileId;
134
+            devFile.setDownloadPath(downloadUrl);
135
+        } else {
136
+            // 阿里云、腾讯云、MINIO可以直接使用存储地址(公网)作为下载地址
137
+            downloadUrl= storageUrl;
138
+            devFile.setDownloadPath(devFile.getStoragePath());
139
+        }
140
+
141
+        this.save(devFile);
142
+
143
+        // 如果是返回id则返回文件id
144
+        if(returnFileId) {
145
+            return fileId;
146
+        } else {
147
+            // 否则返回下载地址
148
+            return downloadUrl;
149
+        }
150
+    }
151
+
152
+
153
+    /**
154
+     * 生成文件的key,格式如 2021/10/11/1377109572375810050.docx
155
+     *
156
+     * @author xuyuxiang
157
+     * @date 2022/4/22 15:58
158
+     **/
159
+    public String genFileKey(String fileId, MultipartFile file) {
160
+
161
+        // 获取文件原始名称
162
+        String originalFileName = file.getOriginalFilename();
163
+
164
+        // 获取文件后缀
165
+        String fileSuffix = FileUtil.getSuffix(originalFileName);
166
+
167
+        // 生成文件的对象名称,格式如:1377109572375810050.docx
168
+        String fileObjectName = fileId + StrUtil.DOT + fileSuffix;
169
+
170
+        // 获取日期文件夹,格式如,2021/10/11/
171
+        String dateFolderPath = DateUtil.thisYear() + StrUtil.SLASH +
172
+                (DateUtil.thisMonth() + 1) + StrUtil.SLASH +
173
+                DateUtil.thisDayOfMonth() + StrUtil.SLASH;
174
+
175
+        // 返回
176
+        return dateFolderPath + fileObjectName;
177
+    }
178
+
179
+
180
+    /**
181
+     * 根据文件后缀判断是否图片
182
+     *
183
+     * @author xuyuxiang
184
+     * @date 2020/7/6 15:31
185
+     */
186
+    private static boolean isPic(String fileSuffix) {
187
+        fileSuffix = fileSuffix.toLowerCase();
188
+        return ImgUtil.IMAGE_TYPE_GIF.equals(fileSuffix)
189
+                || ImgUtil.IMAGE_TYPE_JPG.equals(fileSuffix)
190
+                || ImgUtil.IMAGE_TYPE_JPEG.equals(fileSuffix)
191
+                || ImgUtil.IMAGE_TYPE_BMP.equals(fileSuffix)
192
+                || ImgUtil.IMAGE_TYPE_PNG.equals(fileSuffix)
193
+                || ImgUtil.IMAGE_TYPE_PSD.equals(fileSuffix);
194
+    }
195
+}

+ 37 - 0
src/main/java/com/chinaitop/depot/intelligent/file/util/CommonProperties.java

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.util;
14
+
15
+import lombok.Getter;
16
+import lombok.Setter;
17
+import org.springframework.boot.context.properties.ConfigurationProperties;
18
+import org.springframework.stereotype.Component;
19
+
20
+/**
21
+ * 通用基础配置
22
+ *
23
+ * @author xuyuxiang
24
+ * @date 2022/1/2 17:03
25
+ */
26
+@Getter
27
+@Setter
28
+@Component
29
+@ConfigurationProperties(prefix = "snowy.config.common")
30
+public class CommonProperties {
31
+
32
+    /** 前端地址 */
33
+    private String frontUrl;
34
+
35
+    /** 后端地址 */
36
+    private String backendUrl;
37
+}

+ 259 - 0
src/main/java/com/chinaitop/depot/intelligent/file/util/DevFileLocalUtil.java

@@ -0,0 +1,259 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.util;
14
+
15
+import cn.hutool.core.io.FileUtil;
16
+import cn.hutool.extra.spring.SpringUtil;
17
+import cn.hutool.json.JSONObject;
18
+import cn.hutool.json.JSONUtil;
19
+import cn.hutool.system.SystemUtil;
20
+
21
+import lombok.extern.slf4j.Slf4j;
22
+
23
+
24
+
25
+import java.io.File;
26
+import java.io.InputStream;
27
+
28
+/**
29
+ * 本地文件工具类
30
+ *
31
+ * @author xuyuxiang
32
+ * @date 2022/1/2 18:13
33
+ */
34
+@Slf4j
35
+public class DevFileLocalUtil {
36
+
37
+    private static JSONObject client;
38
+
39
+    private static final String SNOWY_FILE_LOCAL_FOLDER_FOR_WINDOWS_KEY = "SNOWY_FILE_LOCAL_FOLDER_FOR_WINDOWS";
40
+    private static final String SNOWY_FILE_LOCAL_FOLDER_FOR_UNIX_KEY = "SNOWY_FILE_LOCAL_FOLDER_FOR_UNIX";
41
+
42
+    /**
43
+     * 初始化操作的客户端
44
+     *
45
+     * @author xuyuxiang
46
+     * @date 2022/1/5 23:24
47
+     */
48
+    private static void initClient() {
49
+
50
+        String uploadFileFolder;
51
+
52
+        DevConfigApi devConfigApi = SpringUtil.getBean(DevConfigApi.class);
53
+
54
+        if(SystemUtil.getOsInfo().isWindows()) {
55
+
56
+            /* 本地文件上传的位置 windows系统 */
57
+            String localFolderForWindows = devConfigApi.getValueByKey(SNOWY_FILE_LOCAL_FOLDER_FOR_WINDOWS_KEY);
58
+
59
+//            if(ObjectUtil.isEmpty(localFolderForWindows)) {
60
+//                throw new CommonException("本地文件操作客户端未正确配置:SNOWY_FILE_LOCAL_FOLDER_FOR_WINDOWS为空");
61
+//            }
62
+            uploadFileFolder = localFolderForWindows;
63
+        } else {
64
+
65
+            /* 本地文件上传的位置 unix系列系统(linux、mac等) */
66
+            String localFolderForUnix = devConfigApi.getValueByKey(SNOWY_FILE_LOCAL_FOLDER_FOR_UNIX_KEY);
67
+
68
+//            if(ObjectUtil.isEmpty(localFolderForUnix)) {
69
+//                throw new CommonException("本地文件操作客户端未正确配置:SNOWY_FILE_LOCAL_FOLDER_FOR_UNIX为空");
70
+//            }
71
+            uploadFileFolder = localFolderForUnix;
72
+        }
73
+        if(!FileUtil.exist(uploadFileFolder)) {
74
+            FileUtil.mkdir(uploadFileFolder);
75
+        }
76
+        client = JSONUtil.createObj();
77
+        client.set("localFileUploadFolder", uploadFileFolder);
78
+    }
79
+
80
+    /**
81
+     * 销毁操作的客户端
82
+     *
83
+     * @author xuyuxiang
84
+     * @date 2022/1/5 23:24
85
+     */
86
+    public static void destroyClient() {
87
+        client.clear();
88
+    }
89
+
90
+    /**
91
+     * 获取操作的客户端
92
+     *
93
+     * @author xuyuxiang
94
+     * @date 2022/1/5 23:24
95
+     */
96
+    public static JSONObject getClient() {
97
+        return client;
98
+    }
99
+
100
+    /**
101
+     * 获取上传地址
102
+     *
103
+     * @author xuyuxiang
104
+     * @date 2022/1/5 23:24
105
+     */
106
+    public static String getUploadFileFolder() {
107
+        return client.getStr("localFileUploadFolder");
108
+    }
109
+
110
+    /**
111
+     * 查询存储桶是否存在
112
+     * 例如:传入参数examplebucket-1250000000,返回true代表存在此桶
113
+     *
114
+     * @param bucketName 桶名称
115
+     * @author xuyuxiang
116
+     * @date 2022/1/5 23:24
117
+     */
118
+    public static boolean doesBucketExist(String bucketName) {
119
+        initClient();
120
+        return FileUtil.exist(getUploadFileFolder() + FileUtil.FILE_SEPARATOR + bucketName);
121
+    }
122
+
123
+
124
+
125
+
126
+
127
+    /**
128
+     * 存储文件,不返回地址
129
+     *
130
+     * @param bucketName 桶名称
131
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
132
+     * @param bytes      文件字节数组
133
+     * @author xuyuxiang
134
+     * @date 2022/1/5 23:24
135
+     */
136
+    public static void storageFile(String bucketName, String key, byte[] bytes) {
137
+        initClient();
138
+        FileUtil.writeBytes(bytes, getUploadFileFolder() + FileUtil.FILE_SEPARATOR + bucketName + FileUtil.FILE_SEPARATOR + key);
139
+    }
140
+
141
+    /**
142
+     * 存储文件,不返回地址
143
+     *
144
+     * @param bucketName  桶名称
145
+     * @param key         唯一标示id,例如a.txt, doc/a.txt
146
+     * @param inputStream 文件流
147
+     * @author xuyuxiang
148
+     * @date 2022/1/5 23:24
149
+     */
150
+    public static void storageFile(String bucketName, String key, InputStream inputStream) {
151
+        initClient();
152
+        FileUtil.writeFromStream(inputStream, getUploadFileFolder() + FileUtil.FILE_SEPARATOR + bucketName + FileUtil.FILE_SEPARATOR + key);
153
+    }
154
+
155
+
156
+
157
+
158
+
159
+    /**
160
+     * 存储文件,返回存储的地址
161
+     *
162
+     * @param bucketName 桶名称
163
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
164
+     * @param bytes      文件字节数组
165
+     * @author xuyuxiang
166
+     * @date 2022/1/5 23:24
167
+     */
168
+    public static String storageFileWithReturnUrl(String bucketName, String key, byte[] bytes) {
169
+        storageFile(bucketName, key, bytes);
170
+        return getFileAuthUrl(bucketName, key);
171
+    }
172
+
173
+    /**
174
+     * 存储文件,返回存储的地址
175
+     *
176
+     * @param bucketName  桶名称
177
+     * @param key         唯一标示id,例如a.txt, doc/a.txt
178
+     * @param inputStream 文件流
179
+     * @author xuyuxiang
180
+     * @date 2022/1/5 23:24
181
+     */
182
+    public static String storageFileWithReturnUrl(String bucketName, String key, InputStream inputStream) {
183
+        storageFile(bucketName, key, inputStream);
184
+        return getFileAuthUrl(bucketName, key);
185
+    }
186
+
187
+    /**
188
+     * 获取某个bucket下的文件字节
189
+     *
190
+     * @param bucketName 桶名称
191
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
192
+     * @author xuyuxiang
193
+     * @date 2022/1/5 23:24
194
+     */
195
+    public static byte[] getFileBytes(String bucketName, String key) {
196
+        File file = getFileByBucketNameAndKey(bucketName, key);
197
+        return FileUtil.readBytes(file);
198
+    }
199
+
200
+
201
+    /**
202
+     * 拷贝文件
203
+     *
204
+     * @param originBucketName 源文件桶
205
+     * @param originFileKey    源文件名称
206
+     * @param newBucketName    新文件桶
207
+     * @param newFileKey       新文件名称
208
+     * @author xuyuxiang
209
+     * @date 2022/1/5 23:24
210
+     */
211
+    public static void copyFile(String originBucketName, String originFileKey, String newBucketName, String newFileKey) {
212
+        initClient();
213
+        File file = getFileByBucketNameAndKey(originBucketName, originFileKey);
214
+        File newFile = FileUtil.file(getUploadFileFolder() + FileUtil.FILE_SEPARATOR + newBucketName + FileUtil.FILE_SEPARATOR + newFileKey);
215
+        FileUtil.copy(file, newFile, true);
216
+    }
217
+
218
+    /**
219
+     * 获取文件的实际存储地址
220
+     *
221
+     * @param bucketName 文件桶
222
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
223
+     * @author xuyuxiang
224
+     * @date 2022/1/5 23:24
225
+     */
226
+    public static String getFileAuthUrl(String bucketName, String key) {
227
+        initClient();
228
+        File file = getFileByBucketNameAndKey(bucketName, key);
229
+        return file.getAbsolutePath();
230
+    }
231
+
232
+    /**
233
+     * 删除文件
234
+     *
235
+     * @param bucketName 文件桶
236
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
237
+     * @author xuyuxiang
238
+     * @date 2022/1/5 23:24
239
+     */
240
+    public static void deleteFile(String bucketName, String key) {
241
+        File file = getFileByBucketNameAndKey(bucketName, key);
242
+        FileUtil.del(file);
243
+    }
244
+
245
+    /**
246
+     * 根据桶名称和文件key获取文件
247
+     *
248
+     * @param bucketName 文件桶
249
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
250
+     * @author xuyuxiang
251
+     * @date 2022/1/5 23:24
252
+     */
253
+    public static File getFileByBucketNameAndKey(String bucketName, String key) {
254
+        initClient();
255
+        String path = getUploadFileFolder() + FileUtil.FILE_SEPARATOR + bucketName + FileUtil.FILE_SEPARATOR + key;
256
+        File file = FileUtil.file(path);
257
+        return file;
258
+    }
259
+}

+ 219 - 0
src/main/java/com/chinaitop/depot/intelligent/file/util/DevFileMinIoUtil.java

@@ -0,0 +1,219 @@
1
+/*
2
+ * Copyright [2022] [https://www.xiaonuo.vip]
3
+ *
4
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
5
+ *
6
+ * 1.请不要删除和修改根目录下的LICENSE文件。
7
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
8
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
9
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
10
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
11
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
12
+ */
13
+package com.chinaitop.depot.intelligent.file.util;
14
+
15
+import cn.hutool.core.io.IoUtil;
16
+import cn.hutool.core.util.StrUtil;
17
+import cn.hutool.extra.spring.SpringUtil;
18
+import cn.hutool.json.JSONArray;
19
+import cn.hutool.json.JSONObject;
20
+import cn.hutool.json.JSONUtil;
21
+import com.chinaitop.depot.intelligent.file.entity.MinIoProperties;
22
+import com.chinaitop.depot.intelligent.file.enums.DevFileBucketAuthEnum;
23
+import io.minio.*;
24
+import lombok.extern.slf4j.Slf4j;
25
+import org.springframework.beans.factory.annotation.Autowired;
26
+import org.springframework.stereotype.Component;
27
+import org.springframework.web.multipart.MultipartFile;
28
+
29
+import javax.activation.MimetypesFileTypeMap;
30
+import java.io.IOException;
31
+import java.io.InputStream;
32
+
33
+/**
34
+ * MINIO文件工具类
35
+ * 参考文档:http://docs.minio.org.cn/docs/master/java-client-quickstart-guide
36
+ *
37
+ * @author xuyuxiang
38
+ * @date 2022/1/2 18:13
39
+ */
40
+@Slf4j
41
+@Component
42
+public class DevFileMinIoUtil {
43
+
44
+
45
+    private static MinioClient client;
46
+
47
+    private static String defaultBucketName;
48
+
49
+    private static final String SNOWY_FILE_MINIO_ACCESS_KEY_KEY = "SNOWY_FILE_MINIO_ACCESS_KEY";
50
+    private static final String SNOWY_FILE_MINIO_SECRET_KEY_KEY = "SNOWY_FILE_MINIO_SECRET_KEY";
51
+    private static final String SNOWY_FILE_MINIO_END_POINT_KEY = "SNOWY_FILE_MINIO_END_POINT";
52
+    /**
53
+     * 文件访问前缀
54
+     *
55
+     * @author: ybw
56
+     * @date: 2024/5/31
57
+     **/
58
+    private static final String SNOWY_FILE_MINIO_ACCESS_PREFIX = "SNOWY_FILE_MINIO_ACCESS_PREFIX";
59
+    private static final String SNOWY_FILE_MINIO_DEFAULT_BUCKET_NAME = "SNOWY_FILE_MINIO_DEFAULT_BUCKET_NAME";
60
+    private static MinIoProperties minIoProperties;
61
+    @Autowired
62
+    public DevFileMinIoUtil(MinIoProperties minIoProperties) {
63
+        this.minIoProperties = minIoProperties;
64
+    }
65
+
66
+    /**
67
+     * 初始化操作的客户端
68
+     *
69
+     * @author xuyuxiang
70
+     * @date 2022/1/5 23:24
71
+     */
72
+    private static void initClient() {
73
+
74
+
75
+        /* 默认BucketName */
76
+       String defaultBucketName = minIoProperties.getBucketName();
77
+       String endpoint=minIoProperties.getEndpoint();
78
+       String accessKey= minIoProperties.getAccessKey();
79
+        String secretKey =minIoProperties.getSecretKey();
80
+        client = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
81
+
82
+    }
83
+
84
+    /**
85
+     * 获取默认存储桶名称
86
+     *
87
+     * @author xuyuxiang
88
+     * @date 2022/6/22 18:05
89
+     **/
90
+    public static  String getDefaultBucketName() {
91
+        initClient();
92
+
93
+        return minIoProperties.getBucketName();
94
+
95
+    }
96
+
97
+
98
+    /**
99
+     * 存储文件,返回外网地址
100
+     *
101
+     * @param bucketName 桶名称
102
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
103
+     * @param multipartFile      文件
104
+     * @author xuyuxiang
105
+     * @date 2022/1/5 23:45
106
+     */
107
+    public static String storageFileWithReturnUrl(String bucketName, String key, MultipartFile multipartFile) {
108
+        storageFile(bucketName, key, multipartFile);
109
+        setFileAcl(bucketName, key, DevFileBucketAuthEnum.PUBLIC_READ);
110
+        return getFileAuthUrl(bucketName, key);
111
+    }
112
+
113
+
114
+
115
+    /**
116
+     * 获取文件的下载地址(永久的,文件必须为公有读),生成外网地址
117
+     *
118
+     * @param bucketName 文件桶
119
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
120
+     * @author xuyuxiang
121
+     * @date 2022/1/5 23:24
122
+     */
123
+    public static String getFileAuthUrl(String bucketName, String key) {
124
+
125
+            initClient();
126
+            return minIoProperties.getEndpoint() + StrUtil.SLASH + bucketName + StrUtil.SLASH + key;
127
+
128
+    }
129
+    /**
130
+     * 存储文件,不返回地址
131
+     *
132
+     * @param bucketName 桶名称
133
+     * @param key        唯一标示id,例如a.txt, doc/a.txt
134
+     * @param multipartFile      文件
135
+     * @author xuyuxiang
136
+     * @date 2022/1/5 23:45
137
+     */
138
+    public static void storageFile(String bucketName, String key, MultipartFile multipartFile) {
139
+        InputStream inputStream = null;
140
+        try {
141
+            inputStream = multipartFile.getInputStream();
142
+        } catch (IOException e) {
143
+   
144
+        }
145
+        storageFile(bucketName, key, inputStream);
146
+    }
147
+
148
+    /**
149
+     * 设置文件访问权限管理
150
+     *
151
+     * @param bucketName     桶名称
152
+     * @param key             唯一标示id,例如a.txt, doc/a.txt
153
+     * @param devFileBucketAuthEnum 文件权限
154
+     * @author xuyuxiang
155
+     * @date 2022/1/5 23:24
156
+     */
157
+    public static void setFileAcl(String bucketName, String key, DevFileBucketAuthEnum devFileBucketAuthEnum) {
158
+        try {
159
+            JSONObject configObject = JSONUtil.createObj().set("Version", "2012-10-17");
160
+            JSONArray statementArray = JSONUtil.createArray();
161
+            JSONArray actionArray = JSONUtil.createArray();
162
+            if(devFileBucketAuthEnum.equals(DevFileBucketAuthEnum.PUBLIC_READ)) {
163
+                actionArray.put("s3:GetObject");
164
+            }
165
+            if(devFileBucketAuthEnum.equals(DevFileBucketAuthEnum.PUBLIC_READ_WRITE)) {
166
+                actionArray.put("s3:GetObject");
167
+                actionArray.put("s3:PutObject");
168
+            }
169
+            JSONObject statementObject = JSONUtil.createObj();
170
+            statementObject.set("Effect", "Allow").set("Principal", JSONUtil.createObj().set("AWS", JSONUtil.createArray().put("*")))
171
+                    .set("Action", actionArray).set("Resource", JSONUtil.createArray().put("arn:aws:s3:::" + bucketName + "/*"));
172
+            statementArray.put(statementObject);
173
+            configObject.set("Statement", statementArray);
174
+            String config = JSONUtil.toJsonStr(configObject);
175
+            SetBucketPolicyArgs setBucketPolicyArgs = SetBucketPolicyArgs.builder().bucket(bucketName).config(config).build();
176
+            client.setBucketPolicy(setBucketPolicyArgs);
177
+        } catch (Exception e) {
178
+          
179
+        }
180
+    }
181
+
182
+    /**
183
+     * 存储文件,不返回地址
184
+     *
185
+     * @param bucketName  桶名称
186
+     * @param key         唯一标示id,例如a.txt, doc/a.txt
187
+     * @param inputStream 文件流
188
+     * @author xuyuxiang
189
+     * @date 2022/1/5 23:24
190
+     */
191
+    public static void storageFile(String bucketName, String key, InputStream inputStream) {
192
+        try {
193
+            initClient();
194
+            PutObjectArgs putObjectArgs = PutObjectArgs.builder().bucket(bucketName).object(key)
195
+                    .contentType(getFileContentType(key)).stream(inputStream, inputStream.available(), -1).build();
196
+            client.putObject(putObjectArgs);
197
+        } catch (Exception e) {
198
+           
199
+        } finally {
200
+            IoUtil.close(inputStream);
201
+        }
202
+    }
203
+
204
+    /**
205
+     * 根据文件名获取ContentType
206
+     *
207
+     * @author xuyuxiang
208
+     * @date 2022/1/6 11:27
209
+     **/
210
+    private static String getFileContentType(String key) {
211
+        // 根据文件名获取contentType
212
+        String contentType = "application/octet-stream";
213
+        if (key.contains(".")) {
214
+            contentType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(key);
215
+        }
216
+        return contentType;
217
+    }
218
+
219
+}

+ 6 - 0
src/main/resources/bootstrap-dev.yml

@@ -43,8 +43,14 @@ spring:
43 43
         max-wait: -1ms
44 44
         max-idle: 8
45 45
         min-idle: 0
46
+minio:
47
+  endpoint: http://172.16.0.36:15772
48
+  access-key: 4vFQhyfxcwcqAXHPOV57
49
+  secret-key: 3kB9RIsEqXuHMG6FDDp4f299LACEwztgybwYTAmg
50
+  bucket-name: depot-qinghai
46 51
 web:
47 52
   upload-path: /home/depot/depot-web/apache-tomcat-8.0.53/webapps/ROOT/WEB-INF/classes/static
53
+
48 54
 mybatis-plus:
49 55
   mapper-locations: classpath:/mapper/*/*.xml
50 56
   configuration: