修改Tracker服务器相关bug

Change-Id: Id3ec61034575bd794724be98f832f8c065448b92
diff --git a/src/main/java/com/pt/service/ResourceService.java b/src/main/java/com/pt/service/ResourceService.java
index 7d68817..4eb7823 100644
--- a/src/main/java/com/pt/service/ResourceService.java
+++ b/src/main/java/com/pt/service/ResourceService.java
@@ -6,11 +6,14 @@
 import com.pt.repository.DownloadRepository;
 import com.pt.repository.ResourceRepository;
 import com.pt.repository.TorrentMetaRepository;
+import com.pt.service.TrackerService; // 新增导入
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class ResourceService {
@@ -27,6 +30,9 @@
     @Autowired
     private TorrentMetaRepository torrentMetaRepository;
 
+    @Autowired
+    private TrackerService trackerService; // 新增注入
+
     public List<Resource> getAllResources() {
         return resourceRepository.findAll();
     }
@@ -35,7 +41,7 @@
         return resourceRepository.findByAuthor(username);
     }
 
-    public void publishResource(String name, String description, String author, double size, byte[] torrentBytes) throws Exception {
+    public void publishResource(String name, String description, String author, byte[] torrentBytes, String username) throws Exception {
         // 解析并保存torrent元信息
         TorrentMeta meta = torrentService.parseAndSaveTorrent(torrentBytes);
 
@@ -44,13 +50,19 @@
         resource.setName(name);
         resource.setDescription(description);
         resource.setAuthor(author);
-        resource.setSize(size);
         resource.setPublishTime(LocalDateTime.now());
 
         resource.setTorrentData(torrentBytes);
-        resource.setInfo_hash(meta.getInfoHash());
         // 这里可以保存torrent文件路径,或直接存数据库,依据你的设计
         resourceRepository.save(resource);
+
+        // 在Tracker中注册相关信息
+//        Map<String, String[]> params = new HashMap<>();
+//        params.put("info_hash", new String[]{meta.getInfoHash()});
+//        // 这里peer_id和port可以先使用默认值,实际应用中可以根据需求修改
+//        params.put("peer_id", new String[]{username});
+//        params.put("port", new String[]{"6881"});
+//        trackerService.handleAnnounce(params, ip);
     }
 
     // 获取资源时,返回BLOB字段内容作为torrent文件
@@ -89,4 +101,4 @@
         return resourceRepository.findByNameContainingIgnoreCase(query);
     }
 
-}
+}
\ No newline at end of file