From 7abd8ebfdea1bdb6048934b1b5caba2e09922b59 Mon Sep 17 00:00:00 2001 From: liberhe <411497616@qq.com> Date: Sun, 3 Dec 2023 16:18:16 +0800 Subject: [PATCH] delete the ipfsservice --- .../dl/officialsite/file/FileController.java | 130 +++++++++--------- .../officialsite/member/MemberController.java | 36 ++--- 2 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/main/java/com/dl/officialsite/file/FileController.java b/src/main/java/com/dl/officialsite/file/FileController.java index c06b1695..9370e7dc 100644 --- a/src/main/java/com/dl/officialsite/file/FileController.java +++ b/src/main/java/com/dl/officialsite/file/FileController.java @@ -1,65 +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()); - } -} +//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/member/MemberController.java b/src/main/java/com/dl/officialsite/member/MemberController.java index f11d919e..0760c365 100644 --- a/src/main/java/com/dl/officialsite/member/MemberController.java +++ b/src/main/java/com/dl/officialsite/member/MemberController.java @@ -36,8 +36,8 @@ public class MemberController { @Autowired private MemberRepository memberRepository; - @Autowired - private IPFSService ipfsService; +// @Autowired +// private IPFSService ipfsService; @Autowired AaveService aaveService; @@ -128,22 +128,22 @@ public BaseResponse createMember(@Valid @RequestBody Member member, @RequestPara //ignore - @PostMapping("/avatar/update") - public BaseResponse uploadAvatar(@RequestParam String address, @RequestParam("file") MultipartFile file) { - try { - String hash = ipfsService.upload(file.getBytes()); - Optional memberData = memberRepository.findByAddress(address); - if (memberData.isPresent()) { - Member _member = memberData.get(); - _member.setAvatar(hash); - memberRepository.save(_member); - } - return BaseResponse.successWithData(null); - } catch (Exception e) { - return BaseResponse.failWithReason(CodeEnums.FAIL_UPLOAD_FAIL.getCode(), - CodeEnums.FAIL_UPLOAD_FAIL.getMsg()); - } - } +// @PostMapping("/avatar/update") +// public BaseResponse uploadAvatar(@RequestParam String address, @RequestParam("file") MultipartFile file) { +// try { +// String hash = ipfsService.upload(file.getBytes()); +// Optional memberData = memberRepository.findByAddress(address); +// if (memberData.isPresent()) { +// Member _member = memberData.get(); +// _member.setAvatar(hash); +// memberRepository.save(_member); +// } +// return BaseResponse.successWithData(null); +// } catch (Exception e) { +// return BaseResponse.failWithReason(CodeEnums.FAIL_UPLOAD_FAIL.getCode(), +// CodeEnums.FAIL_UPLOAD_FAIL.getMsg()); +// } +// } @PutMapping("/update")