ADD GET /torrent/{torrentId} get info of torrent
Change-Id: I0bd1abe454af0dee5a5ea0228e934f56368d234e
diff --git a/src/main/java/com/example/g8backend/controller/TorrentController.java b/src/main/java/com/example/g8backend/controller/TorrentController.java
index e9216f8..2780722 100644
--- a/src/main/java/com/example/g8backend/controller/TorrentController.java
+++ b/src/main/java/com/example/g8backend/controller/TorrentController.java
@@ -29,9 +29,26 @@
@Autowired
private IUserService userService;
+
+ // 获取种子信息
+ @GetMapping("/{torrentId}")
+ public ApiResponse<Map<String, Object>> getTorrentInfo(@PathVariable Long torrentId){
+ if (torrentId == null) {
+ return ApiResponse.error(400, "种子ID不能为空");
+ }
+ Torrent torrent = torrentService.findByTorrentId(torrentId);
+ if (torrent == null) {
+ return ApiResponse.error(404, "种子不存在");
+ }
+ Map<String, Object> response = new HashMap<>();
+ response.put("torrentName", torrent.getTorrentName());
+ response.put("fileSize", torrent.getFileSize());
+ return ApiResponse.success(response);
+ }
+
// 处理种子文件上传
@PostMapping("/upload")
- public ApiResponse<Map> handleTorrentUpload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
+ public ApiResponse<Map<String, Long>> handleTorrentUpload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
long userId = (long) authentication.getPrincipal();