From e72e3872b6a7e3777b90cf65f24bf9bfbdf07f0f Mon Sep 17 00:00:00 2001 From: liberhe <411497616@qq.com> Date: Mon, 11 Dec 2023 18:39:49 +0800 Subject: [PATCH 1/6] add gitignore --- .gitignore | 2 + .../file/cos/COSClientConfig.java | 2 + .../officialsite/file/cos/COSProperties.java | 2 + .../dl/officialsite/file/cos/FileService.java | 2 + src/main/resources/application-dev.yml | 73 +++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 src/main/java/com/dl/officialsite/file/cos/COSClientConfig.java create mode 100644 src/main/java/com/dl/officialsite/file/cos/COSProperties.java create mode 100644 src/main/java/com/dl/officialsite/file/cos/FileService.java create mode 100644 src/main/resources/application-dev.yml diff --git a/.gitignore b/.gitignore index b3f03a7c..a3d43d8f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ .gitignore ./src/main/resources/ +./src/main/resources/application-dev.yml + HappyRedPacket.java # Package Files # diff --git a/src/main/java/com/dl/officialsite/file/cos/COSClientConfig.java b/src/main/java/com/dl/officialsite/file/cos/COSClientConfig.java new file mode 100644 index 00000000..b3f37f58 --- /dev/null +++ b/src/main/java/com/dl/officialsite/file/cos/COSClientConfig.java @@ -0,0 +1,2 @@ +package com.dl.officialsite.file.cos;public class COSClientConfig { +} diff --git a/src/main/java/com/dl/officialsite/file/cos/COSProperties.java b/src/main/java/com/dl/officialsite/file/cos/COSProperties.java new file mode 100644 index 00000000..34964d71 --- /dev/null +++ b/src/main/java/com/dl/officialsite/file/cos/COSProperties.java @@ -0,0 +1,2 @@ +package com.dl.officialsite.file.cos;public class COSProperties { +} diff --git a/src/main/java/com/dl/officialsite/file/cos/FileService.java b/src/main/java/com/dl/officialsite/file/cos/FileService.java new file mode 100644 index 00000000..18143215 --- /dev/null +++ b/src/main/java/com/dl/officialsite/file/cos/FileService.java @@ -0,0 +1,2 @@ +package com.dl.officialsite.file.cos;public class FileService { +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 00000000..27f5310c --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,73 @@ +server: + port: 8080 + servlet: + session: + timeout: 60m + cookie: + max-age: -1 +spring: + datasource: + url: jdbc:mysql://127.0.0.1:3306/dl?allowPublicKeyRetrieval=true&useSSL=false +#type: com.alibaba.druid.pool.DruidDataSource + username: root +# password: 12345678 + password: {{SPRING_DATASOURCE_PASSWORD}} + maximum-pool-size: 20 + + jpa: + hibernate: + ddl-auto: update + generate-ddl: true + show-sql: true + database-platform: org.hibernate.dialect.MySQL5Dialect + mail: + host: smtp.163.com + port: 465 + username: 15503679582@163.com + password: OXWEDGWEOGIGVWJN + properties: + mail: + smtp: + auth: true + ssl: + enable: true + session: + store-type: jdbc + jdbc: + initialize-schema: always + cleanup-cron: 0 */3 * * * * + timeout: 7200 + + + mvc: + pathmatch: + matching-strategy: ant_path_matcher + + +logging: + level: + org.springframework.security: debug + +ipfs: + url: /ip4/127.0.0.1/tcp/5001 + +web3j: + client-address: "https://polygon-rpc.com" + +oauth: + registrations: + github: + clientId: "Iv1.74aecf988af67044" + clientSecret: "d0f38f58e98bb3dbb9a6bf6a2e1211a4feb24767" + accessTokenUri: https://github.com/login/oauth/access_token + userAuthorizationUri: https://github.com/login/oauth/authorize + userInfoUri: https://api.github.com/user + +qcloud: + #初始化用户身份信息 前往控制台密钥管理查看 + secretId: "AKIDpT1Wq6B1d6RYO1Rh6RsIzX0JYaFoDRjD" + secretKey: "Xt6JYhKo5EIgJtRq3ObdT6WyRuJbkmld" + # 指定要上传到的存储桶 + bucketName: "" + # 地区选择 + regionName: "" \ No newline at end of file From 5d7b316712a2061eb5c9a8c37c6d7deda79dfa25 Mon Sep 17 00:00:00 2001 From: liberhe <411497616@qq.com> Date: Mon, 11 Dec 2023 18:40:56 +0800 Subject: [PATCH 2/6] ignore dev-yaml --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a3d43d8f..80a9926a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ .gitignore ./src/main/resources/ -./src/main/resources/application-dev.yml +src/main/resources/application-dev.yml HappyRedPacket.java From 521d86a887adaf768b22bae8d128293af20301a2 Mon Sep 17 00:00:00 2001 From: liberhe <411497616@qq.com> Date: Mon, 11 Dec 2023 18:41:59 +0800 Subject: [PATCH 3/6] add file storage --- build.gradle | 2 +- .../file/cos/COSClientConfig.java | 32 +++++++- .../officialsite/file/cos/COSProperties.java | 15 +++- .../dl/officialsite/file/cos/FileService.java | 70 +++++++++++++++++- .../com/dl/officialsite/hiring/Hiring.java | 1 + src/main/resources/application-dev.yml | 73 ------------------- src/main/resources/application.yml | 8 ++ 7 files changed, 124 insertions(+), 77 deletions(-) delete mode 100644 src/main/resources/application-dev.yml diff --git a/build.gradle b/build.gradle index 445905c4..19f8df1e 100644 --- a/build.gradle +++ b/build.gradle @@ -58,7 +58,7 @@ dependencies { // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-graphql //implementation 'org.springframework.boot:spring-boot-starter-graphql:2.7.17' implementation 'io.springfox:springfox-boot-starter:3.0.0' - + implementation 'com.qcloud:cos_api:5.6.155' //graphql // implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:latest.release")) diff --git a/src/main/java/com/dl/officialsite/file/cos/COSClientConfig.java b/src/main/java/com/dl/officialsite/file/cos/COSClientConfig.java index b3f37f58..43ea12c9 100644 --- a/src/main/java/com/dl/officialsite/file/cos/COSClientConfig.java +++ b/src/main/java/com/dl/officialsite/file/cos/COSClientConfig.java @@ -1,2 +1,32 @@ -package com.dl.officialsite.file.cos;public class COSClientConfig { +package com.dl.officialsite.file.cos; + + +import com.qcloud.cos.COSClient; +import com.qcloud.cos.ClientConfig; +import com.qcloud.cos.auth.BasicCOSCredentials; +import com.qcloud.cos.auth.COSCredentials; +import com.qcloud.cos.region.Region; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(COSProperties.class) +public class COSClientConfig { + + + @Autowired + private COSProperties cosProperties; + + @Bean + public COSClient cosClient(){ + COSCredentials cred = new BasicCOSCredentials(cosProperties.getSecretId(),cosProperties.getSecretKey()); + Region region = new Region(cosProperties.getRegionName()); + ClientConfig clientConfig = new ClientConfig(region); + // 3 生成 cos 客户端。 + COSClient cosClient = new COSClient(cred, clientConfig); + return cosClient; + } + } diff --git a/src/main/java/com/dl/officialsite/file/cos/COSProperties.java b/src/main/java/com/dl/officialsite/file/cos/COSProperties.java index 34964d71..aa719437 100644 --- a/src/main/java/com/dl/officialsite/file/cos/COSProperties.java +++ b/src/main/java/com/dl/officialsite/file/cos/COSProperties.java @@ -1,2 +1,15 @@ -package com.dl.officialsite.file.cos;public class COSProperties { +package com.dl.officialsite.file.cos; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@Data +@ConfigurationProperties(prefix = "qcloud") +public class COSProperties { + private String secretId; + private String secretKey; + private String bucketName; + private String regionName; + + } diff --git a/src/main/java/com/dl/officialsite/file/cos/FileService.java b/src/main/java/com/dl/officialsite/file/cos/FileService.java index 18143215..5942b9f5 100644 --- a/src/main/java/com/dl/officialsite/file/cos/FileService.java +++ b/src/main/java/com/dl/officialsite/file/cos/FileService.java @@ -1,2 +1,70 @@ -package com.dl.officialsite.file.cos;public class FileService { +package com.dl.officialsite.file.cos; + + +import com.qcloud.cos.COSClient; +import com.qcloud.cos.model.ObjectMetadata; +import com.qcloud.cos.model.PutObjectRequest; +import com.qcloud.cos.model.PutObjectResult; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +@Service +@Slf4j +public class FileService { + + String key; + + @Autowired + private COSClient cosClient; + @Autowired + private COSProperties cosProperties; + + // 支持的文件类型 + private static final List suffixes = Arrays.asList("image/png", "image/jpeg"); + + public String uploadImage(MultipartFile file) { + + try { + // 1、图片信息校验 + // 1)校验文件类型 + String type = file.getContentType(); //获取文件格式 + if (!suffixes.contains(type)) { + // logger.info("上传失败,文件类型不匹配:{}", type); + return null; + } + // 2)校验图片内容 + BufferedImage image = ImageIO.read(file.getInputStream()); + if (image == null) { + // logger.info("上传失败,文件内容不符合要求"); + return null; + } + + ObjectMetadata objectMetadata = new ObjectMetadata(); + objectMetadata.setContentType(type); + UUID uuid = UUID.randomUUID(); + // 指定要上传到 COS 上对象键 此key是文件唯一标识 + key = uuid.toString().replace("-","")+".jpg"; + PutObjectRequest putObjectRequest = new PutObjectRequest(cosProperties.getBucketName(), key, file.getInputStream(),objectMetadata); + + //使用cosClient调用第三方接口 + PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); + log.info(putObjectRequest+""); + //返回路径 + + }catch (Exception e){ + e.printStackTrace(); + } + //拼接返回路径 + String imagePath = "https://" + cosProperties.getBucketName() + ".cos." + cosProperties.getRegionName() + ".myqcloud.com/" + key; + return imagePath; + } + } diff --git a/src/main/java/com/dl/officialsite/hiring/Hiring.java b/src/main/java/com/dl/officialsite/hiring/Hiring.java index 416a8c66..4661bc52 100644 --- a/src/main/java/com/dl/officialsite/hiring/Hiring.java +++ b/src/main/java/com/dl/officialsite/hiring/Hiring.java @@ -32,6 +32,7 @@ public class Hiring { private String invoice; + // private String salary; private int minYearlySalary; private int maxYearlySalary; diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml deleted file mode 100644 index 27f5310c..00000000 --- a/src/main/resources/application-dev.yml +++ /dev/null @@ -1,73 +0,0 @@ -server: - port: 8080 - servlet: - session: - timeout: 60m - cookie: - max-age: -1 -spring: - datasource: - url: jdbc:mysql://127.0.0.1:3306/dl?allowPublicKeyRetrieval=true&useSSL=false -#type: com.alibaba.druid.pool.DruidDataSource - username: root -# password: 12345678 - password: {{SPRING_DATASOURCE_PASSWORD}} - maximum-pool-size: 20 - - jpa: - hibernate: - ddl-auto: update - generate-ddl: true - show-sql: true - database-platform: org.hibernate.dialect.MySQL5Dialect - mail: - host: smtp.163.com - port: 465 - username: 15503679582@163.com - password: OXWEDGWEOGIGVWJN - properties: - mail: - smtp: - auth: true - ssl: - enable: true - session: - store-type: jdbc - jdbc: - initialize-schema: always - cleanup-cron: 0 */3 * * * * - timeout: 7200 - - - mvc: - pathmatch: - matching-strategy: ant_path_matcher - - -logging: - level: - org.springframework.security: debug - -ipfs: - url: /ip4/127.0.0.1/tcp/5001 - -web3j: - client-address: "https://polygon-rpc.com" - -oauth: - registrations: - github: - clientId: "Iv1.74aecf988af67044" - clientSecret: "d0f38f58e98bb3dbb9a6bf6a2e1211a4feb24767" - accessTokenUri: https://github.com/login/oauth/access_token - userAuthorizationUri: https://github.com/login/oauth/authorize - userInfoUri: https://api.github.com/user - -qcloud: - #初始化用户身份信息 前往控制台密钥管理查看 - secretId: "AKIDpT1Wq6B1d6RYO1Rh6RsIzX0JYaFoDRjD" - secretKey: "Xt6JYhKo5EIgJtRq3ObdT6WyRuJbkmld" - # 指定要上传到的存储桶 - bucketName: "" - # 地区选择 - regionName: "" \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2f2b2c01..b203e993 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -63,3 +63,11 @@ oauth: userAuthorizationUri: https://github.com/login/oauth/authorize userInfoUri: https://api.github.com/user +qcloud: + #初始化用户身份信息 前往控制台密钥管理查看 + secretId: "" + secretKey: "" + # 指定要上传到的存储桶 + bucketName: "" + # 地区选择 + regionName: "" \ No newline at end of file From 9f164962ee3d0686fe24d2aa9155d24f6bf59d5f Mon Sep 17 00:00:00 2001 From: liberhe <411497616@qq.com> Date: Mon, 11 Dec 2023 23:33:18 +0800 Subject: [PATCH 4/6] add file upload --- README.md | 8 +- .../dl/officialsite/file/FileController.java | 118 ++++++++---------- .../file/FileControllerWithipfs.java | 65 ++++++++++ .../dl/officialsite/file/cos/FileService.java | 44 ++++++- .../login/filter/LoginFilter.java | 7 +- .../sharing/model/db/TbShare.java | 10 +- src/main/resources/application.yml | 7 +- 7 files changed, 179 insertions(+), 80 deletions(-) create mode 100644 src/main/java/com/dl/officialsite/file/FileControllerWithipfs.java diff --git a/README.md b/README.md index 8e54d938..e9c6269d 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ https://github.com/spruceid/siwe-go/blob/main/message.go ## build ``` - ssh root@43.135.22.107 + ssh root@ip ./gradlew build -x test - scp ./dist/apps/dl.jar root@43.135.22.107:/root/Official-website-backend/dist/apps + scp ./dist/apps/dl.jar root@ip:/root/Official-website-backend/dist/apps ``` @@ -38,4 +38,6 @@ https://github.com/spruceid/siwe-go/blob/main/message.go - upload pic: https://juejin.cn/post/6844903630416379918 - JPA query: https://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl - JPA : https://www.baeldung.com/hibernate-criteria-queries -- session filter: https://blog.csdn.net/dothetrick/article/details/110356640 \ No newline at end of file +- session filter: https://blog.csdn.net/dothetrick/article/details/110356640 +- cos: https://cloud.tencent.com/developer/article/1559746 +- cos download: https://blog.csdn.net/qq_43960768/article/details/126731733 \ No newline at end of file diff --git a/src/main/java/com/dl/officialsite/file/FileController.java b/src/main/java/com/dl/officialsite/file/FileController.java index 9370e7dc..d5656cf6 100644 --- a/src/main/java/com/dl/officialsite/file/FileController.java +++ b/src/main/java/com/dl/officialsite/file/FileController.java @@ -1,65 +1,53 @@ -//package com.dl.officialsite.file; -// -//import cn.hutool.core.io.IoUtil; -//import com.dl.officialsite.common.base.BaseResponse; -//import com.dl.officialsite.common.enums.CodeEnums; -//import com.dl.officialsite.common.exception.BizException; -//import com.dl.officialsite.ipfs.IPFSService; -//import lombok.Data; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.web.bind.annotation.*; -//import org.springframework.web.multipart.MultipartFile; -// -//import javax.servlet.http.HttpServletResponse; -//import java.io.IOException; -//import java.io.InputStream; -// -///** -// * @ClassName FileController -// * @Author jackchen -// * @Date 2023/10/16 17:07 -// * @Description 文件上传 -// **/ -//@RestController -//@RequestMapping("/file") -//@Data -//@Slf4j -//public class FileController { -// -// private final IPFSService ipfsService; -// -// /** -// * 文件上传 -// */ -// @PostMapping("/upload") -// public BaseResponse upload(@RequestParam("file") MultipartFile file, -// @RequestParam String address) { -// try { -// String hash = ipfsService.upload(file.getBytes()); -// return BaseResponse.successWithData(hash); -// } catch (IOException e) { -// log.error("文件上传失败{}", file.getName()); -// throw new BizException(CodeEnums.FAIL_UPLOAD_FAIL.getCode(), -// CodeEnums.FAIL_UPLOAD_FAIL.getMsg()); -// } -// } -// -// /** -// * 文件下载 -// */ -// @GetMapping("/download") -// public void download(@RequestParam String fileHash, -// @RequestParam String address, HttpServletResponse response) -// throws IOException { -// InputStream inputStream = null; -// try { -// inputStream = ipfsService.downloadStream(fileHash); -// } catch (IOException e) { -// log.error("文件下载失败{}", fileHash); -// throw new BizException(CodeEnums.FAIL_DOWNLOAD_FAIL.getCode(), -// CodeEnums.FAIL_DOWNLOAD_FAIL.getMsg()); -// } -// response.setContentType("application/octet-stream"); -// IoUtil.copy(inputStream, response.getOutputStream()); -// } -//} +package com.dl.officialsite.file;//package com.dl.officialsite.file; + +import cn.hutool.core.io.IoUtil; +import com.dl.officialsite.common.base.BaseResponse; +import com.dl.officialsite.file.cos.FileService; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; + +/** + * @ClassName FileController + * @Author jackchen + * @Date 2023/10/16 17:07 + * @Description 文件上传 + **/ +@RestController +@RequestMapping("/file") +@Data +@Slf4j +public class FileController { + + private final FileService fileService; + + /** + * 文件上传 + */ + @PostMapping("/upload") + public BaseResponse upload(@RequestParam(required = false) MultipartFile file, + @RequestParam String address) { + String hash = fileService.upload(file); + return BaseResponse.successWithData(hash); + } + + /** + * todo + */ + @GetMapping("/download") + public void download(@RequestParam String fileHash, + @RequestParam String address, HttpServletResponse response) + throws IOException { + InputStream inputStream = null; + + inputStream = fileService.download(fileHash); + + response.setContentType("application/octet-stream"); + IoUtil.copy(inputStream, response.getOutputStream()); + } +} diff --git a/src/main/java/com/dl/officialsite/file/FileControllerWithipfs.java b/src/main/java/com/dl/officialsite/file/FileControllerWithipfs.java new file mode 100644 index 00000000..9370e7dc --- /dev/null +++ b/src/main/java/com/dl/officialsite/file/FileControllerWithipfs.java @@ -0,0 +1,65 @@ +//package com.dl.officialsite.file; +// +//import cn.hutool.core.io.IoUtil; +//import com.dl.officialsite.common.base.BaseResponse; +//import com.dl.officialsite.common.enums.CodeEnums; +//import com.dl.officialsite.common.exception.BizException; +//import com.dl.officialsite.ipfs.IPFSService; +//import lombok.Data; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.web.bind.annotation.*; +//import org.springframework.web.multipart.MultipartFile; +// +//import javax.servlet.http.HttpServletResponse; +//import java.io.IOException; +//import java.io.InputStream; +// +///** +// * @ClassName FileController +// * @Author jackchen +// * @Date 2023/10/16 17:07 +// * @Description 文件上传 +// **/ +//@RestController +//@RequestMapping("/file") +//@Data +//@Slf4j +//public class FileController { +// +// private final IPFSService ipfsService; +// +// /** +// * 文件上传 +// */ +// @PostMapping("/upload") +// public BaseResponse upload(@RequestParam("file") MultipartFile file, +// @RequestParam String address) { +// try { +// String hash = ipfsService.upload(file.getBytes()); +// return BaseResponse.successWithData(hash); +// } catch (IOException e) { +// log.error("文件上传失败{}", file.getName()); +// throw new BizException(CodeEnums.FAIL_UPLOAD_FAIL.getCode(), +// CodeEnums.FAIL_UPLOAD_FAIL.getMsg()); +// } +// } +// +// /** +// * 文件下载 +// */ +// @GetMapping("/download") +// public void download(@RequestParam String fileHash, +// @RequestParam String address, HttpServletResponse response) +// throws IOException { +// InputStream inputStream = null; +// try { +// inputStream = ipfsService.downloadStream(fileHash); +// } catch (IOException e) { +// log.error("文件下载失败{}", fileHash); +// throw new BizException(CodeEnums.FAIL_DOWNLOAD_FAIL.getCode(), +// CodeEnums.FAIL_DOWNLOAD_FAIL.getMsg()); +// } +// response.setContentType("application/octet-stream"); +// IoUtil.copy(inputStream, response.getOutputStream()); +// } +//} diff --git a/src/main/java/com/dl/officialsite/file/cos/FileService.java b/src/main/java/com/dl/officialsite/file/cos/FileService.java index 5942b9f5..55c54413 100644 --- a/src/main/java/com/dl/officialsite/file/cos/FileService.java +++ b/src/main/java/com/dl/officialsite/file/cos/FileService.java @@ -12,6 +12,9 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -20,8 +23,6 @@ @Slf4j public class FileService { - String key; - @Autowired private COSClient cosClient; @Autowired @@ -30,8 +31,33 @@ public class FileService { // 支持的文件类型 private static final List suffixes = Arrays.asList("image/png", "image/jpeg"); - public String uploadImage(MultipartFile file) { + public String upload(MultipartFile file) { + + // 简单文件上传, 最大支持 5 GB, 适用于小文件上传, 建议 20 M 以下的文件使用该接口 + // 大文件上传请参照 API 文档高级 API 上传 + File localFile = null; + + String oldFileName = file.getOriginalFilename(); + String eName = oldFileName.substring(oldFileName.lastIndexOf(".")); + String newFileName = UUID.randomUUID()+eName; + String key = null; + try { + localFile = File.createTempFile("temp",null); + file.transferTo(localFile); + key = UUID.randomUUID().toString().replace("-",""); + PutObjectRequest putObjectRequest = new PutObjectRequest(cosProperties.getBucketName(), key, localFile); + PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); + } catch (IOException e) { + } + //拼接返回路径 + cosClient.shutdown(); + String imagePath = "https://" + cosProperties.getBucketName() + ".cos." + cosProperties.getRegionName() + ".myqcloud.com/" + key; + return imagePath; + } + + public String uploadImage(MultipartFile file) { + String key = null; try { // 1、图片信息校验 // 1)校验文件类型 @@ -62,9 +88,15 @@ public String uploadImage(MultipartFile file) { }catch (Exception e){ e.printStackTrace(); } - //拼接返回路径 - String imagePath = "https://" + cosProperties.getBucketName() + ".cos." + cosProperties.getRegionName() + ".myqcloud.com/" + key; - return imagePath; + cosClient.shutdown(); + //拼接返回路径 + String imagePath = "https://" + cosProperties.getBucketName() + ".cos." + cosProperties.getRegionName() + ".myqcloud.com/" + key; + return imagePath; } + + //todo + public InputStream download(String fileHash) { + return null; + } } diff --git a/src/main/java/com/dl/officialsite/login/filter/LoginFilter.java b/src/main/java/com/dl/officialsite/login/filter/LoginFilter.java index 3f19d94c..c804b9b4 100644 --- a/src/main/java/com/dl/officialsite/login/filter/LoginFilter.java +++ b/src/main/java/com/dl/officialsite/login/filter/LoginFilter.java @@ -13,6 +13,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; import org.springframework.session.web.http.SessionRepositoryFilter; import org.springframework.stereotype.Component; @@ -26,7 +29,9 @@ import java.io.PrintWriter; import java.util.*; -@Component +@Configuration +@ConditionalOnProperty(value="login.filter", + havingValue = "true") @Order(SessionRepositoryFilter.DEFAULT_ORDER + 1) @Slf4j public class LoginFilter extends OncePerRequestFilter { diff --git a/src/main/java/com/dl/officialsite/sharing/model/db/TbShare.java b/src/main/java/com/dl/officialsite/sharing/model/db/TbShare.java index 25e2cf34..2542c5b9 100644 --- a/src/main/java/com/dl/officialsite/sharing/model/db/TbShare.java +++ b/src/main/java/com/dl/officialsite/sharing/model/db/TbShare.java @@ -1,13 +1,18 @@ package com.dl.officialsite.sharing.model.db; import lombok.Data; +import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; @Data @Entity +@DynamicUpdate +@EntityListeners(AuditingEntityListener.class) @Table(name = "tb_share", - uniqueConstraints={@UniqueConstraint(columnNames={"theme"})}, + uniqueConstraints={ + @UniqueConstraint(columnNames={"theme"})}, indexes= { @Index(columnList="member_address") }) @@ -23,6 +28,7 @@ public class TbShare { /** * 分享主题 */ + @Column(length = 256) private String theme; /** @@ -58,7 +64,7 @@ public class TbShare { /** * 分享人 */ - @Column(name = "member_address") + @Column(name = "member_address",length = 42) private String memberAddress; /** diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b203e993..0a175bae 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -38,7 +38,8 @@ spring: cleanup-cron: 0 */3 * * * * timeout: 7200 - + profiles: + active: dev mvc: pathmatch: matching-strategy: ant_path_matcher @@ -57,8 +58,8 @@ web3j: oauth: registrations: github: - clientId: "Iv1.74aecf988af67044" - clientSecret: "d0f38f58e98bb3dbb9a6bf6a2e1211a4feb24767" + clientId: "" + clientSecret: "" accessTokenUri: https://github.com/login/oauth/access_token userAuthorizationUri: https://github.com/login/oauth/authorize userInfoUri: https://api.github.com/user From e12d91ab92a265d65cfd7bd2b2dc3790b9f91382 Mon Sep 17 00:00:00 2001 From: liberhe <411497616@qq.com> Date: Mon, 11 Dec 2023 23:36:33 +0800 Subject: [PATCH 5/6] merge code --- src/main/java/com/dl/officialsite/common/enums/CodeEnums.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java b/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java index 1c868b57..3c410dd8 100644 --- a/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java +++ b/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java @@ -22,7 +22,7 @@ public enum CodeEnums { MEMBER_ALREADY_REQUEST_TEAM("1007", "member already request team"), NOT_FOUND_JD("1008", "not found jd"), - NOT_FOUND_MEMBER("1008", "not found user"); + NOT_FOUND_MEMBER("1008", "not found user"), //Sharing SHARING_NOT_FOUND("5001", "Sharing not found"), SHARING_NOT_OWNER("5002", "You are no sharing user"), From 0fd4b7bdf7c3b1012f4fdfabd48b797a8f968762 Mon Sep 17 00:00:00 2001 From: liberhe <411497616@qq.com> Date: Mon, 11 Dec 2023 23:44:05 +0800 Subject: [PATCH 6/6] add application-template --- src/main/resources/application-template.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/resources/application-template.yml b/src/main/resources/application-template.yml index 0a539621..cf0170a1 100644 --- a/src/main/resources/application-template.yml +++ b/src/main/resources/application-template.yml @@ -58,4 +58,11 @@ oauth: userAuthorizationUri: https://github.com/login/oauth/authorize userInfoUri: https://api.github.com/user +qcloud: + secretId: "" + secretKey: "" + bucketName: "" + regionName: "" +login: + filter: true \ No newline at end of file