解决user冲突,种子封面显示

Change-Id: Ib2de8038d08c57b2681f04a5fd2cb72aed2e953a
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 66660f7..4620775 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,10 +5,9 @@
   </component>
   <component name="ChangeListManager">
     <list default="true" id="f008fe30-0711-42e2-bb33-17dcfdbad387" name="Changes" comment="pom">
-      <change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/echo-backend.iml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/config/WebConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/config/WebConfig.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/controller/TorrentController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/controller/TorrentController.java" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -45,36 +44,36 @@
     <option name="hideEmptyMiddlePackages" value="true" />
     <option name="showLibraryContents" value="true" />
   </component>
-  <component name="PropertiesComponent"><![CDATA[{
-  "keyToString": {
-    "JUnit.UserControllerTest.executor": "Run",
-    "JUnit.UserControllerTest.testUpdateUserAvatar.executor": "Run",
-    "JUnit.UserControllerTest.testUploadUserAvatar.executor": "Run",
-    "RequestMappingsPanelOrder0": "0",
-    "RequestMappingsPanelOrder1": "1",
-    "RequestMappingsPanelWidth0": "75",
-    "RequestMappingsPanelWidth1": "75",
-    "RunOnceActivity.OpenProjectViewOnStart": "true",
-    "RunOnceActivity.ShowReadmeOnStart": "true",
-    "RunOnceActivity.git.unshallow": "true",
-    "Spring Boot.MyProjectApplication.executor": "Run",
-    "git-widget-placeholder": "my-branch",
-    "kotlin-language-version-configured": "true",
-    "last_opened_file_path": "D:/study/学习资源/大三下/school/pt2/echo-backend",
-    "node.js.detected.package.eslint": "true",
-    "node.js.selected.package.eslint": "(autodetect)",
-    "node.js.selected.package.tslint": "(autodetect)",
-    "nodejs_package_manager_path": "npm",
-    "settings.editor.selected.configurable": "project.propVCSSupport.DirectoryMappings",
-    "vue.rearranger.settings.migration": "true",
-    "应用程序.MyProjectApplication.executor": "Run"
+  <component name="PropertiesComponent">{
+  &quot;keyToString&quot;: {
+    &quot;JUnit.UserControllerTest.executor&quot;: &quot;Run&quot;,
+    &quot;JUnit.UserControllerTest.testUpdateUserAvatar.executor&quot;: &quot;Run&quot;,
+    &quot;JUnit.UserControllerTest.testUploadUserAvatar.executor&quot;: &quot;Run&quot;,
+    &quot;RequestMappingsPanelOrder0&quot;: &quot;0&quot;,
+    &quot;RequestMappingsPanelOrder1&quot;: &quot;1&quot;,
+    &quot;RequestMappingsPanelWidth0&quot;: &quot;75&quot;,
+    &quot;RequestMappingsPanelWidth1&quot;: &quot;75&quot;,
+    &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
+    &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
+    &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
+    &quot;Spring Boot.MyProjectApplication.executor&quot;: &quot;Run&quot;,
+    &quot;git-widget-placeholder&quot;: &quot;my-branch&quot;,
+    &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
+    &quot;last_opened_file_path&quot;: &quot;D:/study/学习资源/大三下/school/pt2/echo-backend&quot;,
+    &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
+    &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
+    &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
+    &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
+    &quot;settings.editor.selected.configurable&quot;: &quot;project.propVCSSupport.DirectoryMappings&quot;,
+    &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;,
+    &quot;应用程序.MyProjectApplication.executor&quot;: &quot;Run&quot;
   },
-  "keyToStringList": {
-    "DatabaseDriversLRU": [
-      "mysql_aurora"
+  &quot;keyToStringList&quot;: {
+    &quot;DatabaseDriversLRU&quot;: [
+      &quot;mysql_aurora&quot;
     ]
   }
-}]]></component>
+}</component>
   <component name="RecentsManager">
     <key name="CopyFile.RECENT_KEYS">
       <recent name="D:\PT\echo-backend\src\main\java\com\example\myproject\config" />
@@ -85,7 +84,7 @@
       <recent name="D:\study\学习资源\大三下\school\echo-backend\src\main\resources\mapper" />
     </key>
   </component>
-  <component name="RunManager" selected="JUnit.TorrentControllerTest">
+  <component name="RunManager" selected="应用程序.MyProjectApplication">
     <configuration name="MyProjectApplication" type="Application" factoryName="Application" temporary="true">
       <option name="MAIN_CLASS_NAME" value="com.example.myproject.MyProjectApplication" />
       <module name="echo-backend" />
@@ -183,10 +182,10 @@
     </configuration>
     <recent_temporary>
       <list>
+        <item itemvalue="应用程序.MyProjectApplication" />
         <item itemvalue="JUnit.UserControllerTest.testUploadUserAvatar" />
         <item itemvalue="JUnit.UserControllerTest.testUpdateUserAvatar" />
         <item itemvalue="JUnit.UserControllerTest" />
-        <item itemvalue="应用程序.MyProjectApplication" />
         <item itemvalue="JUnit.TorrentControllerTest" />
       </list>
     </recent_temporary>
diff --git a/data/files/20250525_204009.mp4.part b/data/files/20250525_204009.mp4.part
new file mode 100644
index 0000000..a41aa2f
--- /dev/null
+++ b/data/files/20250525_204009.mp4.part
Binary files differ
diff --git a/data/files/20250525_204009.mp4.torrent b/data/files/20250525_204009.mp4.torrent
new file mode 100644
index 0000000..c1417ff
--- /dev/null
+++ b/data/files/20250525_204009.mp4.torrent
Binary files differ
diff --git a/data/torrents/a81d902452f8cd95a75bfdddcc86213423394bb7.torrent b/data/torrents/a81d902452f8cd95a75bfdddcc86213423394bb7.torrent
new file mode 100644
index 0000000..c1417ff
--- /dev/null
+++ b/data/torrents/a81d902452f8cd95a75bfdddcc86213423394bb7.torrent
Binary files differ
diff --git a/src/main/java/com/example/myproject/config/WebConfig.java b/src/main/java/com/example/myproject/config/WebConfig.java
index 5564452..6f9322d 100644
--- a/src/main/java/com/example/myproject/config/WebConfig.java
+++ b/src/main/java/com/example/myproject/config/WebConfig.java
@@ -11,5 +11,7 @@
         // 访问 /uploads/** 映射到本地 D:/Desktop/echo/echo-backend/uploads/
         registry.addResourceHandler("/uploads/**")
                 .addResourceLocations("file:D:/PT/echo-backend/uploads/");
+        registry.addResourceHandler("/torrent-images/**")
+                .addResourceLocations("file:./uploads/torrents/");
     }
 }
diff --git a/src/main/java/com/example/myproject/controller/TorrentController.java b/src/main/java/com/example/myproject/controller/TorrentController.java
index cea2ccf..74cb8f9 100644
--- a/src/main/java/com/example/myproject/controller/TorrentController.java
+++ b/src/main/java/com/example/myproject/controller/TorrentController.java
@@ -27,6 +27,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
@@ -86,7 +87,10 @@
     @PostMapping("/upload")
     public Result uploadTorrent(
             @RequestParam("file") MultipartFile file,
-            @ModelAttribute @Validated TorrentUploadParam param) throws IOException {
+            @RequestParam("coverImage") MultipartFile coverImage,
+            @ModelAttribute @Validated TorrentUploadParam param,
+            HttpServletRequest request
+            ) throws IOException {
         try {
             // 验证用户权限
             // Long userId = StpUtil.getLoginIdAsLong();
@@ -101,6 +105,31 @@
             if (!file.getOriginalFilename().toLowerCase().endsWith(".torrent")) {
                 return Result.error("只支持.torrent文件");
             }
+            if (!coverImage.isEmpty()) {
+                String originalFilename = coverImage.getOriginalFilename();
+                String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
+                String fileName = System.currentTimeMillis() + suffix;
+
+                if (!originalFilename.toLowerCase().matches(".*\\.(jpg|jpeg|png)$")) {
+                    return Result.error("仅支持 JPG/PNG 格式的封面图片");
+                }
+
+
+                // 项目根目录下的 /uploads/torrents/
+                String uploadDir = System.getProperty("user.dir") + "/uploads/torrents/";
+                File dir = new File(uploadDir);
+                if (!dir.exists()) dir.mkdirs(); // 自动创建目录
+
+                File dest = new File(uploadDir + fileName);
+                coverImage.transferTo(dest);
+
+
+                String imageUrl = request.getScheme() + "://" + request.getServerName() + ":" +
+                        request.getServerPort() + "/torrent-images/" + fileName;
+
+
+                param.setImageUrl(imageUrl);
+            }
 
             torrentService.uploadTorrent(file, param);
             return Result.ok();
diff --git a/target/classes/application.properties b/target/classes/application.properties
index 9612287..6678bb5 100644
--- a/target/classes/application.properties
+++ b/target/classes/application.properties
@@ -6,6 +6,7 @@
 spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
 
 mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
+mybatis-plus.mapper-locations=classpath:/mapper/**/*.xml
 
 # Mail configuration
 spring.mail.password=tljnebonhzhqecda
@@ -20,10 +21,6 @@
 spring.jpa.open-in-view=false
 
 pt.tracker.port=6969
-
 pt.tracker.torrent-dir=${user.dir}/data/torrents
-
 pt.tracker.allow-foreign=false
-pt.tracker.announce-url=/custom-announce
-
-mybatis-plus.mapper-locations=classpath:/mapper/**/*.xml
\ No newline at end of file
+pt.tracker.announce-url=http://localhost:6969/announce
diff --git a/target/classes/com/example/myproject/config/WebConfig.class b/target/classes/com/example/myproject/config/WebConfig.class
index 7e6fb72..4c40a79 100644
--- a/target/classes/com/example/myproject/config/WebConfig.class
+++ b/target/classes/com/example/myproject/config/WebConfig.class
Binary files differ
diff --git a/target/classes/com/example/myproject/controller/TorrentController.class b/target/classes/com/example/myproject/controller/TorrentController.class
index 130ba3f..dc007a8 100644
--- a/target/classes/com/example/myproject/controller/TorrentController.class
+++ b/target/classes/com/example/myproject/controller/TorrentController.class
Binary files differ
diff --git a/uploads/torrents/1749131044219.jpg b/uploads/torrents/1749131044219.jpg
new file mode 100644
index 0000000..4ba04de
--- /dev/null
+++ b/uploads/torrents/1749131044219.jpg
Binary files differ