mirror of https://github.com/elunez/eladmin
remove qiniu
parent
5cb24d00ec
commit
b48f7af12f
|
@ -4,4 +4,5 @@
|
||||||
*/target/*
|
*/target/*
|
||||||
*/*.iml
|
*/*.iml
|
||||||
/.gradle/
|
/.gradle/
|
||||||
/application.pid
|
/application.pid
|
||||||
|
/eladmin-system/application.pid
|
||||||
|
|
17
README.md
17
README.md
|
@ -1,10 +1,5 @@
|
||||||
# ELADMIN Backend Management System
|
# ELADMIN Backend Management System
|
||||||
|
|
||||||
[](https://github.com/elunez/eladmin/blob/master/LICENSE)
|
|
||||||
[](https://gitee.com/elunez/eladmin)
|
|
||||||
[](https://github.com/elunez/eladmin)
|
|
||||||
[](https://github.com/elunez/eladmin)
|
|
||||||
|
|
||||||
## Project Introduction
|
## Project Introduction
|
||||||
|
|
||||||
A front-end and back-end separated management system based on Spring Boot 2.7.18, Spring Boot JPA, JWT, Spring Security, Redis, and Vue.
|
A front-end and back-end separated management system based on Spring Boot 2.7.18, Spring Boot JPA, JWT, Spring Security, Redis, and Vue.
|
||||||
|
@ -26,12 +21,6 @@ A MyBatis-Plus version has also been released:
|
||||||
| GitHub | https://github.com/elunez/eladmin | https://github.com/elunez/eladmin-web |
|
| GitHub | https://github.com/elunez/eladmin | https://github.com/elunez/eladmin-web |
|
||||||
| Gitee | https://gitee.com/elunez/eladmin | https://gitee.com/elunez/eladmin-web |
|
| Gitee | https://gitee.com/elunez/eladmin | https://gitee.com/elunez/eladmin-web |
|
||||||
|
|
||||||
## VPS Recommendation
|
|
||||||
|
|
||||||
[](https://bwh81.net/aff.php?aff=70876)
|
|
||||||
|
|
||||||
Use promo code: `BWHCGLUKKB` for a 6.81% discount [See details](https://bwhstock.in/)
|
|
||||||
|
|
||||||
## Main Features
|
## Main Features
|
||||||
|
|
||||||
- Uses the latest tech stack with rich community resources.
|
- Uses the latest tech stack with rich community resources.
|
||||||
|
@ -58,7 +47,7 @@ Use promo code: `BWHCGLUKKB` for a 6.81% discount [See details](https://bwhstock
|
||||||
- Scheduled Tasks: Integrate Quartz for scheduled tasks, with task logs and task execution status.
|
- Scheduled Tasks: Integrate Quartz for scheduled tasks, with task logs and task execution status.
|
||||||
- Code Generation: High flexibility code generation for front-end and back-end, reducing repetitive work.
|
- Code Generation: High flexibility code generation for front-end and back-end, reducing repetitive work.
|
||||||
- Email Tool: Send HTML format emails with rich text.
|
- Email Tool: Send HTML format emails with rich text.
|
||||||
- Qiniu Cloud Storage: Synchronize Qiniu cloud storage data to the system, no need to log in to Qiniu cloud to operate cloud data.
|
- AWS Cloud Storage: Synchronize AWS cloud storage data to the system, no need to log in to AWS cloud to operate cloud data.
|
||||||
- Alipay Payment: Integrate Alipay payment and provide a test account for self-testing.
|
- Alipay Payment: Integrate Alipay payment and provide a test account for self-testing.
|
||||||
- Server Monitoring: Monitor server load status.
|
- Server Monitoring: Monitor server load status.
|
||||||
- Operations Management: One-click deployment of your application.
|
- Operations Management: One-click deployment of your application.
|
||||||
|
@ -70,7 +59,7 @@ The project uses a modular development approach, with the following structure:
|
||||||
- `eladmin-common`: System public module, including various utility classes and public configurations.
|
- `eladmin-common`: System public module, including various utility classes and public configurations.
|
||||||
- `eladmin-system`: System core module and project entry module, also the final module to be packaged and deployed.
|
- `eladmin-system`: System core module and project entry module, also the final module to be packaged and deployed.
|
||||||
- `eladmin-logging`: System log module, other modules need to import this module to record logs.
|
- `eladmin-logging`: System log module, other modules need to import this module to record logs.
|
||||||
- `eladmin-tools`: Third-party tool module, including email, Qiniu cloud storage, local storage, and Alipay payment.
|
- `eladmin-tools`: Third-party tool module, including email, AWS cloud storage, local storage
|
||||||
- `eladmin-generator`: System code generation module, supporting front-end and back-end CRUD code generation.
|
- `eladmin-generator`: System code generation module, supporting front-end and back-end CRUD code generation.
|
||||||
|
|
||||||
## Detailed Structure
|
## Detailed Structure
|
||||||
|
@ -100,7 +89,7 @@ The project uses a modular development approach, with the following structure:
|
||||||
- eladmin-logging System Log Module
|
- eladmin-logging System Log Module
|
||||||
- eladmin-tools Third-party Tool Module
|
- eladmin-tools Third-party Tool Module
|
||||||
- email Email tool
|
- email Email tool
|
||||||
- qiniu Qiniu cloud storage tool
|
- AWS S3 cloud storage tool
|
||||||
- alipay Alipay payment tool
|
- alipay Alipay payment tool
|
||||||
- local-storage Local storage tool
|
- local-storage Local storage tool
|
||||||
- eladmin-generator System Code Generation Module
|
- eladmin-generator System Code Generation Module
|
||||||
|
|
|
@ -63,7 +63,7 @@ task:
|
||||||
# Queue capacity
|
# Queue capacity
|
||||||
queue-capacity: 50
|
queue-capacity: 50
|
||||||
|
|
||||||
# Qiniu Cloud
|
# S3 Cloud
|
||||||
s3:
|
s3:
|
||||||
# File size /M
|
# File size /M
|
||||||
max-size: 15
|
max-size: 15
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<mail.version>1.4.7</mail.version>
|
<mail.version>1.4.7</mail.version>
|
||||||
<qiniu.version>7.9.3</qiniu.version>
|
|
||||||
<alipay.version>4.22.57.ALL</alipay.version>
|
<alipay.version>4.22.57.ALL</alipay.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -31,18 +30,11 @@
|
||||||
<version>${mail.version}</version>
|
<version>${mail.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Qiniu Cloud Storage -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.qiniu</groupId>
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
<artifactId>qiniu-java-sdk</artifactId>
|
<artifactId>s3</artifactId>
|
||||||
<version>${qiniu.version}</version>
|
<version>2.25.22</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Alipay dependency -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alipay.sdk</groupId>
|
|
||||||
<artifactId>alipay-sdk-java</artifactId>
|
|
||||||
<version>${alipay.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -15,24 +15,15 @@
|
||||||
*/
|
*/
|
||||||
package me.zhengjie.service.impl;
|
package me.zhengjie.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.qiniu.common.QiniuException;
|
|
||||||
import com.qiniu.http.Response;
|
|
||||||
import com.qiniu.storage.BucketManager;
|
|
||||||
import com.qiniu.storage.Configuration;
|
|
||||||
import com.qiniu.storage.UploadManager;
|
|
||||||
import com.qiniu.storage.model.DefaultPutRet;
|
|
||||||
import com.qiniu.storage.model.FileInfo;
|
|
||||||
import com.qiniu.util.Auth;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import me.zhengjie.domain.S3Content;
|
|
||||||
import me.zhengjie.domain.S3Config;
|
import me.zhengjie.domain.S3Config;
|
||||||
|
import me.zhengjie.domain.S3Content;
|
||||||
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.repository.S3ConfigRepository;
|
import me.zhengjie.repository.S3ConfigRepository;
|
||||||
import me.zhengjie.repository.S3ContentRepository;
|
import me.zhengjie.repository.S3ContentRepository;
|
||||||
|
import me.zhengjie.service.S3Service;
|
||||||
import me.zhengjie.service.dto.S3QueryCriteria;
|
import me.zhengjie.service.dto.S3QueryCriteria;
|
||||||
import me.zhengjie.utils.*;
|
import me.zhengjie.utils.*;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
|
||||||
import me.zhengjie.service.S3Service;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CachePut;
|
import org.springframework.cache.annotation.CachePut;
|
||||||
|
@ -41,6 +32,7 @@ import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -92,39 +84,7 @@ public class S3ServiceImpl implements S3Service {
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public S3Content upload(MultipartFile file, S3Config s3Config) {
|
public S3Content upload(MultipartFile file, S3Config s3Config) {
|
||||||
FileUtil.checkSize(maxSize, file.getSize());
|
return null;
|
||||||
if(s3Config.getId() == null){
|
|
||||||
throw new BadRequestException("Please add the corresponding configuration first, then operate");
|
|
||||||
}
|
|
||||||
// Construct a configuration class with the specified Zone object
|
|
||||||
Configuration cfg = new Configuration(S3Util.getRegion(s3Config.getZone()));
|
|
||||||
UploadManager uploadManager = new UploadManager(cfg);
|
|
||||||
Auth auth = Auth.create(s3Config.getAccessKey(), s3Config.getSecretKey());
|
|
||||||
String upToken = auth.uploadToken(s3Config.getBucket());
|
|
||||||
try {
|
|
||||||
String key = file.getOriginalFilename();
|
|
||||||
if(s3ContentRepository.findByKey(key) != null) {
|
|
||||||
key = S3Util.getKey(key);
|
|
||||||
}
|
|
||||||
Response response = uploadManager.put(file.getBytes(), key, upToken);
|
|
||||||
// Parse the result of successful upload
|
|
||||||
DefaultPutRet putRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class);
|
|
||||||
S3Content content = s3ContentRepository.findByKey(FileUtil.getFileNameNoEx(putRet.key));
|
|
||||||
if(content == null){
|
|
||||||
// Store in database
|
|
||||||
S3Content s3Content = new S3Content();
|
|
||||||
s3Content.setSuffix(FileUtil.getExtensionName(putRet.key));
|
|
||||||
s3Content.setBucket(s3Config.getBucket());
|
|
||||||
s3Content.setType(s3Config.getType());
|
|
||||||
s3Content.setKey(FileUtil.getFileNameNoEx(putRet.key));
|
|
||||||
s3Content.setUrl(s3Config.getHost()+"/"+putRet.key);
|
|
||||||
s3Content.setSize(FileUtil.getSize(Integer.parseInt(String.valueOf(file.getSize()))));
|
|
||||||
return s3ContentRepository.save(s3Content);
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BadRequestException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -136,69 +96,19 @@ public class S3ServiceImpl implements S3Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String download(S3Content content,S3Config config){
|
public String download(S3Content content,S3Config config){
|
||||||
String finalUrl;
|
return null;
|
||||||
String type = "Public";
|
|
||||||
if(type.equals(content.getType())){
|
|
||||||
finalUrl = content.getUrl();
|
|
||||||
} else {
|
|
||||||
Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
|
|
||||||
// 1 hour, can customize link expiration time
|
|
||||||
long expireInSeconds = 3600;
|
|
||||||
finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds);
|
|
||||||
}
|
|
||||||
return finalUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(S3Content content, S3Config config) {
|
public void delete(S3Content content, S3Config config) {
|
||||||
// Construct a configuration class with the specified Zone object
|
|
||||||
Configuration cfg = new Configuration(S3Util.getRegion(config.getZone()));
|
|
||||||
Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
|
|
||||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
|
||||||
try {
|
|
||||||
bucketManager.delete(content.getBucket(), content.getKey() + "." + content.getSuffix());
|
|
||||||
s3ContentRepository.delete(content);
|
|
||||||
} catch (QiniuException ex) {
|
|
||||||
s3ContentRepository.delete(content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void synchronize(S3Config config) {
|
public void synchronize(S3Config config) {
|
||||||
if(config.getId() == null){
|
|
||||||
throw new BadRequestException("Please add the corresponding configuration first, then operate");
|
|
||||||
}
|
|
||||||
// Construct a configuration class with the specified Zone object
|
|
||||||
Configuration cfg = new Configuration(S3Util.getRegion(config.getZone()));
|
|
||||||
Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
|
|
||||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
|
||||||
// File name prefix
|
|
||||||
String prefix = "";
|
|
||||||
// Length limit for each iteration, maximum 1000, recommended value 1000
|
|
||||||
int limit = 1000;
|
|
||||||
// Specify directory separator, list all common prefixes (simulate directory listing effect). Default value is empty string
|
|
||||||
String delimiter = "";
|
|
||||||
// List space file list
|
|
||||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(config.getBucket(), prefix, limit, delimiter);
|
|
||||||
while (fileListIterator.hasNext()) {
|
|
||||||
// Process the obtained file list result
|
|
||||||
S3Content s3Content;
|
|
||||||
FileInfo[] items = fileListIterator.next();
|
|
||||||
for (FileInfo item : items) {
|
|
||||||
if(s3ContentRepository.findByKey(FileUtil.getFileNameNoEx(item.key)) == null){
|
|
||||||
s3Content = new S3Content();
|
|
||||||
s3Content.setSize(FileUtil.getSize(Integer.parseInt(String.valueOf(item.fsize))));
|
|
||||||
s3Content.setSuffix(FileUtil.getExtensionName(item.key));
|
|
||||||
s3Content.setKey(FileUtil.getFileNameNoEx(item.key));
|
|
||||||
s3Content.setType(config.getType());
|
|
||||||
s3Content.setBucket(config.getBucket());
|
|
||||||
s3Content.setUrl(config.getHost()+"/"+item.key);
|
|
||||||
s3ContentRepository.save(s3Content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Zheng Jie
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package me.zhengjie.utils;
|
|
||||||
|
|
||||||
import com.qiniu.storage.Region;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* S3 cloud storage utility class
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2018-12-31
|
|
||||||
*/
|
|
||||||
public class S3Util {
|
|
||||||
|
|
||||||
private static final String HUAD = "East China";
|
|
||||||
|
|
||||||
private static final String HUAB = "North China";
|
|
||||||
|
|
||||||
private static final String HUAN = "South China";
|
|
||||||
|
|
||||||
private static final String BEIM = "North America";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the corresponding relationship of the machine room
|
|
||||||
* @param zone machine room name
|
|
||||||
* @return Region
|
|
||||||
*/
|
|
||||||
public static Region getRegion(String zone){
|
|
||||||
|
|
||||||
if(HUAD.equals(zone)){
|
|
||||||
return Region.huadong();
|
|
||||||
} else if(HUAB.equals(zone)){
|
|
||||||
return Region.huabei();
|
|
||||||
} else if(HUAN.equals(zone)){
|
|
||||||
return Region.huanan();
|
|
||||||
} else if (BEIM.equals(zone)){
|
|
||||||
return Region.beimei();
|
|
||||||
// Otherwise, it is Southeast Asia
|
|
||||||
} else {
|
|
||||||
return Region.qvmHuadong();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* By default, if no key is specified, the hash value of the file content is used as the file name
|
|
||||||
* @param file file name
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
public static String getKey(String file){
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
||||||
Date date = new Date();
|
|
||||||
return FileUtil.getFileNameNoEx(file) + "-" +
|
|
||||||
sdf.format(date) +
|
|
||||||
"." +
|
|
||||||
FileUtil.getExtensionName(file);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue