Kaynağa Gözat

Merge remote-tracking branch 'origin/next' into windows11

john 1 yıl önce
ebeveyn
işleme
5903624017

+ 2 - 1
package.json

@@ -20,7 +20,8 @@
     "react": "^18.3.1",
     "react-dom": "^18.3.1",
     "react-router": "^6.23.1",
-    "react-router-dom": "^6.23.1"
+    "react-router-dom": "^6.23.1",
+    "tauri-plugin-sql-api": "https://github.com/tauri-apps/tauri-plugin-sql#v1"
   },
   "devDependencies": {
     "@rollup/plugin-alias": "^5.1.0",

Dosya farkı çok büyük olduğundan ihmal edildi
+ 517 - 122
src-tauri/Cargo.lock


+ 25 - 24
src-tauri/Cargo.toml

@@ -1,47 +1,48 @@
 [package]
 name = "tauri-app"
 version = "0.0.1"
-description = "A Tauri App"
-authors = ["you"]
+description = "A System Tools Tauri App"
+authors = ["Johnhong9527"]
 license = ""
-repository = ""
+repository = "https://github.com/Johnhong9527/tauri-app.git"
 edition = "2021"
-rust-version = "1.57"
+rust-version = "1.78.0"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 # https://docs.rs/tensorflow/0.19.1/tensorflow/
 
 [build-dependencies]
-tauri-build = {version = "1.2", features = [] }
+tauri-build = {version = "1.5.2", features = [] }
 
 [dependencies]
-serde_json = "1.0"
+serde_json = "1.0.117"
 rusqlite = {version = "0.29.0", features = ["bundled"] }
-thiserror = "1.0"
+thiserror = "1.0.61"
 serde = { version = "1.0", features = ["derive"] }
-tauri = {version = "1.2", features = ["api-all"] }
-#tensorflow = { version = "0.19.1" }
-#tensorflow-sys = { version = "0.22.1", features = ["tensorflow_gpu"] }
-#tensorflow = { version = "0.19.1", features = ["tensorflow_gpu"] }
-#tensorflow-sys = "0.22.1"
-uuid = "1.2.2"
-regex = "1.7.0"
-crypto = "0.4.0"
-ring = "0.16.20"
-data-encoding = "2.3.3"
-sha2 = "0.10"
-digest = "0.10.6"
+tauri = {version = "1.5.2", features = ["api-all"] }
+uuid = "1.8.0"
+regex = "1.10.4"
+crypto = "0.5.1"
+ring = "0.17.8"
+data-encoding = "2.6.0"
+sha2 = "0.10.8"
+digest = "0.10.7"
 hex = "0.4.3"
 file_diff = "1.0.0"
 strsim = "0.10.0"
 diff = "0.1"
 anyhow = "1"
-async-trait = "0.1.68"
-tracing = "0.1.15"
-tracing-subscriber = { version = "0.3", features = ["fmt"] }
-lazy_static = "1.4"
-home = "0.5.4"
+async-trait = "0.1.80"
+tracing = "0.1.40"
+tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
+lazy_static = "1.4.0"
+home = "0.5.9"
+
+[dependencies.tauri-plugin-sql]
+git = "https://github.com/tauri-apps/plugins-workspace"
+branch = "v1"
+features = ["sqlite"] # or "postgres", or "mysql"
 
 [workspace]
 #members = ["modules"]

+ 0 - 1
src-tauri/src/common/sqlite/migration/mod.rs

@@ -1,5 +1,4 @@
 mod database_version;
 
-pub use database_version::*;
 
 

+ 2 - 3
src-tauri/src/common/sqlite/rusqlite_utils.rs

@@ -5,11 +5,10 @@ use rusqlite::{
     types::ValueRef::{Blob, Integer, Null, Real, Text}, // SQLite 值引用类型
     Connection,
     Params,
-    Row,
-    ToSql, // 引入 SQLite 连接、参数、行和 ToSql 类型
+    Row, // 引入 SQLite 连接、参数、行和 ToSql 类型
 };
 use serde_json::{Number, Value}; // 引入 JSON 处理库
-use std::{collections::HashMap, sync::Mutex}; // 引入 HashMap 和 Mutex
+use std::{collections::HashMap}; // 引入 HashMap 和 Mutex
 
 // 查询单个值
 pub fn query_one_value<P, V>(connection: &Connection, sql: &str, p: P) -> Result<V>

+ 9 - 10
src-tauri/src/event_loop.rs

@@ -77,7 +77,6 @@ pub fn file_path(name: &str, parentid: &str) -> String {
 
 use sha2::{Digest, Sha256};
 use std::{fs, io};
-use tauri::api::http::FormPart::File;
 
 #[derive(Debug)]
 struct UseHashInfoStruct {
@@ -108,7 +107,7 @@ fn get_file_hase(path: &str) -> UseHashInfoStruct {
 
 fn read_file(path: &str) -> io::Result<Vec<u8>> {
     use std::fs::File;
-    use std::io::{self, Read};
+    use std::io::{Read};
     let mut file = File::open(path)?;
     let mut bytes = Vec::new();
     file.read_to_end(&mut bytes)?;
@@ -119,7 +118,7 @@ fn read_file(path: &str) -> io::Result<Vec<u8>> {
 
 fn create_file(path: &str, buf: &str) -> io::Result<()> {
     use std::fs::File;
-    use std::io::{self, Write};
+    use std::io::{Write};
     let mut file = File::create(path)?;
     // let file_byts = read_file("/Users/sysadmin/Downloads/文件相似度对比_new.pdf")?;
     file.write_all(buf.as_bytes())?;
@@ -138,11 +137,11 @@ fn jaccard(str1: &str, str2: &str) -> f64 {
 #[tauri::command(name = "file_sort")]
 // pub fn file_sort(path: &str) -> String {
 pub fn file_sort(path: &str)  {
-    use file_diff::{diff_files};
-    use std::io;
-    use std::io::prelude::*;
-    use std::fs::File;
-    use strsim::damerau_levenshtein;
+    
+    
+    
+    
+    
 
     // use strsim::{jaccard};
     let hash_info = get_file_hase(&path);
@@ -158,11 +157,11 @@ pub fn file_sort(path: &str)  {
     // let n1 = f1.read(&mut buffer[..]).unwrap();
     // let n2 = f2.read(&mut buffer[..]).unwrap();
     let bytes = read_file("/Users/sysadmin/Downloads/文件相似度对比_old.pdf").unwrap();
-    let mut bytes_str = format!("{:?}", bytes);
+    let bytes_str = format!("{:?}", bytes);
     // create_file("/Users/sysadmin/Downloads/文件相似度对比_old.md", &bytes_str);
     // let bytes2 = read_file("/Users/sysadmin/Downloads/文件相似度对比_new.pdf").unwrap();
     let bytes2 = read_file("/Users/sysadmin/Downloads/截屏2022-11-30 上午10.00.17 2.png").unwrap();
-    let mut  bytes2_str = format!("{:?}", bytes2);
+    let bytes2_str = format!("{:?}", bytes2);
     // create_file("/Users/sysadmin/Downloads/文件相似度对比_new.md", &bytes2_str);
 
 

+ 59 - 0
src-tauri/src/main.rs

@@ -16,16 +16,75 @@ use self_plugin::tauri_plugin_sqlite;
 use self_plugin::tauri_plugin_file;
 
 
+use tauri::{Manager, generate_context};
+// use tauri_plugin_sql::{Builder as SqlBuilder, TauriSql};
+use tauri::api::path::app_data_dir;
+
+use tauri_plugin_sql::{Migration, MigrationKind};
+
 fn main() {
+    let migrations = vec![
+        // Define your migrations here
+        Migration {
+            version: 1,
+            description: "create_initial_tables",
+            sql: "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);",
+            kind: MigrationKind::Up,
+        },
+        Migration {
+            version: 2,
+            description: "create_initial_tables",
+            sql: "ALTER TABLE 'users' ADD 'addType' TEXT;ALTER TABLE 'users' ADD 'userTime' TEXT;",
+            kind: MigrationKind::Up,
+        }
+        // Migration {
+        //     version: 3,
+        //     description: "create_initial_tables",
+        //     sql: "ALTER TABLE users DROP COLUMN userTime;",
+        //     kind: MigrationKind::Up,
+        // },
+        // Migration {
+        //     version: 4,
+        //     description: "create_initial_tables",
+        //     sql: "ALTER TABLE 'users' ADD 'addType' TEXT;",
+        //     kind: MigrationKind::Up,
+        // },
+        // Migration {
+        //     version: 5,
+        //     description: "create_initial_tables",
+        //     sql: "ALTER TABLE 'users' ADD 'addType2' TEXT;",
+        //     kind: MigrationKind::Up,
+        // }
+    ];
     tauri::Builder::default()
         .plugin(tauri_plugin_sqlite::init())
         .plugin(tauri_plugin_file::init())
+        .plugin(
+            tauri_plugin_sql::Builder::default()
+            .add_migrations("sqlite:test.db", migrations)
+        .build()
+    )
+
         .menu(use_memu())
         .on_menu_event(|event| {
             // 处理菜单事件
             m_event(event);
         })
         .invoke_handler(tauri::generate_handler![greet, file_path, file_sort])
+        .setup(|app| {
+            let app_handle = app.handle();
+            let app_dir = app_data_dir(&app_handle.config());
+
+            // 打印应用程序目录路径
+            println!("打印应用程序目录路径App directory: {:?}", app_dir);
+
+
+            // // 设定数据库文件路径
+            // let db_path = app_dir.join("test.db");
+            // println!("Database file path: {:?}", db_path);
+
+            Ok(())
+        })
         .run(tauri::generate_context!())
         .expect("error while running tauri application");
 }

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

@@ -1,4 +1,3 @@
-use std::collections::HashSet;
 use std::fs;
 // use crypto::digest::Digest;
 // use crypto::sha2::Sha256;

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

@@ -1,8 +1,7 @@
 pub(crate) mod files;
 
 use tauri::{
-    plugin::{Builder, TauriPlugin},
-    Manager, Runtime,
+    plugin::{Builder, TauriPlugin}, Runtime,
 };
 
 use self::files::*;

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

@@ -2,8 +2,7 @@ pub(crate) mod sqlite;
 //  as tauri_plugin_sqlite;
 
 use tauri::{
-    plugin::{Builder, TauriPlugin},
-    Manager, Runtime,
+    plugin::{Builder, TauriPlugin}, Runtime,
 };
 
 use self::sqlite::*;

+ 33 - 7
src/pages/DuplicateFile/DuplicateFile.tsx

@@ -10,6 +10,7 @@ import {
   Input,
   Progress,
   Pagination,
+  PaginationProps,
 } from "antd";
 import { useEffect, useState } from "react";
 const { Option } = Select;
@@ -22,10 +23,16 @@ import { get_all_history, get_info_by_path, insertSeletedFileHistory } from "@/s
 import dayjs from "dayjs";
 import { DEFAULT_TIME_FORMAT } from "@/config";
 
+import Database from "tauri-plugin-sql-api";
+import { createSql } from "@/databases/createTableSql";
+const db = await Database.load("sqlite:test.db");
+
 const { Search } = Input;
 const { TextArea } = Input;
 
 export default function DuplicateFile() {
+  const [total, setTotal] = useState(20); // 页数
+  const [current, setCurrent] = useState(1); // 页码
   const [usePath, setUsePath] = useState<string>();
   const [historyList, setHistoryList] = useState<historyListType[]>([]);
   const [fileList, setFileList] = useState<insertSearchFilesPasamsType[]>([
@@ -52,6 +59,8 @@ export default function DuplicateFile() {
   const [fileInfo, setFileInfo] = useState<any>({});
   const [fileInfoSource, setFileInfoSource] = useState<FileInfoType>({});
 
+
+
   const columns = [
     {
       title: "ID",
@@ -136,7 +145,8 @@ export default function DuplicateFile() {
   }
 
   async function openModal(info?: FileInfoType) {
-    setIsModalOpen(true);
+    initDB()
+    // setIsModalOpen(true);
     // const res = await insertSeletedFileHistory('/Users/sysadmin/Downloads');
     // console.log(133, res);
     // const res = await get_info_by_path('/Users/sysadmin/Downloads')
@@ -148,8 +158,8 @@ export default function DuplicateFile() {
       checkedSizeValues: ["巨大(4GB+)", "大(128MB ~ 1GB-)"],
       addType: "2131231231231"
     }); */
-    /* 
-    
+    /*
+
     {path: "/Users/sysadmin/Downloads", checkedTypeValues: ["音频", "图片"], checkedSizeValues: ["巨大(4GB+)", "大(128MB ~ 1GB-)"]}
 
 
@@ -171,17 +181,33 @@ Object Prototype
   }
 
   async function getFileList() {
-    const list = await get_all_history();
-    console.log(173, list);
-    const newFileList = list.map(item => {
+    const {data, total: localeTotal} = await get_all_history(current, total);
+    console.log(173, data);
+    const newFileList = data.map(item => {
       return {
         ...item,
         time: dayjs(item.time).format(DEFAULT_TIME_FORMAT)
       }
     })
     setFileList(newFileList)
+    setTotal(localeTotal)
+  }
+
+
+  async function initDB() {
+    try {
+      const result = await db.execute(createSql.search_files);
+      console.log(179, result);
+    } catch (error) {
+      console.log(182, error);
+    }
   }
 
+  const onPaginationChange: PaginationProps['onChange'] = (page) => {
+    console.log(page);
+    setCurrent(page);
+  };
+  
   return (
     <div className={styles.DuplicateFileBox}>
       <FileInfoEditer
@@ -219,7 +245,7 @@ Object Prototype
         />
       </Row>
       <Row justify="end" style={{ width: "100%", marginTop: "12px" }}>
-        <Pagination defaultCurrent={1} total={50} />
+        <Pagination current={current} total={total} onChange={onPaginationChange} />
       </Row>
     </div>
   );

+ 8 - 6
src/services/file-service.ts

@@ -60,7 +60,7 @@ export async function get_info_by_path(path: string):Promise<[FileInfoType|boole
     );
     
     if(res.length) {
-      return [res[0], ""];  
+      return [res[0], ""];
     }
     return [false, "暂无数据"];
   } catch (err) {
@@ -113,14 +113,16 @@ export async function get_info_by_path(path: string):Promise<[FileInfoType|boole
  *          - data: FileInfoType[] - 当前页的记录数据数组。
  *          - total: number - 表中的总记录数,用于前端计算总页数。
  */
-export async function get_all_history(page: number, pageSize: number): Promise<{ data: insertSearchFilesPasamsType[], total: number }> {
+export async function get_all_history(page?: number, pageSize?: number): Promise<{
+  [x: string]: any; data: insertSearchFilesPasamsType[], total: number 
+}> {
   await table_init(FILE_DB_PATH, "select_history");
   const DB = await SQLite.open(FILE_DB_PATH);
   // 查询总记录数
   const totalResult = await DB.queryWithArgs<Array<{ total: number }>>("SELECT COUNT(*) AS total FROM select_history");
   const total = totalResult[0].total;  // 获取总记录数
   // 计算分页偏移量
-  const offset = (page - 1) * pageSize;
+  const offset = (page || 1 - 1) * (pageSize || 10);
 
   // 获取当前页的数据
   const data = await DB.queryWithArgs<Array<insertSearchFilesPasamsType>>(
@@ -141,15 +143,15 @@ export async function get_list_by_sourceid(sourceId: number):Promise<[insertSear
       { ":sourceId": sourceId }
     );
     console.log(969696, sourceId);
-    
+
     /* const res = await DB.queryWithArgs<Array<insertSearchFilesPasamsType>>(
       "SELECT * FROM search_files WHERE sourceId = :sourceId GROUP BY hash HAVING COUNT(*) > 1",
       { ":sourceId": sourceid }
     ); */
     console.log(3434, res);
-    
+
     if(res.length) {
-      return [res, ""];  
+      return [res, ""];
     }
     return [false, "暂无数据"];
   } catch (err) {

+ 7 - 1
yarn.lock

@@ -593,7 +593,7 @@
   resolved "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.18.0.tgz#5d694d345ce36b6ecf657349e03eb87297e68da4"
   integrity sha512-UOo5FdvOL0+eIVTgS4tIdbW+TtnBLWg1YBCcU2KWM7nuNwRz9bksDX1bekJJCpu25N1DVWaCwnT39dVQxzqS8g==
 
-"@tauri-apps/api@^1.5.6":
+"@tauri-apps/api@1.5.6", "@tauri-apps/api@^1.5.6":
   version "1.5.6"
   resolved "https://registry.npmjs.org/@tauri-apps/api/-/api-1.5.6.tgz#7496d79f6586659a59bc6e9d6666eed8d24dc6da"
   integrity sha512-LH5ToovAHnDVe5Qa9f/+jW28I6DeMhos8bNDtBOmmnaDpPmJmYLyHdeDblAWWWYc7KKRDg9/66vMuKyq0WIeFA==
@@ -1606,6 +1606,12 @@ supports-color@^5.3.0:
   dependencies:
     has-flag "^3.0.0"
 
+"tauri-plugin-sql-api@https://github.com/tauri-apps/tauri-plugin-sql#v1":
+  version "0.0.0"
+  resolved "https://github.com/tauri-apps/tauri-plugin-sql#6a4a14c36b1ad49c9f468351706d104a54e0540c"
+  dependencies:
+    "@tauri-apps/api" "1.5.6"
+
 throttle-debounce@^5.0.0:
   version "5.0.0"
   resolved "https://registry.npmjs.org/throttle-debounce/-/throttle-debounce-5.0.0.tgz#a17a4039e82a2ed38a5e7268e4132d6960d41933"

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor