diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index d351c9c..a529164 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -76,7 +76,4 @@ jobs: if: ${{ runner.os == 'macOS' }} run: cargo build -Z build-std -p ezlog --release --lib --target aarch64-apple-ios - name: Clippy Check - # tauri cant run from cargo - run: | - cargo clippy -p ezlog --all-features -- -D warnings - cargo clippy -p ezlogcli --all-features -- -D warnings \ No newline at end of file + run: cargo clippy --all --all-features -- -D warnings \ No newline at end of file diff --git a/ezlog-core/Cargo.toml b/ezlog-core/Cargo.toml index c2edd83..9b1eef6 100644 --- a/ezlog-core/Cargo.toml +++ b/ezlog-core/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["ezlog"] crate-type = ["lib", "cdylib", "staticlib"] [features] -default = ["json"] +default = [] log = ["dep:log"] json = ["serde", "serde_json", "bitflags/serde"] decode = ["aes-gcm", "regex", "log", "hex"] diff --git a/ui-tauri/src-tauri/Cargo.toml b/ui-tauri/src-tauri/Cargo.toml index a5852e7..5416410 100644 --- a/ui-tauri/src-tauri/Cargo.toml +++ b/ui-tauri/src-tauri/Cargo.toml @@ -16,7 +16,7 @@ tauri-build = { version = "1.5.2", features = [] } tauri = { version = "1.6", features = ["shell-open", "window-center", "window-close", "window-hide", "window-maximize", "window-minimize", "window-print", "window-show", "window-start-dragging"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -ezlog = { version = "0.2.0", path = "../../ezlog-core", features = ["decode"] } +ezlog = { version = "0.2.0", path = "../../ezlog-core", features = ["decode", "json"] } [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/ui-tauri/src-tauri/src/main.rs b/ui-tauri/src-tauri/src/main.rs index 1731e58..61103f4 100644 --- a/ui-tauri/src-tauri/src/main.rs +++ b/ui-tauri/src-tauri/src/main.rs @@ -11,6 +11,7 @@ use std::{ }; use ezlog::EZLogConfigBuilder; +use serde_json::json; fn main() { tauri::Builder::default() @@ -31,25 +32,8 @@ fn parse_header_and_extra(file_path: String) -> Result { let mut cursor = Cursor::new(contents); ezlog::decode::decode_header_and_extra(&mut cursor) .map(|header_and_extra| { - let extra_tuple = header_and_extra.1.unwrap_or_default(); - let json_string = format!( - "{{\"{}\":{},\"{}\":{},\"{}\":{},\"{}\":\"{}\",\"{}\":\"{}\"}}", - "timestamp", - header_and_extra.0.timestamp().unix_timestamp(), - "version", - Into::::into(*header_and_extra.0.version()), - "encrypt", - if header_and_extra.0.is_encrypt() { - 1 - } else { - 0 - }, - "extra", - extra_tuple.0, - "extra_encode", - extra_tuple.1 - ); - json_string + let extra_tuple: (String, String) = header_and_extra.1.unwrap_or_default(); + json!({"header": header_and_extra.0, "extra": extra_tuple.0, "extra_encode": extra_tuple.1}).to_string() }) .map_err(|e| e.to_string()) } diff --git a/ui-tauri/src/App.vue b/ui-tauri/src/App.vue index 1439c4b..f18fd42 100644 --- a/ui-tauri/src/App.vue +++ b/ui-tauri/src/App.vue @@ -8,7 +8,8 @@ import { onMounted, ref } from "vue"; import Modal from './Modal.vue' const logs = ref([]); -const add = (items: Record[]) => { +const addRecords = (items: Record[]) => { + logs.value = [] logs.value.push(...items) showTable.value = logs.value.length > 0 } @@ -29,7 +30,11 @@ logColors.set('Error', "rgb(244, 67, 54)"); type Header = { timestamp: 0, version: 2, - encrypt: 0, + cipher: string, +} + +type HeaderWithExtra = { + header: Header, extra: "", extra_encode: "" } @@ -62,7 +67,7 @@ async function fetchLogs(path: string, k: string, n: string) { await invoke('parse_log_file_to_records', { filePath: path, key: k, nonce: n }) .then((logs: any) => { let records: Record[] = JSON.parse(logs).map((item: string) => JSON.parse(item)); - add(records) + addRecords(records) }) .catch((error: any) => { console.error('Error fetching logs:', error); @@ -73,10 +78,10 @@ async function parse_header_and_extra(path: string) { console.log('parse file dropped:', path); currentPath.value = path; await invoke('parse_header_and_extra', { filePath: path }).then(async (result: any) => { - const header = JSON.parse(result as string) as Header - console.log(header) - currentExtra.value = header.extra_encode + ":\n" + header.extra - if (header.encrypt == 0) { + const header_extra = JSON.parse(result as string) as HeaderWithExtra + currentExtra.value = header_extra.extra_encode + ":\n" + header_extra.extra + const noEncrypt = "NONE" == header_extra.header.cipher; + if (noEncrypt) { fetchLogs(path, "", "") } else { showModal.value = true; @@ -100,9 +105,7 @@ function getColorClass(data: string) { listen('tauri://file-drop', (event: Event) => { if (event.payload && event.payload.length > 0) { const firstFilePath = event.payload[0]; - console.log('First file dropped:', firstFilePath); - // Now you can do something with the first file path - // For example, reading the file content or processing the file + console.log('file dropped:', firstFilePath); parse_header_and_extra(firstFilePath) } })