Skip to content

Commit

Permalink
Merge pull request #66 from yanyanho/main
Browse files Browse the repository at this point in the history
delete the ipfs service
  • Loading branch information
yanyanho authored Dec 3, 2023
2 parents ac1717b + de72fd0 commit cbba97b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 83 deletions.
130 changes: 65 additions & 65 deletions src/main/java/com/dl/officialsite/file/FileController.java
Original file line number Diff line number Diff line change
@@ -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());
// }
//}
36 changes: 18 additions & 18 deletions src/main/java/com/dl/officialsite/member/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class MemberController {
@Autowired
private MemberRepository memberRepository;

@Autowired
private IPFSService ipfsService;
// @Autowired
// private IPFSService ipfsService;
@Autowired
AaveService aaveService;

Expand Down Expand Up @@ -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<Member> 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<Member> 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")
Expand Down

0 comments on commit cbba97b

Please sign in to comment.