Selaa lähdekoodia

update file-service

reghao 1 kuukausi sitten
vanhempi
commit
150bfb5720

+ 5 - 0
file/file-service/pom.xml

@@ -77,6 +77,11 @@
             <artifactId>javase</artifactId>
             <version>3.1.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tika</groupId>
+            <artifactId>tika-core</artifactId>
+            <version>2.9.1</version>
+        </dependency>
 
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 1 - 1
file/file-service/src/main/java/cn/reghao/tnb/file/app/controller/FileOssController.java

@@ -7,7 +7,7 @@ import cn.reghao.oss.api.dto.rest.UploadSample;
 import cn.reghao.tnb.common.web.WebResult;
 import cn.reghao.oss.api.dto.ServerInfo;
 import cn.reghao.tnb.common.auth.AuthUser;
-import cn.reghao.tnb.file.app.model.constant.UploadChannelType;
+import cn.reghao.oss.api.constant.UploadChannelType;
 import cn.reghao.tnb.file.app.service.OssUploadService;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.Operation;

+ 1 - 1
file/file-service/src/main/java/cn/reghao/tnb/file/app/controller/OpenFileController.java

@@ -7,7 +7,7 @@ import cn.reghao.oss.api.dto.rest.UploadPrepareRet;
 import cn.reghao.oss.api.dto.rest.UploadSample;
 import cn.reghao.tnb.common.auth.AuthUser;
 import cn.reghao.tnb.common.web.WebResult;
-import cn.reghao.tnb.file.app.model.constant.UploadChannelType;
+import cn.reghao.oss.api.constant.UploadChannelType;
 import cn.reghao.tnb.file.app.service.OssUploadService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;

+ 0 - 50
file/file-service/src/main/java/cn/reghao/tnb/file/app/model/constant/UploadChannelType.java

@@ -1,50 +0,0 @@
-package cn.reghao.tnb.file.app.model.constant;
-
-import cn.reghao.oss.api.constant.ObjectSize;
-import cn.reghao.oss.api.constant.ObjectScope;
-import cn.reghao.oss.api.constant.ObjectType;
-
-/**
- * @author reghao
- * @date 2025-10-19 17:24:54
- */
-public enum UploadChannelType {
-    videoChannel(101, "video/playback/", ObjectType.Video.getCode(), ObjectSize.mb10.getSize(), ObjectScope.PUBLIC.getCode()),
-    imageChannel(102, "image/i/", ObjectType.Image.getCode(), ObjectSize.mb100.getSize(), ObjectScope.PUBLIC.getCode()),
-    photoChannel(103, "image/p/", ObjectType.Image.getCode(), ObjectSize.gb10.getSize(), ObjectScope.PUBLIC.getCode()),
-    fileChannel(104, "file/", ObjectType.Any.getCode(), ObjectSize.gb10.getSize(), ObjectScope.PRIVATE.getCode()),
-    camChannel(105, "video/cam/", ObjectType.Video.getCode(), ObjectSize.gb10.getSize(), ObjectScope.PRIVATE.getCode());
-
-    private final int channelCode;
-    private final String channelPrefix;
-    private final int fileType;
-    private final long maxSize;
-    private final int scope;
-    UploadChannelType(int channelCode, String channelPrefix, int fileType, long maxSize, int scope) {
-        this.channelCode = channelCode;
-        this.channelPrefix = channelPrefix;
-        this.fileType = fileType;
-        this.maxSize = maxSize;
-        this.scope = scope;
-    }
-
-    public int getChannelCode() {
-        return channelCode;
-    }
-
-    public String getChannelPrefix() {
-        return channelPrefix;
-    }
-
-    public int getFileType() {
-        return fileType;
-    }
-
-    public long getMaxSize() {
-        return maxSize;
-    }
-
-    public int getScope() {
-        return scope;
-    }
-}

+ 23 - 34
file/file-service/src/test/java/DiskUnitTest.java

@@ -4,7 +4,9 @@ import cn.reghao.oss.api.dto.ServerInfo;
 import cn.reghao.oss.sdk.OssClient;
 import cn.reghao.tnb.file.app.zdisk.model.vo.FileTree;
 import cn.reghao.oss.api.constant.ObjectType;
+import lombok.extern.slf4j.Slf4j;
 import net.sourceforge.tess4j.Tesseract;
+import org.apache.tika.Tika;
 import org.junit.jupiter.api.Test;
 import org.mockito.junit.MockitoJUnitRunner;
 
@@ -18,57 +20,44 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.stream.Collectors;
 
+@Slf4j
 public class DiskUnitTest {
     void walkDir(Path path) throws IOException {
-        Files.walkFileTree(path, new FileVisitor<Path>() {
-            @Override
-            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
-                File dir1 = dir.toFile();
-                process(dir1);
-                return FileVisitResult.CONTINUE;
-            }
-
+        Files.walkFileTree(path, new SimpleFileVisitor<>() {
             @Override
             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                 File file1 = file.toFile();
                 process(file1);
                 return FileVisitResult.CONTINUE;
             }
-
-            @Override
-            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
         });
     }
 
-    List<FileTree> fileTreeList = new ArrayList<>();
     private void process(File file) {
-        String basePath = dir.getAbsolutePath();
-        String absolutePath = file.getAbsolutePath();
-        String path = absolutePath.replace(basePath, "");
-        String pid = file.getParent().replace(basePath, "");
-        if (path.equals("")) {
-            pid = "0";
-        } else if (pid.equals("")) {
-            pid = "/";
-        }
+        String contentType = getContentType(file);
+        log.info("{} -> {}", contentType, file.getName());
+    }
 
-        int fileType = ObjectType.Image.getCode();
-        if (file.isDirectory()) {
-            fileType = ObjectType.Folder.getCode();
+    Tika tika = new Tika();
+    private String getContentType(File file) {
+        try {
+            // Tika 会根据文件头字节进行深度探测
+            return tika.detect(file);
+        } catch (IOException e) {
+            log.error("Tika 探测文件类型失败: {}", file.getAbsolutePath(), e);
+            return "application/octet-stream";
         }
+    }
 
-        String fileId = absolutePath.replace(basePath, "");
-        FileTree fileTree = new FileTree(pid, fileId, fileType);
-        fileTreeList.add(fileTree);
+    @Test
+    public void fileWalk() throws IOException {
+        String baseDir = "/disk/2/porn/bt";
+        Path path = Paths.get(baseDir);
+        walkDir(path);
+        System.out.println();
     }
 
+    List<FileTree> fileTreeList = new ArrayList<>();
     String baseDir = "/home/reghao/Downloads/";
     File dir = new File(baseDir);
 

+ 12 - 8
file/file-service/src/test/java/FileTest.java

@@ -27,8 +27,8 @@ import java.util.List;
  * @date 2024-04-17 07:18:59
  */
 @Slf4j
-@ActiveProfiles("dev")
-@SpringBootTest(classes = FileApplication.class)
+//@ActiveProfiles("dev")
+//@SpringBootTest(classes = FileApplication.class)
 public class FileTest {
     void walkDir(Path path) throws IOException {
         Files.walkFileTree(path, new FileVisitor<Path>() {
@@ -59,19 +59,23 @@ public class FileTest {
     List<CamPhoto> camPhotoList = new ArrayList<>();
     private void process(File file) {
         CamPhoto camPhoto = PhotoExif.getCamPhoto(file.getAbsolutePath());
-        if (camPhoto != null && camPhoto.getLatitude() != null) {
+        /*if (camPhoto != null && camPhoto.getLatitude() != null) {
+            camPhotoList.add(camPhoto);
+        }*/
+
+        if (camPhoto != null && camPhoto.getShotAt() != null) {
             camPhotoList.add(camPhoto);
         }
     }
 
-    String baseDir = "/home/reghao/data/vdisk/320g/photo/";
     String kmlFile = "/home/reghao/Downloads/my_places.kml";
-    @Autowired
-    EarthService earthService;
+    //@Autowired
+    //EarthService earthService;
     @Test
     public void photoTest() throws Exception {
+        String baseDir = "/media/veracrypt1/pv/2";
         walkDir(Path.of(baseDir));
-        earthService.getEarthKml(kmlFile, camPhotoList);
+        //earthService.getEarthKml(kmlFile, camPhotoList);
         System.out.println();
     }
 
@@ -84,7 +88,7 @@ public class FileTest {
                 System.out.println(line);
             }
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("{}", e.getMessage());
         }
     }