john 1 жил өмнө
parent
commit
f21d92647a

+ 34 - 0
src-tauri/src/self_plugin/tauri_plugin_file/files.rs

@@ -231,3 +231,37 @@ pub fn calculate_file_hash(file_path: String) -> Result<String> {
     let hash = hex::encode(result);
     Ok(hash)
 }
+
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct FileInfos {
+    file_path: PathBuf,
+    file_name: Option<String>,
+    file_type: Option<String>,
+    file_size: u64,
+    modified_time: Option<u64>, // 时间戳形式
+}
+
+#[command]
+pub fn get_file_info(file_path: String) -> Result<FileInfos> {
+    let path = Path::new(&file_path);
+
+    // 正确地处理错误
+    let metadata = fs::metadata(&path)?;
+
+    // 获取文件修改时间
+    let modified_time = metadata.modified().ok()
+        .and_then(|t| t.duration_since(UNIX_EPOCH).ok())
+        .map(|d| d.as_secs());
+
+    // 构造FileInfo结构
+    let file_info = FileInfos {
+        file_path: path.to_path_buf(),
+        file_name: path.file_name().and_then(|name| name.to_str()).map(|name| name.to_string()),
+        file_type: get_file_type(&file_path).map(|t| t.to_string()),
+        file_size: metadata.len(),
+        modified_time,
+    };
+
+    Ok(file_info)
+}

+ 2 - 1
src-tauri/src/self_plugin/tauri_plugin_file/mod.rs

@@ -14,7 +14,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
             get_all_directory,
             get_file_type_by_path,
             calculate_file_hash,
-            get_file_info_by_path,
+            get_file_info
+            // get_file_info_by_path,
         ])
         .setup(|_app| {
             // app.manage(SqliteMap::default());

+ 19 - 5
src/pages/DuplicateFile/CalculateDuplicateFiles.tsx

@@ -22,7 +22,7 @@ import {
 } from "@ant-design/icons";
 import { readDir, BaseDirectory } from "@tauri-apps/api/fs";
 import { fileTypeList } from "./config";
-import get_progress_by_sourceId from "@/services/file-service";
+import get_progress_by_sourceId, { get_list_by_sourceid } from "@/services/file-service";
 
 export default function CalculateDuplicateFiles() {
   let { fileId } = useParams();
@@ -69,9 +69,7 @@ export default function CalculateDuplicateFiles() {
     }
   }
   async function scanDirAll() {
-    const resInfo = await File.getInfo("/Users/sysadmin/Downloads/google-cloud-cli-455.0.0-darwin-arm.tar.gz")
-    console.log(7373, resInfo);
-    return
+ 
     // const aabb = await get_progress_by_sourceId(`${fileId}`);
     // console.log(737373, aabb);
     
@@ -107,6 +105,19 @@ export default function CalculateDuplicateFiles() {
             const type = await File.getType(currentFile);
             // const hash = await File.getHash(currentFile);
             const hash = '';
+            /* 
+              const resInfo = await File.getInfo("/Users/sysadmin/Downloads/google-cloud-cli-455.0.0-darwin-arm.tar.gz")
+              console.log(7373, resInfo);
+              return
+                    Object: {
+                      file_name: "google-cloud-cli-455.0.0-darwin-arm.tar.gz",
+                      file_path: "/Users/sysadmin/Downloads/google-cloud-cli-455.0.0-darwin-arm.tar.gz",
+                      file_size: 119890163,
+                      file_type: "gz",
+                      modified_time: 1701394601,
+                      Object Prototype,
+                    }
+            */
             return insertSearchFiles({
               // 组装数据
               sourceId: `${fileId}`,
@@ -121,7 +132,10 @@ export default function CalculateDuplicateFiles() {
         );
 
         console.log(result); // 顺序处理每个项,然后输出最终结果
-
+        // 计算文件具体内容
+        const allList = await get_list_by_sourceid(`${fileId}`)
+        console.log(137, allList);
+        
 
         // 分析重复文件
         const searchDuplicateFileRes =  await searchDuplicateFile({

+ 1 - 1
src/plugins/tauri-plugin-file/file.ts

@@ -29,7 +29,7 @@ export class File {
   }
   
   static async getInfo(path: string): Promise<any> {
-    return await invoke<string>("plugin:st-files|get_file_info_by_path", {
+    return await invoke<string>("plugin:st-files|get_file_info", {
       filePath: path,
     });
   }

+ 4 - 2
src/services/file-service.ts

@@ -220,12 +220,14 @@ export async function get_all_history(
 }
 
 export async function get_list_by_sourceid(
-  sourceId: number
+  sourceId: string
 ): Promise<[insertSearchFilesPasamsType[] | false, string]> {
   try {
     // await table_init(FILE_DB_PATH, "select_history");
     // const DB = await SQLite.open(FILE_DB_PATH);
-    const DB = await Database.load("sqlite:test.db");
+    const DB = await Database.load(`sqlite:files_${sourceId}.db`);
+    // 创建表
+    await DB.execute(createSql.search_files);
     const res = await DB.execute(
       "SELECT * FROM search_files WHERE sourceId = $1",
       [sourceId]